主要是數(shù)據(jù)分解代碼有問題,uint sec = 0;數(shù)據(jù)范圍0~65536,其次138位碼也有問題,給你改好了。
無標題.jpg (139.45 KB, 下載次數(shù): 40)
下載附件
2019-10-15 09:59 上傳
- #include <reg52.h>
- #define uint unsigned int
- #define uchar unsigned char
- //sbit LED = P0^0;
- sbit JA = P2^2;
- sbit JB = P2^3;
- sbit JC = P2^4;
- uchar code led[]={
- 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- uchar ledbuff[8]={0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f};
- uint cnt = 0;
- uint sec = 0;
- uint y;
- uchar i;
- uchar x;
- int main(void)
- {
- i=0;
- TMOD = 0x01; //0000 0001
- TH0 = 0XFC;
- TL0 = 0X18;
- TR0 = 1;
- EA = 1;
- ET0 = 1;
- while(1)
- {
- if(cnt >=1000)
- {
- cnt=0;
- sec++;//大于65535=0
- y=sec;
- for(x=0;x<=5;x++)
- {
- ledbuff[x]=led[y%10];
- y/=10;
- }
- }
- }
- }
-
- void interrupttimer0() interrupt 1
- {
- TH0 = 0XFC;
- TL0 = 0X18;
- cnt++; //cnt放在中斷中了
- P0 = 0x00;//消隱
- switch(i)
- {
- case 0: JA=1;JB=1;JC=1;break;
- case 1: JA=0;JB=1;JC=1;break;
- case 2: JA=1;JB=0;JC=1;break;
- case 3: JA=0;JB=0;JC=1;break;
- case 4: JA=1;JB=1;JC=0;break;
- case 5: JA=0;JB=1;JC=0;break;
- case 6: JA=1;JB=0;JC=0;break;
- case 7: JA=0;JB=0;JC=0;break;
- }
- P0=ledbuff[i];
- i++;
- i%=8;
- }
復制代碼
|