try this
Code:' I/O definition ' TRISB = %10000001 ' Set PORTB (0)INPUT (1-5)OUTPUTS ' Variable Definition ' Switch VAR PORTB.0 Red VAR PORTB.1 Green VAR PORTB.2 Blue VAR PORTB.3 PushHowManyTimes VAR Byte PWMVariable VAR Byte ' PWM Variable 1-9 PWMVariableTimeOut VAR Byte ' 5 second Timeout (100 loops of 50mS) storedloop VAR Byte onled VAR Byte DelayVar VAR WORD ' register and interrupt definition ' CMCON = 7 ' Disable analog comparator on PORTA... not needed as now 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 initialisation ' 'PORTB = 0 ' Reset all outputs on PORTB PushHowManyTimes = 0 DelayVar = 0 'Main Procedure ' MainProcedure: Select Case PushHowManyTimes case 1 Gosub resetleds PWMVariable = 1 PWM BLue,1,100 Case 2 Gosub resetleds PWMVariable = 2 PWM blue,25,100 Case 3 Gosub resetleds PWMVariable = 3 PWM blue,255,100 Case 4 Gosub resetleds PWMVariable = 4 PWM green,1,100 Case 5 Gosub resetleds PWMVariable = 5 PWM green,25,100 Case 6 Gosub resetleds PWMVariable = 6 PWM green,255,100 Case 7 Gosub resetleds PWMVariable = 7 PWM red,1,100 Case 8 Gosub resetleds PWMVariable = 8 PWM red,25,100 Case 9 Gosub resetleds PWMVariable = 9 PWM red,255,100 End Select pauseus 100 delayvar=delayvar + 1 if delayvar = 50000 then delayvar=0 PushHowManyTimes=PushHowManytimes+1 If PushHowManyTimes=10 then PushHowManytimes=1 endif Goto Mainprocedure ResetLEDs: Low PortB.1 ' reset output to PORTB Low PortB.2 Low PortB.3 Low PortB.4 Low PortB.5 Return ' Interrupt handler stuff here ' Disable ' Disable interrupts in handler ProcedureSwitcher: PushHowManytimes = PushHowManytimes + 1 ' Changing task If PushHowManytimes = 10 Then PushHowManytimes=1 Here: While SWITCH = 0 ' waiting until wend ' push-button is release pause 100 ' debounce time If switch = 0 then here INTCON.1=0 ' reset RB0 interrupt flag DelayVar= 0 Resume ' Return to main program Enable ' Enable interrupts after ' handler




Bookmarks