2:43AM
Junior Member level 1
- Joined
- Feb 6, 2010
- Messages
- 15
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Midwest USA
- Activity points
- 1,419
First and foremost, I would like to introduce myself to the forums. This is my first post! I mainly signed up for information and help on the older 8051 micros and learning new info on the AVR micros, which seem to be the most popular choice of quality uC's today. I've been messing with the 8051 for about 10 years now, but I regret to say that I don't do it enough to be a pro! So I need some help
Anyway, I have a prototype I'm working on with the AT89S51. I'm coding using uVision, and I code in ASM. Right now, my test program is to set up Timer0 and use it as an interrupt to pop out, move the ACC value to Port0, rotate the value in the ACC left one bit, return from the interrupt...and do it all over again. Eight LEDs are on Port0 (P0.0-P0.7). 16MHz crystal, 12 clocks per MC part.
My goal is a 10ms delay using Timer0. The timer delay is used to scan the LEDs so they appear constantly lit. I think 100Hz refresh should be good for a test.
But the problem seems to be that no matter what I load into TH0 and TL0, the delay doesn't change when looking at the LEDs on my prototype! The only time it changes is if I change the Timer0 mode (TMOD) to either the 8-bit or 13-bit modes...but even in those modes, changing TH0 and TL0 doesn't do a darn thing!!!
What am I doing wrong here? Here's the code. Thanks for the help!
;START
ORG 0000h;
LJMP NEXT;
;-------------------------------------------------------------------------
TIMER_0_INTERRUPT:
ORG 000Bh;
MOV P0, A;
RL A;
RETI ; Return from Interrupt to where the program came from
;-------------------------------------------------------------------------
NEXT:
;---------- 16-BIT TIMER SETUP -------------
; Configure and Enable timer. Enable Interrupts.
MOV TMOD, #01h ; 16-bit Timer0 Mode
MOV SCON, #0x0 ; Reset Serial Control
SETB ET0 ; Enable Timer0 Interrupt
SETB EA ; Enable Interrupts
MOV TH0, #0xCB ; Upper Byte
MOV TL0, #0xEB ; Lower Byte
CLR TF0 ; Clear Timer0 Flag
SETB TR0 ; Start Timer0
;--------------------------------------------------
MOV A, #01111111B ;
DO_NOTHING:
NOP;
NOP;
JMP DO_NOTHING;
END;
Anyway, I have a prototype I'm working on with the AT89S51. I'm coding using uVision, and I code in ASM. Right now, my test program is to set up Timer0 and use it as an interrupt to pop out, move the ACC value to Port0, rotate the value in the ACC left one bit, return from the interrupt...and do it all over again. Eight LEDs are on Port0 (P0.0-P0.7). 16MHz crystal, 12 clocks per MC part.
My goal is a 10ms delay using Timer0. The timer delay is used to scan the LEDs so they appear constantly lit. I think 100Hz refresh should be good for a test.
But the problem seems to be that no matter what I load into TH0 and TL0, the delay doesn't change when looking at the LEDs on my prototype! The only time it changes is if I change the Timer0 mode (TMOD) to either the 8-bit or 13-bit modes...but even in those modes, changing TH0 and TL0 doesn't do a darn thing!!!
What am I doing wrong here? Here's the code. Thanks for the help!
;START
ORG 0000h;
LJMP NEXT;
;-------------------------------------------------------------------------
TIMER_0_INTERRUPT:
ORG 000Bh;
MOV P0, A;
RL A;
RETI ; Return from Interrupt to where the program came from
;-------------------------------------------------------------------------
NEXT:
;---------- 16-BIT TIMER SETUP -------------
; Configure and Enable timer. Enable Interrupts.
MOV TMOD, #01h ; 16-bit Timer0 Mode
MOV SCON, #0x0 ; Reset Serial Control
SETB ET0 ; Enable Timer0 Interrupt
SETB EA ; Enable Interrupts
MOV TH0, #0xCB ; Upper Byte
MOV TL0, #0xEB ; Lower Byte
CLR TF0 ; Clear Timer0 Flag
SETB TR0 ; Start Timer0
;--------------------------------------------------
MOV A, #01111111B ;
DO_NOTHING:
NOP;
NOP;
JMP DO_NOTHING;
END;