Glad to hear if Rob.
You did not say what is happening only that it is not working.
I took a look at your code and several things jump out at me.
1. You are jumping into the deep end of the pool with testing "nap"
If would take a smaller step first. Set a flag in the ISR and resume. Then in the main act on the flag you set in the ISR.
This way you can see the effects of the ISR logic.
2. You have IOC.1 enabled, which is GP1, which you are using for the comparator. You need to comment out IOC.1.
3. You are not testing for which Interrupt is firing inside of your ISR. It is almost always a good practice to determine what interrupt caused the jump to the ISR.
4. At the end of your ISR you are not setting the INTCON register they way you think. I believe you have a typo in the value you are assigning to it.
I changed your code to the following which shows the changes.
See if this gets you along further.Code:'PIC 12F683 #CONFIG __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF #ENDCONFIG PAUSE 20 'wait for hardware to settle DEFINE OSC 4 '4mhz ocsillator ANSEL = %00000010 'pin 6 analog CMCON0 = %00000100 'comparator mode VRCON = %10101000 'voltage reference TRISIO = %00000010 'pin 6 input ON INTERRUPT GOTO SLSELECT 'interrupt handler is slselect INTCON = %11001000 'enable GIE and GPIE; clear GPIF 'IOC = %00000010 ' enable IOC1 (GPIO.1 Interrupt on change) PIE1 = %00001000 'enable comparator interrupt POT1 VAR CMCON0.6 'read potentiometer LED VAR GPIO.2 'led pin 5 bitTest var bit 'Debug test bit. Set/Clear in ISR and Check in maiin bitTest = 0 ENABLE main: 'HIGH LED 'light led LED = bitTest GOTO main 'repeat DISABLE 'disable interrupts in handler SLSELECT: 'IF POT1 = 1 THEN 'if <1.1v sleep 'NAP 1 'ELSE 'ENDIF if PIR1.3 = 1 then 'Comparator Interrupt fired (must be cleared before resume) bitTest = POT1 endif 'INTCON = %10001000 'enable GIE and GPIE; clear GPIF INTCON =%11001000 PIR1 = %00000000 'reset CMIF RESUME 'where left off ENABLE 'enable interrupts




Bookmarks