Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Frustrated: 8051 Timer Problem Has Got Me Scratchin' My Head

Status
Not open for further replies.

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;
 

Re: Frustrated: 8051 Timer Problem Has Got Me Scratchin' My

Besides knowing 8051 assembler, you should also know, how the 8051 hardware works, You may want to check the 80S51
datasheet. There's no auto reload in 16-Bit timer 0 mode. Timer 2 has it, in contrast.
 

Re: Frustrated: 8051 Timer Problem Has Got Me Scratchin' My

FvM said:
Besides knowing 8051 assembler, you should also know, how the 8051 hardware works, You may want to check the 80S51
datasheet. There's no auto reload in 16-Bit timer 0 mode. Timer 2 has it, in contrast.

You're right! I know what's happening now...the 16-bit timer was always rolling over back to 00h/00h for TH0/TL0, thus always making the delay about 50ms!

Thanks for the kick in the pants!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top