|
大家好:本人是单片机初学者用51单片机编写了一数码管动态先是程序目的为:用动态扫描方法和定时器1在数码管的前三位显示出秒表,精确到1%秒,即后两位显示1%秒,一直循环下去,代码如下不能达到预期目的,感觉代码没什么问题王高人指点:
#include
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar a,bai,shi,ge;
void delay();
void init();
void display(uchar,uchar,uchar);
main()
{
init();
while(1)
{
display(bai,shi,ge);
}
}
void init()
{
TMOD=0x10;
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
EA=1;
ET1=1;
TR1=1;
a++;
if(a==1)
{
a=0;
ge++;
if(ge==10)
{
ge=0;
shi++;
if(shi==10)
{
shi=0;
bai++;
if(bai==10)
bai=0;
}
}
}
}
void timer1() interrupt 3
{
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
}
void display(uchar bai,uchar shi,uchar ge)
{
wela=1;
P0=0xfe;
wela=0;
dula=1;
P0=table[bai];
dula=0;
delay();
wela=1;
P0=0xfd;
wela=0;
dula=1;
P0=table[shi];
dula=0;
delay();
wela=1;
P0=0xfb;
wela=0;
dula=1;
P0=table[ge];
dula=0;
delay();
}
void delay()
{;;
// uchar x,y;
// for(x=z;x>0;x--)
// for(y=1;y>0;y--);
}
|
|