本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
初学单片机,请问下面一段程序哪里出问题了,为什么数码管不能正常显示59秒循环计时?
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^1;
sbit wela=P2^2;
sbit led=P2^0;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delayms(uint);
void display(uchar,uchar);
uchar num,num1,num2,shi,ge;
void main()
{
TMOD=0x11;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
while(1)
{
display(shi,ge);
}
}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display(uchar shi,uchar ge)
{
dula=1;
P1=table[shi];
dula=0;
P1=0xff;
wela=1;
P1=0xfe;
wela=0;
delayms(5);
dula=1;
P1=table[ge];
dula=0;
P1=0xff;
wela=1;
P1=0xfd;
wela=0;
delayms(5);
}
void T0_time() interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
num1++;
if(num1==4)
{
num1=0;
led=~led;
}
}
void T1_time() interrupt 3
{
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
num2++;
if(num2==20)
{
num2=0;
num++;
if(num==60)
num=0;
shi=num/10;
ge=num%10;
}
}
|