Thanks very much, that works great. I'm almost there with the main code now. The one thing i can't figure out though, is that with an Interrupt, should that stop what ever is being processed and then move onto the next procedural call? As part of the sequence i have set up at the moment is some PWM. If this procedure is being processed, and you push the button, it does remember the push, but doesn't move on until the full PWM part of the code has finished its cycle.
Heres an extract of working code which hopefully demonstartes what i mean. Its a piece of code which makes the LEDs look as if the are fading on and off. I would like to step to the next LED immediately the button is pushed, no matter at what position the fading is at. Can this be done?
Here it is:
' I/O definition
'
TRISC=0 ' Set PORTC as OUTPUT
TRISB.0=1 ' Set PORTB.1 as input
Red VAR PORTC.0 ' All LEDs
Green VAR PORTC.1 ' Connected between
Bright var byte
' 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
Delay VAR WORD
DelayLoop VAR Word
' Variable initialisation
'
PORTC=0 ' Reset all outputs on PORTC
PushHowManyTimes=0
start:
Select Case PushHowManyTimes
case 1
gosub FadeRed
Case 2
gosub FadeGreen
end select
goto start
FadeRed:
low Red
for bright = 0 to 255
PWM Red,Bright,1
next
for bright = 255 to 0 step -1
PWM Red,Bright,1
next
return
FadeGreen:
low red
for bright = 0 to 255
PWM Green,Bright,1
next
for bright = 255 to 0 step -1
PWM Green,Bright,1
next
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=3 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
Thank you again.




Bookmarks