|
P0要接上拉電阻。段碼數(shù)組有誤。
- #include<reg52.h>
- unsigned char code ledchar[10]={
- 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- unsigned char ledbuff[2]={0x3f,0x3f};
- unsigned char i=0;
- unsigned int cnt=0;
- unsigned char flag1s=0;
- void main()
- {
- unsigned int sec = 0;
- EA=1;
- TMOD=0x01;
- TH0=0xfC;
- TL0=0x67;
- ET0=1;
- TR0=1;
- while(1)
- {
- if(flag1s==1)
- {
- flag1s=0;
- sec=++sec%60;
- ledbuff[0]=ledchar[sec%10];
- ledbuff[1]=ledchar[sec/10%10];
- }
- }
- }
- void yb() interrupt 1
- {
- TH0=0xfC;
- TL0=0x67;
- cnt++;
- if(cnt>=1000)
- {
- cnt=0;
- flag1s=1;
- }
- P0=0x00;
- switch(i)
- {
- case 0:P1=0xfe;i++;P0=ledbuff[0];break;
- case 1:P1=0xfd;i=0;P0=ledbuff[1];break;
- default:break;
- }
- }
復(fù)制代碼 |
|