I'm still learning myself but i hope this works for your need or is a good pointer. This i have test and works on my development board. Each time you push the switch on the Interupt pin, the LEDs on PORTB light in sequence as you push the switch.
As i say, still learning myself, but willing to help where i can !!Code:' I/O definition ' TRISB = %10000001 ' Set PORTB (0)INPUT (1-5)OUTPUTS ' Variable Definition ' Switch VAR PORTB.0 PushHowManyTimes VAR Byte ' 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 'Main Procedure ' MainProcedure: Select Case PushHowManyTimes case 1 Gosub Routine_1 Case 2 Gosub Routine_2 Case 3 Gosub Routine_3 Case 4 Gosub Routine_4 Case 5 Gosub Routine_5 End Select Goto Mainprocedure Routine_1: High 1 Return Routine_2: High 2 Return Routine_3: High 3 Return Routine_4: High 4 Return Routine_5: High 5 Return ' Interrupt handler stuff here ' Disable ' Disable interrupts in handler ProcedureSwitcher: PushHowManytimes=PushHowManytimes+1 ' Changing task If PushHowManytimes=6 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 Resume ' Return to main program Enable ' Enable interrupts after ' handler
Regards,
Steve
Bookmarks