??? 03/17/05 01:01 Read: times |
#89831 - Weird result using timer1and0 together. |
Hi.
Please spare me, I'm new to assembly language so my codes may look dirty and unoptimized ^_^; (maybe my english language as well >_<;) Using assembler, I successfully wrote 2 codes to control 8051. One is an alarm clock. Another is a stopwatch. I implemented both codes SEPERATELY on real hardware and they work fine. But when I try to merge them into one code, the stopwatch is not functioning. I implement an alarm clock using timer1 and use timer2 to control the stop watch. Both runs in 16 bit mode. Timer1 is always counting(actually it's Real time clock code from the tutorial in this site but modified by me). But timer0 will start running(SETB TR0) only when the appropiate button is clicked. The problem here is when I press the button to start the stopwatch, weird result happen. Instead of seeing the stopwatch starting to count up, everything seems like went back to MAIN function and stay there, freezing. Posting whole 500+ lines of code here may be impossible so I'll bring only neccessary lines. ; Timer0 interrupt routines ; 1 Tick = 0.05 seconds. My stopwatch can count up to 0.1 seconds detailed. ORG 000Bh PUSH ACC PUSH PSW CLR TR0 MOV TH0,#HIGH RESET_VALUE2 MOV TL0,#LOW RESET_VALUE2 SETB TR0 DJNZ MTICKS,EXIT_RTC2 MOV MTICKS,#2 INC MSEC MOV R6,MSEC CJNE R6,#10,EXIT_RTC2 MOV MSEC,#0 INC SECOND MOV R6,SECOND CJNE R6,#60,EXIT_RTC2 MOV SECOND,#0 INC MINUTE MOV R6,MINUTE CJNE R6,#60,EXIT_RTC2 MOV MINUTE,#0 INC HOUR EXIT_RTC2: POP PSW POP ACC RETI ; Timer1 interrupt routines 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,#20 INC SECONDS MOV A,SECONDS CJNE A,#60,EXIT_RTC ADD A,TL1 ANL A,#00001111b MOV password,A MOV SECONDS,#0 INC MINUTES MOV A,MINUTES CJNE A,#60,EXIT_RTC MOV MINUTES,#0 INC HOURS EXIT_RTC: POP PSW POP ACC RETI MAIN: ;****** Initializing variables for stopwatch MOV RUNNING,#00 MOV TH0,#HIGH RESET_VALUE ;Initialize timer high-byte MOV TL0,#LOW RESET_VALUE ;Initialize timer low-byte MOV MTICKS,#02 MOV MSEC,#00 MOV HOUR,#00 MOV MINUTE,#00 MOV SECOND,#00 ;****** Initializing variables for alarm clock. MOV TH1,#HIGH RESET_VALUE MOV TL1,#LOW RESET_VALUE MOV ALARM,#01 MOV HOURS,#00 MOV MINUTES,#00 MOV SECONDS,#58 ; initialize clock at 00:58 so I can test alarm in 2 sec after each run. MOV HOURS2,#00 MOV MINUTES2,#01 ; set alarm clock to 00:01 MOV TICKS,#20 MOV TMOD,#00010001b SETB TR1 SETB EA SETB ET0 SETB ET1 ; Main loop trick: JB P3.0,SKIP01 JMP ADDMIN SKIP01: JNB P3.1,ADDHOUR JNB P3.2,ADDALAMMIN JNB P3.3,ADDALAMHOUR JB P2.6,SKIP02 ;Check for the button to start/stop the stopwatch JMP MODESELECT SKIP02: JB P2.7,SKIP03 ; Check if the button for Reseting the stopwatch is pressed. JMP RESET1 SKIP03: ; These lines is the LCD display functions which display both alarmclock and the stopwatch in the same time. ; *** Problem is here MODESELECT: ; Choosing which to do between start/pause the stopwatch MOV A,RUNNING CJNE A,#01,START01b jmp STOP01a START01b: MOV RUNNING,#01 SETB TR0 jmp trick STOP01a: MOV RUNNING,#00 CLR TR0 jmp trick When I pressed P2.6 button(make it go low). The program should have entered MODESELECT (like it did before I merge 2 codes together). Instead, the LCD display 00:00:58(these values are initialized in MAIN) and freeze here. How come it went back to MAIN ? I've checked everylines and found no way it can return to MAIN function. I post this because I'm just curious. There's no need to make this work or anything. And my apology for the very long post >_<; |
Topic | Author | Date |
Weird result using timer1and0 together. | 01/01/70 00:00 | |
timer2?? | 01/01/70 00:00 | |
My bad. | 01/01/70 00:00 | |
Yes, I assembled this code myself. | 01/01/70 00:00 | |
English | 01/01/70 00:00 | |
please complete user profile | 01/01/70 00:00 | |
you need working s/w for hello world | 01/01/70 00:00 | |
Re: | 01/01/70 00:00 | |
Re:Weird result using timer1and0 togethe | 01/01/70 00:00 | |
Thank you ^_^ | 01/01/70 00:00 | |
Register Bank | 01/01/70 00:00 | |
R6 ? | 01/01/70 00:00 | |
All the R's | 01/01/70 00:00 | |
just one thing | 01/01/70 00:00 | |
TF0 and TF1 interrupts![]() | 01/01/70 00:00 |