以上是代码,功能是实现秒表计时,60清零,精确到后两位,我觉得代码没问题啊
以下是仿真
- #include<reg51.h>
- #include<intrins.h>
- char led[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
- int number=0;
- char score[]={0,0,0,0};
- void timer0(void) interrupt 1
- {
- number++;
- score[1]=number/1000;
- score[2]=(number-score[1]*1000)/100;
- score[3]=(number-score[1]*1000-score[2]*100)/10;
- score[4]=number-score[1]*1000-score[2]*100-score[3]*10;
- if (number>6000){number=0;}
- TL0=0Xf0;
- TH0=0Xd8;
- }
- main(){
- int k=0;
- int wei=0x01;
- TMOD=0X01;
- TH0=0Xd8;
- TL0=0Xf0;//10ms
- TR0=1;
- ET0=1;
- EA=1;
- while(1){
- for(k=1;k<5;k++)
- { P2=led[score[k]];
- wei=_crol_(wei,2);
- P3=wei;
- }
- }
- }
复制代码
|