- #include <STC89C5xRC.H>
- void Delay20us() //@11.0592MHz
- {
- unsigned char i;
- i = 52;
- while (--i);
- }
- void Delay10ms() //@11.0592MHz
- {
- unsigned char i, j;
- i = 108;
- j = 145;
- do
- {
- while (--j);
- } while (--i);
- }
- int i, k=1, t, j, sum;
- const unsigned char seg_code[] = { 0x3F,/*0*/ 0x06,/*1*/ 0x5B,/*2*/ 0x4F,/*3*/ 0x66,/*4*/ 0x6D,/*5*/ 0x7D,/*6*/ 0x07,/*7*/ 0x7F,/*8*/ 0x6F,/*9*/};
-
- void main(){
- IT0 = 1;
- EX0 = 1;
- IT1 = 1;
- EX1 = 1;
- EA = 1;
- while(1){
- j=sum;
- for(k=1;j>=10;k++){
- j/=10;
- }
- t=sum;
- for(i = 0;i < k;i++){
- P2 = i<<2;
- P0 = seg_code[t%10];
- Delay20us();
- P0 = 0x00;
- t/=10;
- }
- }
- }
- void int0() interrupt 0{
- Delay10ms();
- if(P32 == 0){
- sum++;
- if(sum>9999)sum=0;
- }
- }
- void int1() interrupt 2{
- Delay10ms();
- if(P33 == 0){
- sum--;
- if(sum<0)sum=9999;
- }
- }
复制代码 |