A simple digital tube clock based on 51 single chip microcomputer

Publisher:千变万化Latest update time:2019-12-11 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Looking at the materials in the drawer, I wanted to make something for fun. I originally wanted to make a 99-meter meter, but there were not enough key switches, so I changed it to a clock. Without further ado, here are the pictures. The final simulation schematic diagram
of the minimum system

 



display module is as follows (the proteus simulation project file can be downloaded in the attachment of this post) The microcontroller source program is as follows:
 



 


 

/*********************************************************************************

*Experiment name: Digital tube dynamic display

*Experimental results: 8-bit digital tube displays the numbers 12345678

*Note: The delay time between each digital tube display is less than 3ms, and you can see 8 digital tubes light up at the same time

*

*********************************************************************************/

#include

#define uchar unsigned char

#define uint unsigned int

        

uint k=0;

uint second=0;//second

uint min = 0; // Minutes

uint hour=1;//hour


sbit we1=P3^3; //bit selection

sbit we2=P3^1;

sbit we3=P3^2;

sbit we4=P3^0;

sbit L0=P2^0;


uchar code sz[17]={0x3f , 0x06 , 0x5b ,0x4f , 0x66 , 0x6d ,0x7d ,

                   0x07 , 0x7f , 0x6f ,0x77 , 0x7c , 0x39 , 

                   0x5e , 0x79 , 0x71 , 0x00}; //0-9&A-F&“not displayed” font code


void delay(uint xms) //xms equals to the delay of a few milliseconds

{

    uint i,j;

        for(i=xms;i>0;i--)

            for(j=112;j>0;j--);

}


void Init_timer0(void)

{

  TMOD |= 0X01; //Working mode 1 Timing function controlled by internal register

        TH0=0X3c; //initial value of the upper eight bits

        TL0=0Xb0; //initial value of the eighth bit

        EA=1; // Enable overall interruption

        ET0=1; //Enable timer 0 interrupt

        TR0=1; //Start counting

}


void Timer0_isr(void)interrupt 1

{

  TH0=0x3c;

        TL0=0xb0;

        k++;

}


void main()

{

        Init_timer0();

    while(1)

        {

                if(k==20) //20 times 1 second

                {

                second++;

                k=0;

                if(second==60)

                {

                  second =0;

                        min++;

                        if(min==60)

                        {

                           min=0;

                                 hour++;

                                if(hour==13)

                                {

                                  hour=1;

                                }

                        }

                }

                

                }

                P1=sz[min%10]; //Minute display

                we4 =0;

                delay(5);

                we4=1;

                        

                P1=sz[min/10];   

                of 3=0;

                delay(5);

                of 3=1;

                

                P1=sz[hour%10]; //Hour display

                we2=0;

                delay(5);

                we2=1;

                

                P1=sz[hour/10];   

                we1=0;

                delay(5);

                we1=1;

                

                /*P1=sz[0]; //display 0

                we1=0;

                delay(10);

                we1=1;

                

                P1=sz[1]; //display 1

                we2=0;

                delay(10);

                we2=1;

                

                P1=sz[2]; //display 2

                of 3=0;

                delay(10);

                of 3=1;

                

                P1=sz[3]; //display 3

                we4=0;

                delay(10);

                we4=1;*/

        }

}

…………………



Reference address:A simple digital tube clock based on 51 single chip microcomputer

Previous article:MFRC522 circuit schematic and MCU test program
Next article:GP2Y0E02B distance measurement module 89c52 microcontroller serial port program

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号