Hello guys,
My name is Tim and I'm currently in my second year of EE. I'm trying to make a 8051 Real Time Clock based on the tutorial from 8052.com
http://8052.com/tutrtc. I followed their code and make some changes according to the hardware that i am using and modify the code a bit to produce output to 6 7-segment displays (hook up with 7447) to display the time. I've got some questions that i don't understand, and since that 8052.com site forum is no longer active, I don't know anywhere else to ask except here. So here is the code
HOURS EQU 07CH
MINUTES EQU 07DH
SECONDS EQU 07EH
TICKS EQU 07FH
;CRYSTAL EQU 22118400
;TMRCYCLE EQU 12
;TMR_SEC EQU CRYSTAL/TMRCYCLE
;F50TH_OF_SEC EQU TMR_SEC*0.02
;F50TH_OF_SEC EQU 36864
;RESET_VALUE EQU 65536 - F50TH_OF_SEC
RESET_VALUE EQU 28672
ORG 0000H
LJMP _MAIN
ORG 001BH
PUSH ACC
PUSH PSW
CLR TR1
MOV TH1,#HIGH RESET_VALUE
MOV TL1,#LOW RESET_VALUE
SETB TR1
DJNZ TICKS,EXIT_RTC
MOV TICKS,#50
INC SECONDS
MOV A,SECONDS
CJNE A,#60,EXIT_RTC
MOV SECONDS,#0
INC MINUTES
MOV A,MINUTES
CJNE A,#60,EXIT_RTC
MOV MINUTES,#0
INC HOURS
MOV A,HOURS
CJNE A,#24,EXIT_RTC
MOV HOURS,#0
EXIT_RTC:
; Convert the time to BCD and display it to the 7-segment display
MOV A,SECONDS
MOV B,#10D
DIV AB
RL A
RL A
RL A
RL A
ADD A,B
MOV P2,A
MOV A,MINUTES
MOV B,#10D
DIV AB
RL A
RL A
RL A
RL A
ADD A,B
MOV P0,A
MOV A,HOURS
MOV B,#10D
DIV AB
RL A
RL A
RL A
RL A
ADD A,B
MOV P1,A
POP PSW
POP ACC
RETI
_MAIN:
MOV TH1,#HIGH RESET_VALUE
MOV TL1,#LOW RESET_VALUE
MOV TMOD,#10H
SETB TR1
MOV HOURS,#00
MOV MINUTES,#55
MOV SECONDS,#00
; 50 Ticks is needed for the timer to count a second
MOV TICKS,#50
SETB EA
SETB ET1
END
So according to the tutorial, if I want to start the timer to count from 23:00:00, i need only to set the HOURS value to 23 like this
MOV HOURS,#23
MOV MINUTES,#00
MOV SECONDS,#00
MOV TICKS,#50
But after i tried, it still starts at 00:00:00 after reset. I've been trying to find the problem and changing code here and there for 3 hours but i still got no luck.
Strangely, i have also tried to remove the initialization process
MOV HOURS,#23
MOV MINUTES,#00
MOV SECONDS,#00
MOV TICKS,#50
But it doesn't produce an error and it still starts from 00:00:00. I have no idea where i was doing wrong. I'm still a beginner with the 8051 programming, so i might have overlook something stupid here. I'm using M-IDE51 and FLIP to program the board. The board is custom made by my school. Any help is appreciated, and thank you for your time guys
EDIT : The solution for the problem is adding a loop like
loop: sjmp loop
Before the END statement of the program
Thumbs up for @PA0PBZ
Cheers
,
Best Regards,
Tim