??? 02/20/09 18:23 Read: times |
#162601 - edge-triggered interrupt |
I have connected the output from a signal generator to the P3.2 (INT0) of the 8051 (AT89S51).
I use R1 and R2 to store TH0 and TL0 respectively, and I can convert this 16-bit hex value into bcd value (stored in R3, R4, R5, R6 and R7 ) using the math subroutine, Hex2BCD. The LCD will show this value and I can do a calculation, 1/(bcd value * 1e-6) manually to compare it with the frequency shown in the signal generation. i.e. 20000 => 50Hz I don't why the value is only accurate at the first time (round) and after this, the value becomes almost half of the correct one and it's not stable. The following is my program (main + ISR) RAM_ADDR EQU 40H ORG 0000H LJMP MAIN ORG 0003H ;INT0 LJMP ISR_ET ;--------------MAIN PROGRAM---------------- ORG 30H MAIN: FLAG BIT PSW.5 FLAG2 BIT PSW.1 ACALL LCD_init MOV TMOD, #01H ;timer 0, mode 1 SETB TCON.0 ;falling edge-triggered external interrupt 0 MOV IE, #80H ;enable all interrupts HERE: CLR FLAG ;set when the timer is stopped CLR FLAG2 ;set when the timer is already started MOV TH0, #0 MOV TL0, #0 SETB IE.0 ;enable external interrupt 0 HERE3: JNB FLAG, HERE3 ;jump if FLAG=0 CLR IE.0 ;disable external interrupt 0 CLR TF0 ;clear timer 0 flag MOV R1, TH0 ;store TH0 MOV R2, TL0 ;store TL0 ACALL Hex2BCD ;R1(H), R2(L) ;result in R7(M) to R3(L) MOV R0, #RAM_ADDR MOV @R0, 07H INC R0 MOV @R0, 06H INC R0 MOV @R0, 05H INC R0 MOV @R0, 04H INC R0 MOV @R0, 03H MOV R0, #RAM_ADDR MOV R2, #5 AGAIN: MOV A, @R0 ORL A, #30H ;make it an ASCII code ACALL DATA_DISPLAY INC R0 DJNZ R2, AGAIN ACALL DELAY ACALL DELAY ACALL DELAY ACALL DELAY ACALL DELAY MOV A, #02H ;cursor: line 1, pos. 1 ACALL COMMAND SJMP HERE ISR_ET: JB FLAG2, HERE4 ;jump if FLAG2=1 SETB TR0 ;start timer 0 SETB FLAG2 RETI HERE4: CLR TR0 ;stop timer 0 CLR FLAG2 SETB FLAG RETI The strange thing is when I remove those "ACALL DELAY" in the main program and the LCD routine, the result is very accurate and stable. Does anyone know what's wrong with my program? I want to show the correct one on the screen and hold it like one second then jump back and start next round. Please help, thanks. Please help. Thanks. |
Topic | Author | Date |
edge-triggered interrupt | 01/01/70 00:00 | |
no throrough analysis, but | 01/01/70 00:00 | |
edge triggered interrupt | 01/01/70 00:00 | |
you need to read "the bible" | 01/01/70 00:00 | |
I did | 01/01/70 00:00 | |
edge triggered interrupt | 01/01/70 00:00 | |
already answered | 01/01/70 00:00 | |
edge triggered interrupt | 01/01/70 00:00 | |
Need better comments | 01/01/70 00:00 | |
Document "why" instead of "how" | 01/01/70 00:00 | |
Clear Interrupt flag before enabling interrupt | 01/01/70 00:00 | |
still imprecise | 01/01/70 00:00 | |
Some thoughts... | 01/01/70 00:00 | |
the remaining part of the program![]() | 01/01/70 00:00 |