Project Report
Project Report
Project Report
Microcontroller-Based System Design
Project Name: Real Time Clock
Table of Contents
Introduction ..................................................................................................................................... 3
Objective ......................................................................................................................................... 3
Required Components ..................................................................................................................... 3
Circuit Diagram .............................................................................................................................. 4
Features ........................................................................................................................................... 4
Mandatory features: .................................................................................................................... 4
Additional features: ..................................................................................................................... 4
Working Principle ........................................................................................................................... 5
LCD Initialization: ...................................................................................................................... 5
Taking Input from Keypad: ........................................................................................................ 5
Clock Mechanism: ...................................................................................................................... 5
Mode selection: ........................................................................................................................... 5
Clock resetting: ........................................................................................................................... 6
Buzzing of alarm: ........................................................................................................................ 6
Toggling of AM/PM: .................................................................................................................. 6
Day display: ................................................................................................................................ 6
Flowchart .................................................................................................................................... 7
Code ................................................................................................................................................ 8
Hardware Implementation ............................................................................................................ 19
Problems Encountered .................................................................................................................. 20
Conclusion .................................................................................................................................... 20
Introduction
The implementation of the project involves the integration of both hardware and software
components to create a real-time clock system based on the 8051 microcontroller. A real-time
clock, which serves the purpose of timekeeping, is a computer clock that can be either
microcontroller-based or an integrated circuit. It is commonly utilized in various devices such as
computers, servers, and GPS systems to accurately track time and perform specific tasks at
predetermined intervals. The real-time clock system can be realized through the utilization of an
external pulse generator or by employing software programming internally. In this particular
project, the software approach has been employed to achieve the functionality of the real-time
clock. The project is done in two sections – one is the software section where the entire clock is
built in the simulation software Proteus and in the other section the clock was realized on an 80S52
microcontroller board.
Objective
• To create a system that can accurately measure time in precise 1-second intervals
• Implementation and testing in a simulation environment to ensure its accuracy and
reliability.
• Construction of the circuit according to the provided connection diagram.
• Programming into the microcontroller and integration with the circuit to create a fully
functional time-counting system.
• Realizing the real-time clock in both software simulation and hardware setup.
Required Components
1 Microcontroller AT89S52 1
2 Capacitor 47uF 2
3 Crystal Oscillator 11.0592 MHz 1
4 LCD Display 16*2 LCD 1
5 Keypad Matrix N/A 1
6 Active Buzzer 2.3 kHz 1
Circuit Diagram
Features
Mandatory features:
1. Use of LCD Display: A 16*2 LCD Display Module has been used to display the time in
HH: MM: SS format.
2. Clock Format: The clock supports 12 hr. format and it can show the part of the day with
AM/PM.
3. Day Format: The clock can also show the name of the day (i.e. SUN, MON, TUE etc.).
Additional features:
1. Configurable Clock: The time of the clock can be configured using a keypad.
2. Dual Format: The clock will support 24 hr. clock format alongside 12 hr. format.
3. Hourly Alarm: An active buzzer generates a beep sound after every hour to notify the
user.
4. Use of Delay: Programmed and calibrated delay has been used to generate 1-second delay
and run the clock.
Working Principle
LCD Initialization
The MYLCD lookup table will be utilized to initialize the necessary steps for starting the display.
Subsequently, the setup time display will become accessible.
Clock Mechanism
The right hand of the second, R0, will be incremented. If R0 is not equal to 10, it will return to the
loop and continue increasing R0. Once R0 reaches a value of 10, the left hand of the second, R1,
will be incremented by 1, and R0 will be reset to zero before returning to the loop. The program
will then check if R1 is equal to 6. If it is, the right hand of the minute, R2, will be incremented by
1, and R1 will be reset to zero before returning to the loop. If R1 is not equal to 6, it will simply
return to the loop. When R2 reaches a value of 10, the left hand of the minute, R3, will be
incremented by 1, and R2 will be reset to zero before returning to the loop. If R2 is not equal to
10, it will return to the loop. If R3 is equal to 6, the left hand of the hour, R4, will be incremented
by 1, and R3 will be reset to zero before returning to the loop.
Mode selection
The clock mode selection is determined by the state of pin P2.6. If P2.6 is set to 0, the clock will
operate in 24-hour mode. On the other hand, if P2.6 is not 0, the clock will be set to 12-hour mode.
In the case of the 24-hour mode, the clock will first check if the left digit of the hour, represented
by R5, is equal to 2. If it is, the clock will then verify if R4 is equal to 4. If R4 is indeed equal to
4, both R4 and R5 will be reset to their initial values, and the clock will return to its main loop.
However, if R4 is not equal to 4, the loop will be repeated. If R5 is not equal to 2, the clock will
check if R4 is equal to 10. If R4 is not equal to 10, the loop will be resumed. Otherwise, the value
of R5 will be incremented by one, and the value of R4 will be set to 0 before returning to the loop.
In contrast, when the 12-hour mode is selected, the clock will first evaluate if the left digit of the
hour, represented by R5, is equal to 1. If it is, the clock will then check if R4 is equal to 3. If R4 is
indeed equal to 3, R4 will be set to 1 and R5 will be reset to its initial value, and the cycle will
continue. However, if R4 is not equal to 3, the loop will be repeated. If R5 is greater than 1, the
clock will check if R4 is greater than 9. If R4 is not greater than 9, the loop will be resumed.
Otherwise, the value of R5 will be increased by one, while the value of R4 will be set to 0.
Clock resetting
Resetting the clock involves utilizing the reset pin, P2.7. When this pin is activated, it initiates a
process that clears the display, returns to the starting menu, and prompts for input values again.
The new values provided will be stored, and a new time cycle will commence.
Buzzing of alarm
To indicate the passing of every hour, the activation of R4 by incrementing it by 1 triggers a buzzer.
This buzzer will sound for a duration of 1 second. The buzzer is connected to 2.3. The buzzer gets
turned on at active low signal.
Toggling of AM/PM
The toggling of AM and PM functionality is only applicable when the 12-hour mode is active. In
this mode, the pin (P2.5) is utilized to select whether it is AM or PM. To perform the toggling
operation, the system first checks if the value is 0. If it is, the system stores the binary value
00000000B in the B register. Otherwise, it stores the binary value 11111111B in the B register.
Subsequently, the system checks if the value in the B register is zero. If it is, the display will show
'AM'. If it is not zero, the display will show 'PM'. After completing the 12-hour cycle, the value
stored in the B register will be altered and returned to the loop. At this point, the display will show
the toggled output of AM/PM.
Day display
There is a seventh input to indicate the day is taken from the user which is stored in RAM locations.
After 12 hours is passed in 12-hour mode if the PM is complemented then the day RAM location
is incremented to show the passing of 1 day. And for 24-hour mode when R4, R5 is cleared then
the day is incremented to show the passing of 1 day. And whenever the value is 7, when
incremented it is restored to 1 to indicate passing from Friday to Saturday.
Flowchart
Code
;--------------Start of coding------------
ORG 0H
;--------------I/O Initialization------------
;------------DISPLAY INITIALIZATION----------
S1:
MOV DPTR,#MSG1
D1:
CLR A
MOVC A,@A+DPTR
LCALL DISPLAY
LCALL DELAY
JZ S2 ;Runs rest of the code
INC DPTR
SJMP D1
SJMP START
LCALL DELAY
LCALL DELAY ;DELAY TO START THE CLOCK AFTER SET THE TIME
CLR A
MOV A,B
JZ J5 ; AM OR PM DECIDER
SJMP J6
MOV DPTR,#MY_NUMBER
;-------------------------CLOCK LOGIC------------------
;------------CLOCK FORMAT: HL HR : ML MR : SL SR---------
W2 : INC R0 ;INCREMENT SR
CJNE R0,#10,L2
SJMP L9
L9: MOV R0,#0
INC R1 ;INCREMENT SL
CJNE R1,#6,L2
SJMP L10
L10: MOV R1,#0
INC R2 ;INCREMENT MR
CJNE R2,#10,L2
SJMP L7
L7: MOV R2,#0
INC R3 ;INCREMENT ML
CJNE R3,#6,L2
SJMP L8
L8: MOV R3,#0
INC R4 ;INCREMENT HR
CLR BUZZ ;HOURLY BUZZER ALARM
LCALL DELAY3
SETB BUZZ
INC R0 ;COMPENSATION OF 1 SECOND FOR THE BUZZER
MODE_1:
CJNE R4,#10,L2
SJMP L3
L2: LJMP S_DATA
MODE_3:
CJNE R4,#10,Q2
SJMP Q3
Q2: LJMP S_DATA
SJMP Q6
Q6: LJMP S_DATA2
KEYPAD:
MOV A,#0FH
MOV P3,A ;MAKE PORT 3 AS INPUT
K1: MOV P3,#00001111B
MOV A,P3 ;READ ALL COLUMNS, ENSURE ALL KEYS OPEN
ANL A,#00001111B ;MASK UNUSED BITS
CJNE A,#00001111B,K1 ;CHECK TILL ALL KEYS RELEASED
COMMAND:
MOV PORT,A
CLR RS ;RS=0 FOR COMMAND
CLR RW ;R/W=0 FOR WRITE
SETB E ;E=1 FOR HIGH PULSE
ACALL DELAY
CLR E ;E=0 FOR H-TO-L PULSE
RET
DISPLAY:
MOV PORT,A
SETB RS ;RS=1 FOR DATA
CLR RW ;R/W=0 FOR WRITE
SETB E ;E=1 FOR HIGH PULSE
ACALL DELAY
CLR E ;E=0 FOR H-TO-L PULSE
RET
CJNE A,#1,DAY_2
MOV DPTR,#MY_DAY_1
LOOP_DAY_1:
CLR A
MOVC A,@A+DPTR ;GET ASCII CODE FROM TABLE
LCALL DISPLAY ;CALL DISPLAY SUBROUTINE
LCALL DELAY
JZ DAY_2
INC DPTR
SJMP LOOP_DAY_1
DAY_2:
CJNE A,#2,DAY_3
MOV DPTR,#MY_DAY_2
LOOP_DAY_2:
CLR A
MOVC A,@A+DPTR ;GET ASCII CODE FROM TABLE
LCALL DISPLAY ;CALL DISPLAY SUBROUTINE
LCALL DELAY
JZ DAY_3
INC DPTR
SJMP LOOP_DAY_2
DAY_3:
CJNE A,#3,DAY_4
MOV DPTR,#MY_DAY_3
LOOP_DAY_3:
CLR A
MOVC A,@A+DPTR ;GET ASCII CODE FROM TABLE
LCALL DISPLAY ;CALL DISPLAY SUBROUTINE
LCALL DELAY
JZ DAY_4
INC DPTR
SJMP LOOP_DAY_3
DAY_4:
CJNE A,#4,DAY_5
MOV DPTR,#MY_DAY_4
LOOP_DAY_4:
CLR A
MOVC A,@A+DPTR ;GET ASCII CODE FROM TABLE
LCALL DISPLAY ;CALL DISPLAY SUBROUTINE
LCALL DELAY
JZ DAY_5
INC DPTR
SJMP LOOP_DAY_4
DAY_5:
CJNE A,#5,DAY_6
MOV DPTR,#MY_DAY_5
LOOP_DAY_5:
CLR A
MOVC A,@A+DPTR ;GET ASCII CODE FROM TABLE
LCALL DISPLAY ;CALL DISPLAY SUBROUTINE
LCALL DELAY
JZ DAY_6
INC DPTR
SJMP LOOP_DAY_5
DAY_6:
CJNE A,#6,DAY_7
MOV DPTR,#MY_DAY_6
LOOP_DAY_6:
CLR A
MOVC A,@A+DPTR ;GET ASCII CODE FROM TABLE
LCALL DISPLAY ;CALL DISPLAY SUBROUTINE
LCALL DELAY
JZ DAY_7
INC DPTR
SJMP LOOP_DAY_6
DAY_7:
CJNE A,#7,DAY_8
MOV DPTR,#MY_DAY_7
LOOP_DAY_7:
CLR A
MOVC A,@A+DPTR ;GET ASCII CODE FROM TABLE
LCALL DISPLAY ;CALL DISPLAY SUBROUTINE
LCALL DELAY
JZ DAY_8
INC DPTR
SJMP LOOP_DAY_7
DAY_8:
RET
ORG 600H
MSG1: DB " INITIALIZE",0
MYLCD : DB 38H,0EH,01,06,80H,0
MY_COL: DB ":"
MY_NUMBER: DB "0","1","2","3","4","5","6","7","8","9"
MY_DAY_1: DB " DAY:SAT",0
MY_DAY_2: DB " DAY:SUN",0
MY_DAY_3: DB " DAY:MON",0
MY_DAY_4: DB " DAY:TUE",0
MY_DAY_5: DB " DAY:WED",0
MY_DAY_6: DB " DAY:THU",0
MY_DAY_7: DB " DAY:FRI",0
msg2: DB "A"
msg3: DB "P"
msg4: DB "M"
END
Hardware Implementation
Problems Encountered
1. Unpredictable behavior of Proteus: The simulator software occasionally exhibits
unexpected output and behaves in an unpredictable manner, which hinders the addition of
additional features and program improvements.
2. Display freezing: In Proteus, there are instances where the display freezes and retains the
time value for a longer duration than 1 second. However, following this glitch, the
subsequent time updates occur much faster than 1 second, thereby rectifying the anomaly.
3. Alarm glitch: When the buzzer beeps, the time freezes and skips the HH:00:00 time,
immediately transitioning to HH:00:01 after HH:59:59. This occurs because the buzzer
requires an additional second, causing the SR register to increment twice to compensate
for this delay.
4. Complexity of coding sequence: The complexity of the coding process has introduced
errors, including breaches in the flow chart and unexpected output. Numerous backups
and iterative approaches have been pursued to overcome this problem.
5. Display glitch: You have encountered a ‘pi’ looking character in the first line of the lcd.
We are not sure weather it is a display glitch or code error.
Conclusion
This project has helped us improve our skills in applying assembly language programming to
hardware, allowing us to effectively address real-world difficulties. Our understanding of assembly
language has significantly increased, as seen by the way several features have been implemented
successfully throughout the project. Even though some obstacles have emerged, it's important to
understand that these are manageable problems that offer chances to bring the project's unrealized
potential to light. Enhancing the project's overall development requires integrating the Real-Time
Clock (RTC) module and adding sophisticated features like timers and interrupts. This tactical
improvement strengthens the project's durability and promotes modularity, which is a major step
toward its overall improvement.