24 hour clock simulation in proteus using assembly language for 8051

24 Hour Digital Clock Simulation in Proteus using Assembly Language for 8051







This is a 24 hour clock simulation in Proteus. The time is displayed on six seven segment displays. As AT89C51 does not has 7x6=42 io pins to drive all the six displays at once, therefore I have used BCD to seven segment decoder ICs 7447 to drive them. 7447 IC takes only 4 pins to drive a seven segment display VS 7 pins for directly driving from the microcontroller. So a total of 4x6=24 pins are required to drive the six displays. Another solution was to multiplex the seven segment displays in the code but it was increasing its complexity level.

Assembly Language Code



ORG 00H
MOV R5,#00H ;SEC
MOV R6,#00H ;MIN
MOV R7,#00H ;HOUR
MOV P2,R5
MOV P3,R6
MOV P1,R7

;logic=if seconds=59 make it 00 and call minute so that it increments as well otherwise only
;display seconds and continue the loop
SECONDS:
CJNE R5,#59H,BIN_TO_BCD
MOV R5,#00H
CALL MINUTES
JMP DISPLAY_SEC

;logic= if the LSD of seconds is less than 9 just increment the seconds and display it otherwise
;add 7 so that it remains BCD and changes from 9 to 10 (and not from 9 to A in HEX)
BIN_TO_BCD:
MOV A,R5
ANL A,#0FH
CJNE A,#09H,INCREMENT_SEC ;9 FOUND AT LSD
MOV A,R5
ADD A,#7H
MOV R5,A
JMP DISPLAY_SEC

INCREMENT_SEC:
INC R5


DISPLAY_SEC:
MOV P2,R5
CALL DELAY
JMP SECONDS


;logic=if minutes=59 make it 00 and call hour so that it increments as well otherwise only
;display minutes and return to "seconds" loop
MINUTES:
CJNE R6,#59H,BIN_TO_BCD_MIN
MOV R6,#00H
CALL HOURS
JMP DISPLAY_MIN

;logic= if the LSD of minute is less than 9 just increment the minute and display it otherwise
;add 7 so that it remains BCD and changes from 9 to 10(and not from 9 to A in HEX)
BIN_TO_BCD_MIN:
MOV A,R6
ANL A,#0FH
CJNE A,#09H,INCREMENT_MIN ;9 FOUND AT LSD
MOV A,R6
ADD A,#7H
MOV R6,A
JMP DISPLAY_MIN

INCREMENT_MIN:
INC R6


DISPLAY_MIN:
MOV P3,R6
RET


;logic=if hours=23 make it 00 and display hours and return to minutes which will return to seconds loop
;otherwise increment hours, display and return
HOURS:
CJNE R7,#23H,BIN_TO_BCD_HOUR
MOV R7,#00H
JMP DISPLAY_HOUR

;logic= if the LSD of hour is less than 9 just increment the hour and display it otherwise
;add 7 so that it remains BCD and changes from 9 to 10 (and not from 9 to A in HEX)
BIN_TO_BCD_HOUR:
MOV A,R7
ANL A,#0FH   ;get rid of MSD and store only LSD in A
CJNE A,#09H,INCREMENT_HOUR ;9 FOUND AT LSD
MOV A,R7
ADD A,#7H ;Add 7 to keep it BCD and not HEX
MOV R7,A
JMP DISPLAY_HOUR

INCREMENT_HOUR:
INC R7


DISPLAY_HOUR:
MOV P1,R7
RET

DELAY:MOV R2,#1
THREE:MOV R1,#1
TWO:MOV R0,#255
ONE: DJNZ R0,ONE
DJNZ R1,TWO
DJNZ R2,THREE
RET

END