Electronic clock based on 8051 (Version 1.1)

Publisher:数字行者Latest update time:2021-08-05 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Functions implemented by the program:


1. After the experimental box is powered on, the current time is not displayed.


2. After sending "Start.E" to 8051, the electronic clock starts working and displays the current time (hours, minutes, seconds).


3. After sending "Stop.E" to 8051, the electronic clock stops working and hides the current time.


#include <STC89C5xRC.H>

 

#include

 

unsigned char code DIG_CODE[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f}; //The corresponding digital tube displays 0~9

 

char buf[30]; //Store received data

 

int tcount = 0; //Record the number of 2ms intervals passed

 

int hour = 23, minute = 59, second = 55;

 

void T0_INT() interrupt 1 //timer0 interrupt, triggered every 2ms

{

TR0 = 0; // turn off timer0

TH0 = 0xF8;

TL0 = 0x30;//65536 - 2000 = 63536 = F830H

if(tcount % 6 == 0)

{

// Seconds digit

P2 = 0; //The first number from the right is bright

P0 = DIG_CODE[second % 10];

tcount ++;

}

else if(tcount % 6 == 1)

{

//Tens of seconds

P2 = 1 << 2; //The second number from the right is lit

P0 = DIG_CODE[second / 10];

tcount ++;

}

else if(tcount % 6 == 2)

{

//Minutes digit

P2 = 2 << 2;

P0 = DIG_CODE[minute % 10];

tcount ++;

}

else if(tcount % 6 == 3)

{

//Tens of minutes

P2 = 3 << 2;

P0 = DIG_CODE[minute / 10];

tcount ++;

}

else if(tcount % 6 == 4)

{

//Hour digit

P2 = 4 << 2;

P0 = DIG_CODE[hour % 10];

tcount ++;

}

else if(tcount % 6 == 5)

{

//Tens of hours

P2 = 5 << 2;

P0 = DIG_CODE[hour / 10];

tcount ++;

}

if(tcount == 500) //2ms * 500 = 1000ms = 1s -> 1s time is up

{

tcount = 0;

second ++;

if(second == 60)

{

second = 0;

minute ++;

if(minute == 60)

{

minute = 0;

hour ++;

if(hour == 24)

{

hour = 0;

}

}

}

}

TR0 = 1; //Restart timer0

}

 

int main()

{

int i;

P2 = 111 << 2;

P0 = 0; // All digital tubes are off

TMOD = 0x21;

SCON = 0x50; //Set serial communication format

TH0 = 0xF8;

TL0 = 0x30;

TH1 = 0xE6;

TL1 = 0xE6;

IE = 0x82;

TR0 = 0; //Do not start timer0 yet

TR1 = 1; // Turn on timer1 to generate baud rate

while(1)

{

if(RI == 1) //Receive data

{

RI = 0;

buf[i++] = SBUF; //Receive data from the serial port

buf[i] = ''; //Manually add the end of string mark

if(i == 29) //Prevent array access out of bounds

{

i = 0;

}

if(buf[i - 1] == 'E') // reach the end

{

i = 0;

if(strcmp(buf, "Start.E") == 0) //Start.E command-> start the clock

{

TR0 = 1; //Start timer 0

}

else if(strcmp(buf, "Stop.E") == 0) //Stop.E command-> turn off the clock

{

TR0 = 0; // turn off timer 0

P2 = 111 << 2;

P0 = 0; // Clear Ping

}

}

}

}

return 0;

}

Reference address:Electronic clock based on 8051 (Version 1.1)

Previous article:An electronic clock based on 8051 that can start, stop, display or hide time (Version 1.2)
Next article:Electronic clock based on 8051 (Version 1.0)

Recommended ReadingLatest update time:2024-11-16 07:55

Design of indoor natural lighting system using two-dimensional fuzzy controller and C8051 microcontroller
1 Introduction From ancient bonfires and oil lamps to candles and incandescent lamps, to the fluorescent lamps in thousands of households today, humans have basically adapted to the indoor lighting environment of artificial light sources. However, due to environmental influences over thousands of years, natural light
[Microcontroller]
Design of indoor natural lighting system using two-dimensional fuzzy controller and C8051 microcontroller
Controlling CF card storage and design research using C8051F020 microcontroller
With the rapid development of computer application technology, mobile storage devices have been widely used. Among them, CF (Compact Flash) card was born in 1994. It is the earliest flash memory card launched and has the highest penetration rate among many products. Because CF cards have the characteristics of low pri
[Microcontroller]
Controlling CF card storage and design research using C8051F020 microcontroller
How to use Keil UVision IDE for 8051 programming
Step 1: Download Keil UVision IDE Keil provides a code-limited (2K bytes) evaluation version) for the 8051 architecture (C51), which is sufficient for learning purposes. The main limitations of the evaluation version are as follows. 8051 compiler, assembler, linker, and debugger have an object code limit of 2 KB Pro
[Microcontroller]
How to use Keil UVision IDE for 8051 programming
Design of temperature and humidity acquisition system based on 8051 microcontroller
Through the previous study, we learned how to use the serial port to send data and receive fixed-byte commands. Today, we continue to discuss the serial port application protocol, and the main focus is on how to effectively use the serial port to send data. To simplify the description, assume that we develop a tempera
[Microcontroller]
Design of temperature and humidity acquisition system based on 8051 microcontroller
Design of human-computer interaction system with C8051F020 microcontroller as the control core
In the development of various modern instruments, human-computer interaction functions are playing an irreplaceable role. Instruments with friendly human-computer interaction interface will be easier to operate and use, thereby improving work efficiency. Liquid crystal displays (LCDs) have the characteristics of low p
[Microcontroller]
Design of human-computer interaction system with C8051F020 microcontroller as the control core
Machine cycle analysis of 8051 microcontroller
In computers, in order to facilitate management, the execution process of an instruction is often divided into several stages, and each stage completes a task. For example, instruction fetch, memory read, memory write, etc. Each of these tasks is called a basic operation. The time required to complete a basic operatio
[Microcontroller]
Machine cycle analysis of 8051 microcontroller
How to generate time delay using 8051 timer?
The 8051 microcontroller has two independent 16-bit up-counting timers named Timer0 and Timer1. This article is about using the 8051 timer to generate time delays. Delays can be generated using pure software loops, but these delays are less accurate and cannot be used in sensitive applications. Using a timer delay is
[Microcontroller]
How to generate time delay using 8051 timer?
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号