Making a stopwatch timer, the recording time of 0-15 seconds. It requires accurate and controllable.
Claim:
- Start the stopwatch can be controlled with a key
- Button can be controlled by stopping the stopwatch
- Button can be used to control the clock to zero
- Time using the timer control precision is required.
- Using a plurality of digital control and implement the functions keys.
1. First, a circuit diagram of the request plus two buttons, as shown in the FIG.
The write code requirements, the following reference code is
#include<reg52.h> #define LED P0 unsigned int i = 0; unsigned int j =0; sbit KEY1 = P1 ^ 0; // Pause, Start button sbit KEY2 = P1 ^ 2; // reset button unsigned char NUM[]= {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,\ 0x80,0x90,0x88,0x83,0xA7,0xA1,0x86,0x8E}; void INT_T0(void) { TMOD = 0X01; // open timer 0, timer 1 mode using TH0 = 0XFC; TL0 = 0X18; // Initial value EA = 1; // Turn on the main switch ET0 = 1; // Open the interrupt switch T0 } void main(void) { INT_T0(); TR0 = 0; // close timing function LED = NUM[0]; while(1) { if(KEY1 == 0) { TR0 = 1; // determination button is pressed, the timing of the opened chronograph } else { TR0 = 0; // Analyzing key release, timed disconnect feature } if(KEY2 == 0) { break; // out of the loop, time to zero } } } void time0(void) interrupt 1 { TH0 = 0XFC; TL0 = 0X18; // Initial value if(i < 1000) { i++; } else { LED NUM = [j]; if(j < 16) { j++; } else { j=0; } i = 0; } }
Press 1 to start counting, stop release, press 2 Reset