Hi, okay I've been playing about with comparator interrupt now & think I have got the hang of it using flags. The code below is something little I came up with![]()
Now I think I would like to implement the nap command now, or do you think I should learn something else before jumping to the nap command?
Thanks again,
Rob
Code:'PIC 12F683 #CONFIG __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF #ENDCONFIG PAUSE 50 '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 int1 'interrupt handler is int1 INTCON = %11001000 'enable GIE and GPIE; clear GPIF PIE1 = %00001000 'enable comparator interrupt POT1 VAR CMCON0.6 'read potentiometer LED VAR GPIO.2 'led pin 5 loop1 var word 'loop1 counter bitTest var bit 'Debug test bit. Set/Clear in ISR and Check in main bitTest = 0 Loop1 = 0 ENABLE main: IF bittest = 1 THEN GOTO FLASH ENDIF LOW LED GOTO main ENABLE FLASH: do for loop1 = 1 to 1000 HIGH LED PAUSE 1 NEXT LOOP1 for loop1 = 1 to 1000 LOW LED PAUSE 1 NEXT LOOP1 IF bittest = 0 THEN GOTO main ENDIF LOOP DISABLE 'disable interrupts in handler int1: if PIR1.3 = 1 then 'Comparator Interrupt fired (must be cleared before resume) BITtest = pot1 ENDIF INTCON =%11001000 PIR1 = %00000000 'reset CMIF RESUME 'where left off ENABLE 'enable interrupts




Bookmarks