麻烦大家帮忙看看这个程序哪里出了问题,用的是89S52调试,晶振是11.0592M,为什么示波器上的频率是343Hz呢,按键时数值会变化,但是占空比却没有改变,是哪里出了问题呢?
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar count=0;
uchar pwm=50;
sbit p10=P1^0; //pwm output
sbit p32=P3^2; //pwm +
sbit p33=P3^3; //pwm -
uchar code table[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //数码管显示
void Time0_init(void) //定时0.01ms
{
TR0=0;
TMOD=0X01;
TH0=0xFF;
TL0=0xF6;
TR0=1;
ET0=1;
EA=1;
}
void TimeO_int ()interrupt 1
{
TH0=0XFF;
TL0=0XF6;
count++;
if(count>=100) count=0;
}
void delay(uint del) //延时,按键延时用
{
uint i,j;
for(i=0; i<del; i++)
for(j=0; j<60; j++)
;
}
void main()
{
Time0_init();
p10=0;
while(1)
{
P0=table[pwm/10]; //数码管显示
P2=0x00;
delay(1);
P0=table[pwm%10];
P2=0X01;
delay(1);
if(p32==0) //pwm +
{
delay(20);
if(p32==0) pwm++;
}
if(p33==0) //pwm -
{
delay(20);
if(p33==0) pwm--;
}
if(pwm>=100)pwm=100; //0-100 PWM control
if(pwm<=0)pwm=0;
if(count<=pwm) p10=1;
else p10=0;
};
} |