Thank you Darrel Taylor for steering me in this direction with your Instant Interrupts - Revisited thread. I tried your LED blink with a 16f876 and it worked great.
I now would like to add some other functions to the main program and would expect the LED to continue merrily on it's way while the program executes.
I found, however, this wasn't the case.
I'm trying to use the interrupt handler to increment a VAR which I then use with a case select for the output to the LCD.
The LED skips a beat occasionally and the output to the LCD is very inconsistent, as if only part of the output reaches the LCD before being interrupted.
Is this the wrong application for the interrupt?
Am I way off base here?
Pardon the code as most of it is cut and paste snippetts from other programs.
DEFINE LOADER_USED 1 'Only required if bootloader used to program PIC
define OSC 4
INCLUDE "modedefs.bas"
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
'OPTION_REG.7 = 0
'ADCON1 = 7 ' PORTA digital
PORTA = %00000000 'Set all INPUTS to 0
TRISA = %00111111 'Set PORTA RA0-RA5 to input
PORTB = %00000000 'Set all outputs to 0 (off)
TRISB = %00000000 'Set PORTB to all output
PORTC = %00000000 'Set all outputs to 0 (off)
TRISC = %00000000 'Set PORTC to all output
'::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
' Alias pins
'::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
scl VAR PORTA.1 'clock line for temp sensors
sda VAR PORTA.0 'data line for temp sensors
Relay1 var PORTB.7 'relay one is connected here
Relay2 var PORTB.6 'relay two is connected here
Relay3 var PORTB.5 'relay three is connected here
Relay4 var PORTB.4 'relay four is connected here
Relay5 var PORTB.3 'relay five is connected here
Relay6 var PORTB.2 'relay six is connected here
Relay7 var PORTB.1 'relay seven is connected here
Relay8 var PORTC.5 'relay eight is connected here
RST VAR PORTC.1 'reset line for RTC
IO VAR PORTC.3 'data line for RTC
SCLK VAR PORTC.2 'clock line for RTC
led1 var PORTC.0 'heartbeat LED
'::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
' Define Variables
'::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
rtcyear VAR BYTE 'year value to and from RTC BCD
rtcday VAR BYTE 'day value to and from RTC BCD
rtcmonth VAR BYTE 'month value to and from RTC BCD
rtcdate VAR BYTE 'date value to and from RTC BCD
rtchr VAR BYTE 'hour value to and from RTC BCD
rtcmin VAR BYTE 'minute value to and from RTC BCD
rtcsec VAR BYTE 'seconds value to and from RTC BCD
rtccontrol VAR BYTE '12/24 hour select for RTC 24hr selected
k var byte 'holding variable for conversions
display VAR byte 'count var for serout, udp, and lcd update
powerfail var bit 'lets me know the power failed
decyear VAR BYTE 'decimal year value from siteplayer
decday var byte 'decimal day value from siteplayer
decmonth VAR BYTE 'decimal month value from siteplayer
decdate VAR BYTE 'decimal date value from siteplayer
dechr VAR BYTE 'decimal hour value from siteplayer
decmin VAR BYTE 'decimal minute value from siteplayer
decsec VAR BYTE 'decimal seconds value from siteplayer
'((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
' Clear LCD and pause to start
'((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
Pause 5000
Serout2 PORTC.4,84,[$fe, 1]
Pause 1000
Serout2 PORTC.4,84,[$fe, 1]
Pause 1000
Serout2 PORTC.4,84,[$fe,1,$fe,128,"START"]
Pause 1500
'powerfail = 1
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
INT_ENABLE TMR1_INT ; enable external (INT) interrupts
ENDASM
T1CON = $31 ; Prescaler = 8, TMR1ON
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
'((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
' Main program loop - updates the LCD and siteplayer with the time
'and status of temperatures and pumps
'((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
mainloop:
GoSub gettime ' Reads time from the DS1302 RT clock
'GoSub showtime ' update siteplayer with the real time
GoSub showonlcd
goto mainloop
'((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
' Subroutine to read time from RTC
'((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
gettime:
RST = 1 ' Ready for transfer
ShiftOut IO, SCLK, LSBFIRST, [$bf] ' Read all 8 RTC registers in burst mode
ShiftIn IO, SCLK, LSBPRE, [ rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, rtccontrol]
RST = 0 ' Reset RTC
Return
'((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
'Subroutine to convert from Hex to Dec
'((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
h2d: ' Convert Hex coded time data -> decimal data
K = (K & $F )+((K>>4)*10)
Return
'((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
'Subroutine to convert from Dec to Hex
'((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
d2h: ' Convert Decimal -> Hex coded time data
K = (K DIG 1) * $10 + (K DIG 0)
Return
'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
TOGGLE LED1
DISPLAY = DISPLAY + 1
@ INT_RETURN
'((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
'Subroutine to display time on LCD and write current time to Siteplayer
'((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
showtime:
K = rtcyear
GoSub h2d
decyear = K
K = rtcmonth
GoSub h2d
decmonth = K
K = rtcdate
GoSub h2d
decdate = K
K = rtchr
GoSub h2d
dechr = K
K = rtcmin
GoSub h2d
decmin = K
K = rtcsec
GoSub h2d
decsec = K
'SerOut2 PORTC.6,84, [$00, $82, $12, dechr, rtcday, decmin]
'SerOut2 PORTC.6,84, [$00, $81, $17,decyear, decsec]
'SerOut2 PORTC.6,84, [$00, $81, $1e, decmonth, decdate]
RETURN
'((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
'Subroutine to display time on LCD
'((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
showonlcd:
select case display
case 11
Serout2 PORTC.4,84, [$fe, 1]
Serout2 PORTC.4,84, [$fe, 129, HEX2 rtchr, ":", HEX2 rtcmin,_
":", HEX2 rtcsec," ","DAY",HEX2 rtcday]
Serout2 PORTC.4,84, [$fe, 196, HEX2 rtcmonth,_
"/", HEX2 rtcdate, "/" , HEX2 rtcyear]
case 21
Serout2 PORTC.4,84, [$fe, 1]
Serout2 PORTC.4,84, [$fe,128,"slot 2"]
case 31
Serout2 PORTC.4,84, [$fe, 1]
Serout2 PORTC.4,84, [$fe,128,"slot 3"]
case 41
Serout2 PORTC.4,84, [$fe, 1]
Serout2 PORTC.4,84, [$fe,128,"slot 4"]
case 51
Serout2 PORTC.4,84, [$fe, 1]
Serout2 PORTC.4,84, [$fe,128,"slot 5"]
case 61
Serout2 PORTC.4,84, [$fe, 1]
Serout2 PORTC.4,84, [$fe,128,"slot 6"]
display = 0
end select
if display > 61 then display = 0
RETURN
'((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
'
'((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
goto mainloop
end
Thanks in advance for any input you may have.
Bookmarks