??? 03/08/05 05:24 Read: times |
#89246 - Software-Based Real Time Clock problem. |
Hello.
Please note that I'm new to both 8051 and English language but I'll try my best ^^; According to the RTC tutorial found here http://www.8052.com/tutrtc.phtml ------------------------------------------------------ HOURS EQU 07Ch ;Our HOURS variable MINUTES EQU 07Dh ;Our MINUTES variable SECONDS EQU 07Eh ;Our SECONDS variable TICKS EQU 07Fh ;Our 20th of a second countdown timer RESET_VALUE EQU 19456 ; ***** I modified this line ORG 0000h ;Start assembly at 0000h LJMP MAIN ;Jump to the main routine ORG 001Bh ;This is where Timer 1 Interrupt Routine starts PUSH ACC ;We'll use the accumulator, so we need to protect it PUSH PSW ;Protect PSW flags CLR TR1 ;Turn off timer 1 as we reset the value MOV TH1,#HIGH RESET_VALUE ;Set the high byte of the reset value MOV TL1,#LOW RESET_VALUE ;Set the low byte of the reset value SETB TR1 ;Restart timer 1 now that it has been initialized DJNZ TICKS,EXIT_RTC ;Decrement TICKS, if not yet zero we exit immediately MOV TICKS,#20 ;Reset the ticks variable INC SECONDS ;Increment the second varaiable MOV A,SECONDS ;Move the seconds variable into the accumulator CJNE A,#60,EXIT_RTC ;If we haven't counted 60 seconds, we're done. MOV SECONDS,#0 ;Reset the seconds varaible INC MINUTES ;Increment the number of minutes MOV A,MINUTES ;Move the minutes variable into the accumulator CJNE A,#60,EXIT_RTC ;If we haven't counted 60 minutes, we're done MOV MINUTES,#0 ;Reset the minutes variable INC HOURS ;Increment the hour variable EXIT_RTC: POP PSW ;Restore the PSW register POP ACC ;Restore the accumulator RETI ;Exit the interrupt routine MAIN: MOV TH1,#HIGH RESET_VALUE ;Initialize timer high-byte MOV TL1,#LOW RESET_VALUE ;Initialize timer low-byte MOV TMOD,#10h ;Set timer 1 to 16-bit mode SETB TR1 ;Start timer 1 running MOV HOURS,#00 ;Initialize to 0 hours MOV MINUTES,#00 ;Initialize to 0 minutes MOV SECONDS,#00 ;Initialize to 0 seconds MOV TICKS,#20 ;Initialize countdown tick counter to 20 SETB EA ;Initialize interrupts SETB ET1 ;Initialize Timer 1 interrupt END ; The compiler said I should put 'END' here ---------------------------------------------- Ofcourse this code is just an implementation of RTC. We can include main program. I want to understand how the code work so I try to run and debug the program as is. Using a simulator called Isis 6 professional, I found few problems which I do not understand why. -Question 1.- After the FIRST execution of the command SETB ET1 ;Initialize Timer 1 interrupt The program immediately jump into timer1 interrupt routine. It should only jump into that routine when the timer1 overflow, is it not? @_@ ? -Question 2- After it jump into the interrupt routine, I continue debugging. After this line DJNZ TICKS,EXIT_RTC ;Decrement TICKS, if not yet zero we exit immediately The program exit interrupt routine, which is normal but... It returns to MAIN and continue executing EVERY lines in MAIN which include MOV TICKS,#20. Resulting in TICKS becomes 20 again. We are going to decrement it every time the timer1 overflow aren't we? But why this code set it back to 20 after each decrement? I think I must be misunderstadning something. Can anyone clear this up for me please? Thank you and please spare me for my horrible programming skill >_< ; |
Topic | Author | Date |
Software-Based Real Time Clock problem. | 01/01/70 00:00 | |
infinite loop | 01/01/70 00:00 | |
the above is wrong due to language | 01/01/70 00:00 | |
Thank you.![]() | 01/01/70 00:00 |