那位师傅,帮我看一下这个陈序。四位数码管动态显示,能编译不错,下载到单片机,不显示。错在那里?
#include <reg52.h>
sbit LED=P0^0;
sbit DT0=P1^0;
sbit DT1=P1^1;
sbit DT2=P1^2;
sbit DT3=P1^3;
unsigned char code LedChar[]={
0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,
};
unsigned char LedBuff[4]={
0xFF,0xFF,0xFF,0xFF,
};
void main()
{
unsigned char i=0;
unsigned int cnt=0;
unsigned long sec=0;
LED=1;
DT0=0;
TMOD=0x01;
TH0=0xFC;
TL0=0x67;
TR0=1;
while(1)
{
if(TF0==1)
{
TF0= 0;
TH0 = 0xFC;
TL0=0x67;
cnt++;
if(cnt>=1000)
{
cnt=0;
sec++;
LedBuff[0]=LedChar[sec%10];
LedBuff[1]=LedChar[sec/10%10];
LedBuff[2]=LedChar[sec/100%10];
LedBuff[3]=LedChar[sec/1000%10];
}
if(i==0)
{DT2=0;DT1=0;DT3=0;i++;P0=LedBuff[0];}
else if(i==1)
{DT2=0;DT1=0;DT3=1;i++;P0=LedBuff[1];}
else if(i==2)
{DT2=0;DT1=1;DT3=0;i++;P0=LedBuff[2];}
else if(i==3)
{DT2=0;DT1=1;DT3=1;i++;P0=LedBuff[3];}
}
}
}
|