Hi
I have the following code
When I press the button connected to gpio.3 the red led on gpio.4 lights up but goes out when I let go of the switch.
The green led connected to gpio.5 stops flashing (like it should because I have a T0IE =0). In simulation the red led remains on. When I am not pressing any buttons the green led flashes once per second.
Any idea why the led does not stay on like I want it to in the code? Am I setting up the interupt correctly. I have chopped and changed my code a few times and I get the flashing led like in the interupt section so maybe the timer setup is not completely crap?
I have the following code
Code:
'pic12f675 - 1sec timer interupt
TMR0 = 6
INTCON.T0IF = 0
INTCON.T0IE = 0 'enable Timer0 interrupts
INTCON.GIE = True 'enable all un-masked interrupts
OPTION_REG.T0CS = False 'set Timer0 clock source to internal instruction cycle clock
AllDigital
Config GPIO.0 = Output
Config GPIO.1 = Input
Config GPIO.2 = Input
Config GPIO.3 = Input
Config GPIO.4 = Output
Config GPIO.5 = Output
Dim msec As Word 'this willhold the milli seconds
INTCON.T0IE = 1 'enable Timer0 interrupts
main:
If GPIO.3 = 1 Then
INTCON.T0IE = 0 'enable Timer0 interrupts
GPIO.4 = 1
WaitMs 100
INTCON.T0IE = 1 'enable Timer0 interrupts
Endif
If GPIO.2 = 1 Then
INTCON.T0IE = 0 'enable Timer0 interrupts
GPIO.4 = 0
WaitMs 100
INTCON.T0IE = 1 'enable Timer0 interrupts
Endif
Goto main
End
On Interrupt 'interrupt routine
Save System
msec = msec + 1
If msec = 1000 Then
msec = 0
If GPIO.5 = 1 Then
GPIO.5 = 0
Else
GPIO.5 = 1
Endif
Endif
TMR0 = 6 '131
INTCON.T0IF = 0
Resume
When I press the button connected to gpio.3 the red led on gpio.4 lights up but goes out when I let go of the switch.
The green led connected to gpio.5 stops flashing (like it should because I have a T0IE =0). In simulation the red led remains on. When I am not pressing any buttons the green led flashes once per second.
Any idea why the led does not stay on like I want it to in the code? Am I setting up the interupt correctly. I have chopped and changed my code a few times and I get the flashing led like in the interupt section so maybe the timer setup is not completely crap?