not too far. You didn't define the RB0 interrupt type (falling edge)
and i do my own version. Hope this work and help you.
Code:
' I/O definition
'
TRISC=0 ' Set PORTC as OUTPUT
TRISB.0=1 ' Set PORTB.1 as input
Led1 VAR PORTC.0 ' All LEDs
Led2 VAR PORTC.1 ' Connected between
Led3 VAR PORTC.2 ' RC pins and ground
Led4 VAR PORTC.3 ' via resistor
Led5 Var PORTC.4 '
' register and interrupt definition
'
ADCON1=7 'disable analog to digital converter
OPTION_REG=0 ' enable pull-up resistor on PORTb
' Interrupt on falling edge of RB0
INTCON = %10010000 ' Enable RB0 interrupt
ON INTERRUPT GOTO ProcedureSwitcher
' Variable definition
'
PushHowManyTimes var byte
Bright var byte
Delay VAR WORD
DelayLoop var Word
' Variable initialisation
'
PORTC=0 ' Reset all outputs on PORTC
PushHowManyTimes=0
start:
Select Case PushHowManyTimes
case 1
gosub StayOn
Case 2
gosub Blink
'
' Place your other procedure here
'
end select
goto start
StayOn:
PORTC.0 = 1
return
Blink:
Toggle PORTC.1
Delay = 500
Gosub DoDelay
return
' I do a Delay Loop to be sure getting all interrupt withou latency
'
DoDelay:
For DelayLoop=0 to Delay
pause 1
Next
' Interrupt handler stuff here
'
DISABLE ' Disable interrupts in handler
ProcedureSwitcher:
PORTC=0 ' reset output to PORTC
PushHowManytimes=PushHowManytimes+1 ' Changing task
If PushHowManytimes=5 then PushHowManytimes=1
DelayLoop=Delay ' to exit the delay loop
While PORTB.0 = 0 ' waiting for push-button release
wend
pause 50 ' debounce time
RESUME ' Return to main program
ENABLE ' Enable interrupts after handler
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks