I am trying to play with the interrupt function on the 16F88. I have read Section 15 of the data sheet, but most of it is above my skill level. I understand the basic concept of the interrupt, but don’t understand the notations INTCON<7>, PORTB<:4>.
I wrote a simple interrupt routine (rising edge, I think) below, but have been unable to reset the interrupt flag as discussed in several articles with statements like INTCON0.0, INTCON1.0. I don’t understand these 2 statements, but they were suggested in other posts.
I was able to reset the flag with INTCON = %10010000, but one post suggests that this is not the correct way, and it can lead to problems.
Also, in all of the posts (and the help file) there is the interrupt routine, the RESUME statement, then the ENABLE INTERRUPT statement. How does the enable statement ever fire if the resume comes first? Shouldn’t the interrupt be enables before the resume?
Can someone give me a simple explanation of working with the interrupts, a way to reset the flag and where to put the enable statement?
Thanks
--------------------------------------------------------------
This code works, but not sure if it is the best way to do it
OSCCON = $60
@ DEVICE INTRC_OSC_NOCLKOUT, MCLR_OFF, PROTECT_OFF, WDT_OFF
@ DEVICE PIC16F88
CMCON = 7 ' Comparators OFF
ANSEL = 0 ' A/D OFF -- Port pins all digital
INTCON = %10010000 ' Enable RB0 interrupt
ENABLE INTERRUPT
Output PORTA.0
Output PORTA.1
MainLED VAR PORTA.3
InterruptLED VAR PORTA.4
cntr Var Word
Low MainLED
Low InterruptLED
Loop:
On Interrupt goto Int
If cntr=2000 then
Toggle MainLED
cntr=0
EndIF
cntr=cntr+1
Goto Loop
Int:
Disable INTERRUPT
Toggle InterruptLED
PORTB=%00000000 ' Clear interrupt flag
Enable INTERRUPT
RESUME
Bookmarks