The code
# include
Bit int_flag;//timer 0, 1 S to sign a
Unsigned char volatile T0Count;//timer interrupt number of 0
Unsigned char volatile T1Count;
Unsigned char code table []//timer interrupt number 1
X5b x06 x3f={0, 0, 0, 0 x4f, 0 x66, 0 x6d, 0 x7d, 0 x07, 0 x7f, 0 x6f};//display section of the code value is 123456789
Unsigned char code \ []={0 xfe, 0 XFD, 0 XFB, 0 xf7};//digital tube gate
Unsigned long sum;//1 s the total number of pulse in
Unsigned char Led [4];//Led display cache
Void delay (unsigned int num) {//software delay
While (num);//initialization timer 0
}
Void init (void) {
TMOD=0 x51;//T1 timer 0 in mode 1, counting timer 1
TH0=(65536-50000)/256;//timing 50 ms
TL0=(65536-50000) % 256;
TH1=0 x00;
TL1=0 x00;
}
Void disp (void) {//digital display
unsigned char i;
for(i=0; i<4. I++)
{
The P2=\ [I];//piece choose
P0=table [Led [I]];//get data show
Delay (100);//delay 1 millisecond
}
}
Void main (void) {
EA=1;//always interrupt
The init ();//initialize the timer
TR0=1;//timer start work
TR1=1;
ET1=1;//T0 break
ET0=1;
While (1) {
If (int_flag==1) {
Int_flag=0;
Sum=TL1 + TH1 + T1Count * 65536 * 256;//1 s calculated pulse number
//the data format, into a display of BCD
Led [3]=sum % 10000/1000;//show one thousand
Led [2]=sum % 1000/100;//show one hundred
Led [1] sum %=100/10;//display 10
Led [0]=sum % 10;//shows individual
T0Count=0 x00;
T1Count=0;
TH1=0 x00;
TL1=0 x00;
TR1=1;
}
Disp ();
}
}
Void int_t0 (void) interrupt 1 {
TH0=(65535-50000)/256;
TL0=(65536-50000) % 256;
T0Count + +;
If (20) T0Count=={
TR1=0;
Int_flag=1;
T0Count=0 x00;
}
}
Void int_T1 (void) interrupt 3 {
T1Count + +;
}
CodePudding user response:
Delay (100);//delay 1 millisecond
Adjust to 255 and proved CodePudding user response: