Hi guys, okay I've been having a mess today & I am quite happy with myself. I managed to use the comparator successfully, now I have added a button into the routine.
It is all doing what I want it to but I am having this big issue with de-bouncinghow do I sort this out, what is the best way? Do I need to read the button in a different way?
Here is the code -
Code:'PIC 12F683 #CONFIG __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF #ENDCONFIG DEFINE OSC 4 '4mhz ocsillator ANSEL = %00000001 'pin 7 analog CMCON0 = %00011110 'comparator mode VRCON = %10100000 'voltage reference TRISIO = %00101111 'pin 2,4,5,6,7 input PAUSE 50 'wait for hardware to settle ON INTERRUPT GOTO int1 'interrupt handler is int1 INTCON = %11001000 'enable GIE and GPIE; clear GPIF PIE1 = %00001000 'enable comparator interrupt IOC = %00001000 'pin 3 ioc RTPOT VAR CMCON0.6 'right trigger pot RTBITTEST var bit 'trigger debug test bit. Set/Clear in ISR and Check in main BUT VAR GPIO.3 'tactile button BUTBITTEST VAR BIT 'button test bit RTBITTEST = RTPOT 'initial reading BUTBITTEST = 0 'read 0 to start ENABLE main: IF RTBITTEST = 1 THEN GOTO RAPID ENDIF IF RTBITTEST = 0 THEN GOTO SLEEPY ENDIF GOTO main ENABLE RAPID: LOW GPIO.0 PAUSE 70 TRISIO.0 = 1 PAUSE 70 IF RTBITTEST = 0 THEN GOTO SLEEPY ENDIF IF BUTBITTEST = 1 THEN GOTO FLASH ENDIF GOTO RAPID ENABLE SLEEPY: HIGH GPIO.5 PAUSE 1000 TRISIO.5 = 1 PAUSE 1000 IF RTBITTEST = 1 THEN GOTO main ENDIF GOTO SLEEPY ENABLE FLASH: HIGH GPIO.5 PAUSE 300 TRISIO.5 = 1 PAUSE 300 IF BUTBITTEST = 1 THEN GOTO RAPID ENDIF GOTO FLASH DISABLE 'disable interrupts in handler int1: if PIR1.3 = 1 then 'Comparator Interrupt fired (must be cleared before resume) RTBITTEST = RTPOT ENDIF IF IOC.3 = 1 THEN BUTBITTEST = BUT ENDIF INTCON =%11001000 PIR1 = %00000000 'reset CMIF IOC = %00000000 'reset IOC.3 RESUME 'resume to where left off ENABLE 'enable interrupts


how do I sort this out, what is the best way? Do I need to read the button in a different way?


Bookmarks