Mid-term test (making a stopwatch timer)

Making a stopwatch timer, the recording time of 0-15 seconds. It requires accurate and controllable.

1. Start the stopwatch can be controlled with the buttons

2. The button can be controlled by stopping the stopwatch

3. The key can be used to control the clock to zero

4. Use a timer to control the time precision is required.

5. Using a plurality of digital control and implement the functions keys.

#include<reg52.h>
#define LED  P0
sbit KEY1 =P1^0;
sbit KEY2 =P1^4;
unsigned int i = 0;
unsigned char n = 0;
unsigned char LED_NUM[] = {0xc0,0xf9,0xa4,0xb0,\
                           0x99,0x92,0x82,0xf8,\
                           0x80,0x90,0x88,0x83 , \
                            0xC6 , 0xA1 , 0x86 , 0x8e };
 void INT_T0 ( void ) 
{ 
    the TMOD = 0X01 ; // open timer 0, timer 1 mode using 
    TH0 is = 0xFC ; 
    TL0     = 0X18 ; // Initial value 
    EA = 1 ; / / Turn on the main switch 
    the Reference Crop Evapotranspiration = . 1 ; // open the interrupt switch T0 
}
 void main ( void ) 
{     
    INT_T0 ();
    TR0 =1 ; // timing function opens 
    the while ( 1 ) 
    { 
        IF (KEY1 == 0 ) 
        { 
            TR0 = 1 ; 
        }         
        IF (the KEY2 == 0 ) 
        { 
            I = 0 ; 
            n- = 0 ; 

        }             
    } 
} 
void TIME0 ( void ) interrupt . 1  
{ 
    TH0 is = 0xFC ; 
    TL0     = 0X18; //初始值
    if(i < 1000)
    {
        i++;
    }
    else
    {
        LED = LED_NUM[n];
        if(n<16)
        {
            n++;
        }
        else
        {
            n=0;
        }
            i=0;        
    }
}

 

Guess you like

Origin www.cnblogs.com/quanpeng/p/11811325.html