Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/28/99 16:19
Read: times


 
#781 - RE: 3 second timer interupt
You can't configure the timer to cause an interrupt so slowly. Assuming a 12MHZ crystal, the slowest interrupt rate is every .06536 seconds.

What you can do is make the timer interrupt every .05 seconds. Every time it interrupts, increment a counter. When the counter gets to 60, you know 3 seconds have passed. You could do that with:

MY_TIMER EQU 7Fh ;IRAM location

ORG 0000h
LJMP MAIN

ORG 000Bh
PUSH PSW ;Protect the PSW register
MOV TH0,#HIGH -50000 ;Reset timer
MOV TL0,#LOW -50000 ;Reset timer
INC MY_TIMER
CJNE MY_TIMER,#60,EXIT_INTERRUPT
MOV MY_TIMER,#00h ;Reset the timer
... YOUR CODE!
... Put the code you want to execute every 3 seconds here...
EXIT_INTERRUPT:
POP PSW ;Restore the PSW register
RETI ;Terminate interrupt

MAIN:
MOV TMOD,#01h ;Timer 0, mode 1 (16-bit timer)
MOV TH0,#HIGH -50000 ;Initialize timer
MOV TL0,#LOW -50000 ;Initialize timer
SETB ET0 ;Enable timer interrupt
SETB EA ;Enable Global interrupts
SETB TR0 ;Turn on timer 0
SJMP $ ;Cycle

If you execute the above code, the "YOUR CODE!" section of the program will execute once every 3 seconds, if you're using a 12MHZ crystal and a standard 8052.

Good luck,
Craig Steiner


List of 2 messages in thread
TopicAuthorDate
3 second timer interupt            01/01/70 00:00      
RE: 3 second timer interupt            01/01/70 00:00      

Back to Subject List