自己按照书上的程序编了一个,也自己花了个图,秒表计数,为什么10位能变化,个位不动呢,可是每10秒10位还发生变化,在线等哥哥们帮助,哪有问题自己按照书上的程序编了一个,也自己花了个图,秒表计数,为什么10位能变化,个位不动呢,可是每10秒10位还发生变化,在线等哥哥们帮助,哪有问题
单片机源程序如下:
- #include<reg52.h>
- sbit ADDR0=P1^0;
- sbit ADDR1=P1^1;
- sbit ADDR2=P1^2;
- sbit ADDR3=P1^3;
- sbit ENLED=P1^4;
- unsigned char code Ledchar [16]={
- 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
- 0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E
- };
- unsigned char Ledbuff [6]={
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
- unsigned int flagls=0;
- unsigned int cnt=0;
- unsigned int i=0;
-
- void main()
- {
- unsigned long sec = 0;
- EA = 1;
- ADDR3=1;
- ENLED=0;
- TMOD = 0x01;
- ET0 = 1;
- TH0 = 0xFC;
- TL0 = 0x67;
- TR0 = 1;
- while(1)
- {
- if(flagls == 1)
- {
- flagls = 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];
- Ledbuff[4] = Ledchar[sec/10000%10];
- Ledbuff[5] = Ledchar[sec/100000%10];
-
- }
- }
- }
- void InterruptTimer0() interrupt 1
- {
- TH0=0xFC;
- TL0=0x67;
- cnt++;
- if(cnt >= 1000)
- {
- cnt = 0;
- flagls = 1;
- }
-
- P0=0xFF;
- switch(i)
- {
- case 0:ADDR0=0;ADDR1=0;ADDR2=0;i++;P0=Ledbuff[0];break;
- case 1:ADDR0=1;ADDR1=0;ADDR2=0;i++;P0=Ledbuff[1];break;
- case 2:ADDR0=0;ADDR1=1;ADDR2=0;i++;P0=Ledbuff[2];break;
- case 3:ADDR0=1;ADDR1=1;ADDR2=0;i++;P0=Ledbuff[3];break;
- case 4:ADDR0=0;ADDR1=0;ADDR2=1;i++;P0=Ledbuff[4];break;
- case 5:ADDR0=1;ADDR1=0;ADDR2=1;i=0;P0=Ledbuff[5];break;
- default: break;
- }
- }
复制代码
|