I have been trying to get instant interrupts working, using the comparator interrupt with a 16f88. In the data sheet it says:
"You may be getting stuck in an infinite loop with the comparator interrupt service routine if you
did not follow the proper sequence to clear the CMIF flag bit. First you must read the CMCON
register, and then you can clear the CMIF flag bit.
I used the following code ( after alot of trial and error) and it seems to work
Code:
@__CONFIG _CONFIG1, _INTRC_IO & _LVP_OFF & _BODEN_OFF
DEFINE OSC 8
LED1 VAR PORTB.1
VAR1 VAR BYTE
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler CMP_INT, _ToggleLED1, PBP, no
endm
INT_CREATE ; Creates the interrupt processor
INT_ENABLE CMP_INT ; enable Comparator interrupts
ENDASM
OSCCON = %01111000
ANSEL = %00000111
CMCON = %00000010
CVRCON = %11001000
TRISA = %00000011
TRISB = 0
PORTA = 0
PORTB = 0
Main:
PAUSE 1
GOTO Main
'---[TMR1 - interrupt handler]--------------------------------------------------
ToggleLED1:
VAR1 = CMCON
PIR2.6 = 0
TOGGLE LED1
@ INT_RETURN
It works if I put no in the ResetFlags column and in the interrupt handler read CMCON, then clear PIR2.6, which is the flag.
I would like to know if this is the correct way to do this or if there is a better way.
Thanks, Mike
Bookmarks