Barry Johnson
- 23rd January 2005, 05:29
I am having difficulty getting the following program to work. PIC is the 16F819. Using an ext. osc running at 16 MHz. When I run the program, it prints the "starting" and "running," then nothing more. This program has no actual purpose other than to help me understand how to proper use Timer1. Once running, I intend to use it in an actual project. I loaded the TMR1 register with $00FF as an arbitrary value. I know having a print command in the interrupt handler isn't wise, but it is just for debug at present.
Any guidance will be most appreciated.
Thanks,
Barry
' PicBasic Pro program that uses the Timer1
' interrupt for a "real-time clock."
' PIC is a 16F819
include "modedefs.bas" 'include serout defines
DEFINE OSC 16
loops VAR WORD
' initialize interrupts
INTCON = $00 ' disable and clear global interrupts, peripheral interrupts
PIR1 = $00 ' clear interupt flags
INTCON = $C0 ' enable global and peripheral interupts
PIE1 = $01 ' Enable TMR1 overflow interrupt
TMR1H = $00 ' load timer1 with $00FF
TMR1L = $FF
TRISB = %00000010 'All port b output except pin 1 (RX) is input
T1CON = %00000011 ' Turn on Timer1, prescaler = 1, ext. clock on
serout 2, T2400, ["starting", 10, 13]
on interrupt goto inthand
Pause 500
serout 2, T2400, ["running", 10, 13]
loops = 0
loop: ' endless loop with 1 ms pause
pause 1
goto loop
inthand:
PIR1 = $00 ' clear interrupt flags
PIE1 = $01 ' enable TMR1 interrupt
TMR1H = $00 ' load timer1 with $00FF
TMR1L = $FF
loops = loops + 1 ' increment counter of interrupts
serout 2, T2400, ["loops = ", #loops, 10, 13]
resume
End
Any guidance will be most appreciated.
Thanks,
Barry
' PicBasic Pro program that uses the Timer1
' interrupt for a "real-time clock."
' PIC is a 16F819
include "modedefs.bas" 'include serout defines
DEFINE OSC 16
loops VAR WORD
' initialize interrupts
INTCON = $00 ' disable and clear global interrupts, peripheral interrupts
PIR1 = $00 ' clear interupt flags
INTCON = $C0 ' enable global and peripheral interupts
PIE1 = $01 ' Enable TMR1 overflow interrupt
TMR1H = $00 ' load timer1 with $00FF
TMR1L = $FF
TRISB = %00000010 'All port b output except pin 1 (RX) is input
T1CON = %00000011 ' Turn on Timer1, prescaler = 1, ext. clock on
serout 2, T2400, ["starting", 10, 13]
on interrupt goto inthand
Pause 500
serout 2, T2400, ["running", 10, 13]
loops = 0
loop: ' endless loop with 1 ms pause
pause 1
goto loop
inthand:
PIR1 = $00 ' clear interrupt flags
PIE1 = $01 ' enable TMR1 interrupt
TMR1H = $00 ' load timer1 with $00FF
TMR1L = $FF
loops = loops + 1 ' increment counter of interrupts
serout 2, T2400, ["loops = ", #loops, 10, 13]
resume
End