Proteus simulation diagram of single chip digital tube electronic clock

Publisher:达文西happyLatest update time:2020-08-04 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

①When the machine is turned on, it is in running mode and displays the time normally.
②There are 3 buttons in total, namely mode button, function button 1 and function button 2. Press the mode button to switch between the 4 modes of "running time/time adjustment/date display and adjustment/alarm display and adjustment".
③In running mode, press function button 1/function button 2 to stop the alarm.
④In time adjustment mode, function button 1 adjusts the time up and function button 2 adjusts the time down.


The simulation schematic is as follows

The microcontroller source program is as follows:

#include

#define uchar unsigned char

uchar code tab[12]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xbf};

//The common anode digital tube displays the field code of "0~9", "off" and "-"

//uchar code tab[]={0x3f,0x06,05b,0x4f,0x66,0x6d,07d,0x07,0x7f,0x6f,0x00,0x40}; //Common cathode digital tube

uchar code wetab[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //bit selection

uchar data dis[8]={0x00,0x00,0x0b,0x00,0x00,0x0b,0x00,0x00};

//Display data buffer, hour ten, unit digit, minute ten, unit digit, second ten, unit digit are initially 0, 0x0b is "-" code

uchar data timedat[3]={0x00,0x00,0x00}; //Count values ​​for seconds, minutes, and hours respectively (record the number of K1 and K2)

uchar data ms50=0x00, num=0x00, n1=0x00, n2=0x00;

//Define the timer number variable, adjust the mode variable, press the plus 1 key number variable, press the minus 1 key number variable

sbit key0=P1^0 ; //Adjust key--mode

sbit key1=P1^1; //Add 1 key

sbit key2=P1^2 ; //minus 1 key

//---------------------------------------

void delay1ms( unsigned int z ) //define delay 1ms function

{ unsigned int x, y ;

for ( x=z; x>0; x-- )

                for ( y=120; y>0 ; y-- ) ;

}


//---------------------------------------

//Key processing function. If no key is pressed, the clock will run normally. When the K0 key is pressed once, the clock will pause and enter the hour adjustment state; press the K0 key once again, enter the minute adjustment state; press the K0 key once again, and return to the normal time adjustment state. For the K1 and K2 keys, if the clock is running normally, pressing the K1K2 keys will not work; if the clock enters the hour or minute adjustment state, press the K1 key to add 1 to the hour or minute, and the hour will return to 0 when it is added to 24, and the minute will return to 0 when it is added to 60. Press the K2 key to subtract 1 from the hour or minute, and the hour will return to 23 when it is reduced to a negative value, and the minute will return to 59 when it is reduced to a negative value.


void keyscan( void )

{EA=0; //Disable interrupt

        if(timedat[0]==0&timedat[1]==0&timedat[2]==7) {P1=0xff;}

if (key0==0) { delay1ms(10); while (key0==0);

                        num++; TR0=0; ET0=0; // Each time the adjustment key K0 is pressed, the mode variable num is increased by 1

                        if (num>=3) {num=0; ET0=1; TR0=1; } // Start T0 time calibration

        }

                if (num!=0) //The pattern variable is not equal to 0

{ if (key1==0) // K1 key is pressed

         { delay1ms(10); while (key1==0); timedat[num]++; //Record the number of times key K1 is pressed

                                if (num==2) n1=24; else n1=60; //The pattern variable is equal to hour 2--then it will be late by one day or 60 minutes

if (timedat[num]>=n1) { timedat[num]=0; } }

                }

                if (num!=0)

                 { if (key2==0)        

{ delay1ms(10); while (key2==0); timedat[num]--; //Record the number of times key K2 is pressed

                                if (num==2) n2=23;else n2=59;                        

                                if (timedat[num]<=0) {timedat[num]=n2; } }

                }

                 EA=1;

        }


//---------------------------------------

// Function for displaying digital tubes. The time is displayed by calculating and displaying the seconds first, then the seconds, then the minutes, then the minutes, then the tens, then the hours, then the hours, then the tens.

         void display( void )

        { uchar k;

                if(timedat[0]==0&timedat[1]==0&timedat[2]==7) {P1=0xff;}

                 dis[0]=timedat[0]%10; dis[1]=timedat[0]/10; //seconds

dis[3]=timedat[1]%10; dis[4]=timedat[1]/10; // points

dis[6]=timedat[2]%10; dis[7]=timedat[2]/10; //time

for ( k=0; k<8; k++ )

                        { P0=tab[ dis[k] ]; P2=wetab[k]; delay1ms(1); P2=0x00; }

}        

//---------------------------------------

//Main function, the time is displayed by calculating the units of seconds first, then the tens of seconds; then the units of minutes, then the tens of minutes; then the units of hours, then the tens of hours. The timer interrupt first detects whether 1 second has arrived → if 1 second has arrived, the seconds unit will increase by 1; if 1 second has not arrived, it detects whether 1 minute has arrived → if 1 minute has arrived, the minutes unit will increase by 1; if it has not arrived, it detects whether 1 hour has arrived → if 1 hour has arrived, the hours unit will increase by 1; if it has not arrived → then display the time.

         void main( void )

        { TMOD=0x01; //T0 timing 50ms, mode 1

                EA=1; ET0=1; TR0=1; //Open interrupt, enable T0 interrupt, start T0

                TH0=0x3c; TL0=0xb0;

                while (1)

                        { display( ) ;

                                keyscan( ) ;

                        }

}


//Timer/Counter T0 interrupt service function. The timer interrupt first detects whether 1 second has arrived → if 1 second has arrived, the second unit increases by 1; if 1 second has not arrived, detect whether 1 minute has arrived → if 1 minute has arrived, the minute unit increases by 1; if it has not arrived, detect whether 1 hour has arrived → if 1 hour has arrived, the hour unit increases by 1; if it has not arrived → the time is displayed.


void timer0(void) interrupt 1

{ ET0=0; TR0=0; //T0 interruption is not allowed and it is not started

TH0=0x3c; TL0=0xb0;  

TR0=1; //Start T0

ms50++;

P1=0xf7;

         if(timedat[0]==0&timedat[1]==0&timedat[2]==7) {P1=0xff;}

if (ms50==20) { ms50=0x00; timedat[0]++; //The variable m returns to 0, and the second increases by 1

                if (timedat[0]==60) { timedat[0]=0;timedat[1]++; //After the seconds reach 60, it returns to 0 and the minutes increase by 1

                        if (timedat[1]==60) { timedat[1]=0;timedat[2]++; //return to 0 after 60, and add 1

                                if (timedat[2]==24) { timedat[2]=0; } } } //Returns to 0 after time reaches 24

                                 

        }

        ET0=1; //Enable T0 interrupt

}

Reference address:Proteus simulation diagram of single chip digital tube electronic clock

Previous article:Single chip microcomputer DS18B20 temperature measurement and control system
Next article:51 single chip microcomputer buzzer plays Twinkle Twinkle Little Star Two Tigers Ode to Joy

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号