Right I have changed the code from what Tabsoft last posted, so now there are 3 modes each blinking led at a different rate depending on the mode. Every tap of the button is supposed to goto the next mode.
Something weird is happening though, each tap of the button is reversing the mode lol. So instead of going forwards to the next mode, its going backwards (should go mode 1 > mode 2, but is going Mode 1 > mode 3 > mode 2).
Any ideas? here is the code -
Code:'PIC 12F683 #CONFIG __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF #ENDCONFIG 'DEFINE OCS 4 '4mhz ocsillator DEFINE OSC 4 '4mhz ocsillator ANSEL = 0 'all I/O digital CMCON0 = 7 'comparator off LED VAR GPIO.0 'LED pin 7 loop1 var word ' Loop 1 Counter (word for 0 to 65535 increments) ModeFlag var bit ' Bit to determine what state of IOC.3 is '*****Initlaze Vars***** loop1 = 0 ModeFlag = 0 '*********************** ON INTERRUPT GOTO modeselect 'interrupt handler is modeselect INTCON = %10001000 'enable GIE and GPIE; clear GPIF IOC = %00001000 ' enable IOC3 (GPIO3 Interrupt on change) ENABLE mode1: do for loop1 = 1 to 1000 HIGH LED 'led on 'PAUSE 1000 'delay 1 second pause 1 '1 ms if ModeFlag = 1 then gosub mode2 endif next loop1 for loop1 = 1 to 1000 LOW LED 'led off 'PAUSE 1000 'delay 1 second pause 1 '1 ms if ModeFlag = 1 then gosub mode2 endif next loop1 'GOTO mode1 'repeat loop ENABLE mode2: do for loop1 = 1 to 500 HIGH LED 'led on 'PAUSE 500 'delay 0.5 second pause 1 '1 ms if ModeFlag = 1 then gosub mode3 endif next loop1 for loop1 = 1 to 500 LOW LED 'led off 'PAUSE 500 'delay 0.5 second pause 1 '1 ms if ModeFlag = 1 then gosub mode3 endif next loop1 'GOTO mode2 'repeat loop ENABLE mode3: DO for loop1 = 1 to 50 HIGH LED 'led on 'PAUSE 50 'delay 0.05 second pause 1 '1 ms if ModeFlag = 1 then gosub mode1 endif next loop1 for loop1 = 1 to 50 LOW LED 'led off 'PAUSE 50 'delay 0.05 second pause 1 '1 ms if ModeFlag = 1 then gosub mode1 endif next loop1 'GOTO mode3 'repeat loop DISABLE 'disable interrupts in handler modeselect: if INTCON.0 = 1 then 'one of the GPIO<5:0> pins changed state (must be cleared in software) 'next mode 'Set the ModeFlag ModeFlag = ~ ModeFlag endif INTCON = %10001000 'enable GIE and GPIE; clear GPIF RESUME 'return to where left off ENABLE 'enable interrupts end 'got here by mistake




Bookmarks