Damn, the next time i'll test it before sending here.. many apologize. Change to this tested one ;o[
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
HexLed var byte
Delay VAR WORD
DelayLoop var Word
' Variable initialisation
'
PORTC=0 ' Reset all outputs on PORTC
PushHowManyTimes=0
HexLed=0
start:
Select Case PushHowManyTimes
case 1
gosub StayOn
Case 2
gosub Blink
case 3
gosub HEXonPORTC0_1
end select
goto start
StayOn:
led1 = 1
return
Blink:
Toggle led2
Delay = 500
Gosub DoDelay
return
HEXonPORTC0_1:
PORTC=HexLed
delay=500
gosub dodelay
HexLed=HexLed+1
if HexLed=4 then HexLed=0
return
' I do a Delay Loop to be sure getting all interrupt withou latency
'
DoDelay:
For DelayLoop=0 to Delay
pause 1
Next
RETURN
' Interrupt handler stuff here
'
DISABLE ' Disable interrupts in handler
ProcedureSwitcher:
INTCON.7 = 1 'disable all interrputs
PORTC=0 ' reset output to PORTC
HexLed=0
DelayLoop=Delay ' to exit the delay loop
PushHowManytimes=PushHowManytimes+1 ' Changing task
If PushHowManytimes=4 then PushHowManytimes=1
While PORTB.0 = 0 ' waiting untill
wend ' push-button is release
pause 100 ' debounce time
INTCON = %10010000 ' Enable RB0 interrupt
' reset RB0 interrupt flag
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