为什么明明设置的值是10s结果是1s
#include<reg52.h>#define ucharunsignedchar
#define uint unsignedint
void delay(uint z);
void display (uchar x);
sbit dula=P2^6;
sbit wela=P2^7;
sbit beep=P2^3;
char code table[]={0x3f,0x06,0x5b,
0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x3f,
0x7c, 0x39,0x5e,0x79,0x71}; /*ìí¼óêyÂë1ü*/
uchar codetablewela[]={0xfe,0xfd,0xfb,0xf7,
0xef,0xdf};
uchar temp,x,ge,shi,bai;
uchar tt=0;
void main()
{
temp=0;
TMOD=0X01;
EA=1;
TH0=(65536-50000)/256;/*50MS¼Æê±*/
TL0=(65536-50000)%256;
ET0=1;/*ê1óö¨ê±Æ÷0*/
TR0=1;/*¿aÆô¶¨ê±Æ÷0*/
while(1)
{
if (tt==200)
{
tt=0;
temp++;
}
if(temp>255)
temp=0;
display (temp);
}
}
void delay(uint z)
{
uint x,y;
for(x=0;x<11;x++)
{
for(y=z;y>0;y--);
}
}
void display (uchar x)
{
bai=x/100;
shi=x%100/10;
ge=x%10;
dula=1;
P0=table;
dula=0;
wela=1;
P0=0xfe;
wela=0;
delay(5);
dula=1;
P0=table;
dula=0;
wela=1;
P0=0xfd;
wela=0;
delay(5);
dula=1;
P0=table;
dula=0;
wela=1;
P0=0xfb;
wela=0;
delay(5);
}
void timer0() interrupt 1
{
TH0=(65536-5000)/256;/*50MS¼Æê±*/
TL0=(65536-5000)%256;
tt++;
}
本帖最后由 耻思lhj 于 2020-4-16 14:28 编辑
void timer0() interrupt 1
{
TH0=(65536-5000)/256;/*50MS¼Æê±*/
TL0=(65536-5000)%256;
tt++;
}
因为这里应该还是-50000,按12M晶振计算就是50ms触发一次,这样循环200次就是10s
你-5000,除了第一次循环是50ms,其他每次都是5ms,自然就只有1s+45ms
页:
[1]