keil4 making a stopwatch timer ----- 10969

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

Required keil_proteus circuit diagram link: https: //pan.baidu.com/s/1QWcxt7-lTIe9_cJGrILpsQ extraction code: tkn4

First, the requirement

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.

 

1. Open Single circuit diagram of a digital display proteus

 

 2. Open keil4 began to write the code below:

 

 3. Specific code as follows

#include<reg52.h>
#define LED_ALL P0
sbit KEY1 = P1^0;
sbit KEY2 = P1^1; 
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= 0 ;        // timer opens 
    LED_ALL LED_NUM = [ 0 ];
     the while ( . 1 ) 
    { 
        IF (KEY1 == 0 ) 
        { 
          TR0 = . 1 ;       // timer function is disabled 
        }
         IF (the KEY2 == 0 ) 
        { 
            I = 0 ; 
            N = 0 ; 
        }     
    } 
} 
void TIME0 ( void ) interrupt . 1 
{
    TH0 = 0XFC;
    TL0    = 0X18;     //初始值
    if(i < 1000)
    {
        i++;
    }
    else
    {
        LED_ALL = LED_NUM[N];
        if(N<16)
        {
            N++;
        }
        else
        {
            N = 0;
        }
        i = 0;
    }

}

4. Finally hex file simply burned into a circuit diagram of a single digital display can only

 

 

 

Guess you like

Origin www.cnblogs.com/dyw31/p/11832038.html