Hi,
I posted this to the piclist, but thought (hoped!) I might get a faster reply here. I have been learning how to use the interrupts on a '628. I have it working, sort of. I want to have the interrupt occur when tmr1 overflows. The code I am using is:
@ DEVICE HS_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
DEFINE OSC 20 ' We're using a 20MHz crystal
ATN con 254 'prefix value for LCD addresses
CLR con 1 'LCD clear command
line2 con 192 'Address for 1st char of second line
rawCount var word
tmra var rawcount.lowbyte
tmrb var rawcount.highbyte
i var byte
pause 1000
SEROUT2 portb.0,16468,[atn,CLR] 'Clears LCD
pause 10
serout2 portb.0,16468,[ "Initializing.."]
pause 1000
SEROUT2 portb.0,16468,[atn,CLR] 'Clears LCD
intcon = %01000000
pie1 = 1
pir1 =1
on interrupt goto int
enable
tmr1l =0
tmr1h =0
T1CON = %00000101
pauseus 400
loop:
input portb.3
goto loop
int:
disable
T1CON = %00000000
tmra = tmr1l
tmrb = tmr1h
serout2 portb.0,16468,["TIMER: ",dec rawcount]
pause 500
SEROUT2 portb.0,16468,[atn,CLR]
pause 1000
tmr1l =0
tmr1h =0
T1CON = %00000101
pauseus 400
enable
resume
With this code, I alwats get a result of 2007. The 2000 is from the 400us pause. The 7 would be about what I expect the loop to take. Why is it immedailty jumping out of the loop insted of waiting for timr1 to roll over?
Thanks,
Jonathan
www.madlabs.info
Bookmarks