Trying to build interrupt-driven hardware. This is the simplest demo program to control a LED; it will eventually form part of a lighting sequencer but I need to get the basics sorted out first. The idea is that the main loop controls a data structure (in this case just a flag called LEDFLAG) and every ms or so, timer0 generates an interrupt and the routine transfers whatever is in LEDFLAG to the LED. This routine should flash the LED on and off. But it just sits there and does nothing!
#chip 16F690, 4
#config HS_OSC, WDT_OFF
#define FlashDelay 1 ms
'set up timer prescale
InitTimer0 (Osc,PS0_1/16)
'enable global and timer interrupts
set INTCON.GIE = ON
SET INTCON.T0IE = ON
'clear the interrupt flag
SET INTCON.T0IF = OFF
dir C0 out
start:
ledflag = 1
for i = 1 to 255
wait flashdelay
next i
ledflag = 0
for i = 1 to 255
wait flashdelay
next i
goto start
sub interrupt
if ledflag = 0 then set PORTC.0 OFF
if ledflag = 1 then set PORTC.0 ON
'clear the interrupt flag
SET INTCON.T0IF = OFF
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There isn't (or wasn't) meant to be an = in the Set command. Looking at the assembly generated, GCBASIC is actually setting INTCON.T0IF on.
I've now altered GCBASIC slightly so it will accept = in Set. You can either download the newest GCBASIC release (http://gcbasic.sourceforge.net/newfiles/update.zip) or remove the = from the Set command.
Something that you may notice with the newest version is that I've disabled the single letter variable name warning for i, j, k and l. This has no effect on the generated code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Trying to build interrupt-driven hardware. This is the simplest demo program to control a LED; it will eventually form part of a lighting sequencer but I need to get the basics sorted out first. The idea is that the main loop controls a data structure (in this case just a flag called LEDFLAG) and every ms or so, timer0 generates an interrupt and the routine transfers whatever is in LEDFLAG to the LED. This routine should flash the LED on and off. But it just sits there and does nothing!
#chip 16F690, 4
#config HS_OSC, WDT_OFF
#define FlashDelay 1 ms
'set up timer prescale
InitTimer0 (Osc,PS0_1/16)
'enable global and timer interrupts
set INTCON.GIE = ON
SET INTCON.T0IE = ON
'clear the interrupt flag
SET INTCON.T0IF = OFF
dir C0 out
start:
ledflag = 1
for i = 1 to 255
wait flashdelay
next i
ledflag = 0
for i = 1 to 255
wait flashdelay
next i
goto start
sub interrupt
if ledflag = 0 then set PORTC.0 OFF
if ledflag = 1 then set PORTC.0 ON
'clear the interrupt flag
SET INTCON.T0IF = OFF
end sub
One obvious issue I can see is this:
SET INTCON.T0IF = OFF
There isn't (or wasn't) meant to be an = in the Set command. Looking at the assembly generated, GCBASIC is actually setting INTCON.T0IF on.
I've now altered GCBASIC slightly so it will accept = in Set. You can either download the newest GCBASIC release (http://gcbasic.sourceforge.net/newfiles/update.zip) or remove the = from the Set command.
Something that you may notice with the newest version is that I've disabled the single letter variable name warning for i, j, k and l. This has no effect on the generated code.
That got it, thanks.