- 8051 Program Counter
- Program For Digital Clock Using 8051 System
- Assembly Language Code For Digital Clock Using 8051
- 8051 Microcontroller Applications
This program will generate a digital clock using c program. The logic behind to implement this program, Initialize hour, minute, seconds with 0. Run an infinite loop. Increase second and check if it is equal to 60 then increase minute and reset second to 0. Increase minute and check if it is equal to 60 then increase hour and reset minute to 0. The Program/Code Explanation Download Program – Embedded C. The program for RTC (Real Time Clock) using 8051 is written in Embedded C (using Keil compiler). We begin by including “LCD8bit” library into the program. It is a user defined library for interfacing microcontroller with LCD module in 8 bit mode. Mar 11, 2017 In this mini-project, we are going to make a simple Digital Stopwatch by using a Microcontroller from 8051 families. Digital Stopwatch allows you to record the exact number of hours and minutes you worked on a task/activity. It is a special type of watch with buttons that start, stop, and then zero the hands, used to time races. Components required.
Here is a simple project on how to make a digital clock with 8051(89c51,89c52) microcontroller. The clock is efficient and their is no difference in time even in milli seconds. You can verify it with the digital clock you have. In the project i utilized the 8051 microcontroller internal clock source to produce a delay exactly equal to 1 second. This delay is then used to build a efficient clock with 89c51 microcontroller. Usually digital RTC(real time clocks) are interfaced with microcontrollers to make a digital clock. But i utilized the internal timers of 89c51 microcontroller to generate a precise time for making a clock with 8051 microcontroller. 16×2 lcd is interfaced with 8051 microcontroller to display time on lcd. Time in minutes, hours and seconds will be displayed on 16×2 lcd. 4×4 numeric keypad is also part of the 8051 digital clock project. It is used to set time, user manually enters the minutes and hours by pressing the buttons of 4×4 numeric keypad. Buttons represents numbers on keypad.
8051 microcontroller clock – Project requirements
- 16×2 lcd (To display time)
- 8051 (89c51 or any of 8051 series microcontroller)
- Potentiometer/variable resistor (For setting LCD contrast)
- Crystal(11.0592 MHz) (For clock generation)
- 4×4 keypad (For setting time)
- 5 volts power supply for driving lcd and microcontroller.
89c51 microcontroller digital clock – Project circuit diagram
Connect 4×4 keypad with Port-1 of 8051(89c51) microcontroller. Connect 16×2 lcd with Port-2 of microcontroller. The rs (register set) pin of 16×2 lcd is connected to Port-3 pin#5 and en(enable) pin is connected to Port-3 Pin#6 of microcontroller. Ground rw(Read-Write) Pin of 16×2 lcd. Attach crystal of frequency 11.0592 MHz to Pin# 18 and 19 of 8051 microcontroller. I used Crystal of frequency 11.0592 MHz. For reset connect a push button to Pin#9 of microcontroller. To set contrast attach a potentiometer/variable resistor to contrast pin of lcd.
![8051 programming board 8051 programming board](/uploads/1/3/3/8/133879416/923432257.jpg)
digital clock with 8051(89c51,89c52) microcontroller
The code of the project is very complex. If you are newbie it will be very hard to grab all the information in the code. I can not explain each and every statement of code here. I made separate tutorials on how to interface 16×2 lcd and 4×4 numeric keypad with 89c51 microcontroller? If you don’t know about keypad and lcd interfacing with microcontrollers i recommend to take all the tutorials. You have to take each tutorial to fully understand the code. Because each component programming is different with other. Lcd is interfaced in 8-bit mode with 8051 microcontroller. To understand the working of 16×2 lcd take the tutorials whose links are below. Key-pad coding is very easy take the tutorial.Note: These tutorials are very important because the coding in the project heavily depends on these tutorials.
Time delay generation is also very difficult using 8051(89c51,89c52) microcontroller. You have to be familiar with the internal timer registers of the 8051. For delay generation take the following tutorials.
- How to give one minute delay using 8051.
int scan_key(); Used to set time initially at the beginning when power is supplied.
int scan_key1(); Used to set time if 1 is pressed.
The difference between the above two functions is one is used to set time initially when you power on the hardware. The second one is used to set time when clock is operational. For example clock is running and you want to set time again so pressing ‘1‘ on keypad will lead you into scan_key1() function and you can set time according to your desire.
void display(); Used to check increments in seconds, hours and minutes and display time.
void start(); Used to check increments in seconds , hours and minutes and display time.
void tochar(unsigned int value); Used to display time by converting integer in character.
To display a numeric character on 16×2 lcd we have to convert it in character form. The above function is used to achieve this task.
void onemintdelay(); Used to start the internal timer till one second.
One minute delay is generated with the above function. For knowing how to generate one second delay with 89c51 microcontroller? You have to take the tutorial mentioned above.
int scan_key1(); Used to set time if 1 is pressed.
The difference between the above two functions is one is used to set time initially when you power on the hardware. The second one is used to set time when clock is operational. For example clock is running and you want to set time again so pressing ‘1‘ on keypad will lead you into scan_key1() function and you can set time according to your desire.
void display(); Used to check increments in seconds, hours and minutes and display time.
void start(); Used to check increments in seconds , hours and minutes and display time.
void tochar(unsigned int value); Used to display time by converting integer in character.
To display a numeric character on 16×2 lcd we have to convert it in character form. The above function is used to achieve this task.
void onemintdelay(); Used to start the internal timer till one second.
One minute delay is generated with the above function. For knowing how to generate one second delay with 89c51 microcontroller? You have to take the tutorial mentioned above.
digital clock 8051 microcontroller minutes settings
8051 Program Counter
When you are done with all the above circuit building and code compilation. Then burn the code in your 8051 microcontroller with a good burner and now its time to test the code. At the start of the circuit triggering/powering you will see a message “SET 1 CLOCK” displayed on the first line of the 16×2 lcd and on second line you will see time in hours, minutes and seconds. Hour increments after every 60 minutes, minute is incremented after 60 seconds. When hour, minute and seconds reaches 12, 60, 60 they are again initialized with 0 for next reading.Note: You can also set the time at any instance just press 1 and you can see settings , set the time, and your clock starts running from updated time.
Important note:The seconds starts from 3 and goes to 60. This is not an error in coding simply just because after each second i have to check some readings like hour minutes etc in which three seconds are required from each minute. Time displayed on the 16×2 lcd is perfect their is no error in it.
Important note:The seconds starts from 3 and goes to 60. This is not an error in coding simply just because after each second i have to check some readings like hour minutes etc in which three seconds are required from each minute. Time displayed on the 16×2 lcd is perfect their is no error in it.
Download the project files, code(C++,Hex) compiled in keil Uvision 4 compiler. Just download the hex Code in your microcontroller. MaKe the circuit and enjoy your digital clock. And one thing more don’t forget to write comments about the post and project below. Project video is also given below.
You might be seeing a wall clock running with a 1.5V battery or a digital watch running with lithium or silver oxide. But, an interesting thing is, if you want to tick a clock in real time applications, the only solution is to use RTC (Real Time Clock) to get Date and Time.
In the previous tutorial, I have explained how to use RTC DS3231 with microcontroller and display date and time on LCD.
In this article, I will show how to display date and time on PC using 8051 serial communication.
RTC Schematic of DS3231
RTC code for DS3231
This embedded C program evaluates the working of DS3231 RTC with 8051 Microcontroller and displays time and date on PC.
The below code snippet shows the macros used for RTC registers. The addresses correspond to the slave address of DS3231, second, minute, hour, second, date, month, and year, hour format.
The below code shows the macros used for i2c communication with 8051.
The below code explains the serial communication with 8051 and RTC.
The header file has been created for accessing the global variables.
The delay function has been used to set some lag for sending byte by byte to PC.
Proteus Simulation
Program For Digital Clock Using 8051 System
Conclusion
I hope you understand how to use Real Time Clock (RTC) to display the date and time on the serial terminal. Need for speed movie.
Assembly Language Code For Digital Clock Using 8051
There are multiple ways to monitor the data. It might be an LCD, PC or a serial debugger.
8051 Microcontroller Applications
This DS3231 RTC code is tested on 8051 microcontroller. The date and time will be shown on the serial terminal at 9600 baud rate. The software can be putty, real term, dock light, and hyper terminal, etc.