51 single chip microcomputer makes a timer

Publisher:书香墨意Latest update time:2020-04-17 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

We still use STC's 8051 microcontroller. This code is used to make a timer, which is displayed in real time through a digital tube. Because there are 6 digital tubes on the board, you can set the hours, minutes, and seconds. It can also be simulated on Proteus. When the timing ends, you can use a buzzer or a relay interface connection.


An alarm clock. An electromagnetic alarm clock will do. Of course, a buzzer is a good choice.


The program does not set the hour unit. Friends who want to add it can use the method of displaying minutes and seconds to display it. However, you should pay attention to the delay time after adding it. Improper time setting may cause unclear display, digital jitter, or unselected digital tubes to glow faintly ("ghosting"). You can debug the specific size yourself, which is also very simple. The following is the source code:


#include

#define uint unsigned int

#define uchar unsigned char

sbit we=P2^7;

bit du=P2^6;

uchar code table[]={0x3f,0x06,0x5B,0x4F,0x66,

               0x6D,0x7D,0x07,0x7F,0x6F,

               0x77,0x7C,0x39,0x5E,0x79, 

               0x71,0x76,0x38,0x37,0x3E,

               0x73,0x5C,0x40,0x00,};

uchar num=0,aa,s,g,m,f,h;

void delay(volatile x);

void main()

{    

    TMOD=0x01; //Set the internal interrupt 0, 1 to work in mode 1    

    EA=1; //Open the general interrupt

    ET0=1; //Enable interrupt    

    TR0=1; //Open interrupt 0          

    TH0=0x4c;

    TL0=0x00;

    while(1)

    {    

            du = 1;

            P0 = 0;

            du = 0;


            we = 1;

            P0 = 0x3e;

            we = 0;

            

            du = 1;

            P0 = table[s]; //ten digit

            du = 0;

                

            delay(10);


            du = 1;

            P0 = 0;

            du = 0;


            we = 1;

            P0 = 0x3d;

            we = 0;

            

            

            du = 1;

            P0 = table[g]; //unit

            du = 0;

            delay(10);


            du = 1;

            P0 = 0;

            du = 0;


            we = 1;

            P0 = 0x1f; //Display minutes

            we = 0;

            

            du = 1;

            P0 = table[m];

            du = 0;

                

            delay(10);


            du = 1;

            P0 = 0;

            du = 0;


            we = 1;

            P0 = 0x2f;

            we = 0;

            

            du = 1;

            P0 = table[h];       

            du = 0;

                

            delay(10);

        

        if(aa == 20)    

        {            

            aa = 0;

            if(num == 59)

            {

                num = 0;

                f++;

            }

            else

                num++;

            s = number/10;

            g = num%10;

            m = f%10;

            h = f/10;                

        }

        if(h == 6)

        f = 0;

    }

}

void timer0() interrupt 1 //Internal interrupt 0

{

    TH0=0x4c;

    TL0=0x00;

    aa++;

}

void delay(fly x)

{

    uchar y,z;

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

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

}

Reference address:51 single chip microcomputer makes a timer

Previous article:51 MCU simple timer
Next article:51 MCU timer

Recommended ReadingLatest update time:2024-11-16 13:04

MSP430F149 TIMER_A (II) - Comparison Mode
    The comparison mode of TIMER_A of MSP430F149 is mainly used as a PWM generator, which can generate two independent PWM waveforms (TA1, TA2). As long as the second function of the pin is TA1 or TA2, it can be configured as an output. I looked at the datasheet and found that using up-counting with PWM mode 6 (i.e. to
[Microcontroller]
Timer1 of PIC16F877
The Timer1 module is a 16-bit timer/counter consisting of two readable and writable 8-bit registers (TMR1H and TMR1L). The TMR1 register pair (TMR1H:TMR1L) increments from 0000h to FFFFh and rolls over to 0000h. If the Timer1 interrupt is enabled, a Timer1 interrupt will be generated on overflow. The interrupt can be e
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号