Hello to all. I have taken the plunge and tried interrupt for the first time and I thought I understood it but I have stumbled in this simple code and would like someone to show me where I am going wrong. The interrupt works but when I added the LCDOUT command in the main loop things go wrong. I want to see how many times the button is pressed. The first time I press the button connected on RB0 the led on RB7 flashes. The second time it does not work. My understanding of interrupt is that it jumps to the ISR and then jumps back to the main loop and continues. Why would adding the LCDOUT command in the main loop cause the interrupt not work after the first time an interrupt occurs? When the button is pressed the LED does not flash indicating that it did not leave the ISR or that it is not seeing the interrupt occur. Any help would appreciated.
16F877A
MicroCode Studio Plus
' External Interrupt example
' PortB pin 7 Turn LED on
' Interrupt on Portb.0 (INTE) turns LED off
' Program waits .3 secs and turns LED back on
'LCD Parameters
'==============
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTD
Define LCD_RSBIT 2
Define LCD_EREG PORTD
Define LCD_EBIT 3
DEFINE LCD_LINES 2 'Number lines on LCD
define OSC 20
led var PORTB.7 'Establish name for portb.7
counter var byte
OPTION_REG = %01111111 'Enable portb pullups and
'rising edge on B0 interrupt
On interrupt goto myint 'Define interrupt handler
INTCON = %10010000 'Enable INTE interrupt
counter = 0
'**** Main Loop ***
loop:
lcdout $fe,2 'return to beginning of line
lcdout "Count = ",# counter 'display count value
high led 'turn led on
goto loop 'Do it forever
'*****Interrupt Handler *****
Disable 'No interrupts pass this point
myint:
low led 'if we get here turn led off
Pause 300 'wait .3 seconds
counter = counter + 1
INTCON.1 = 0 'clear interrupt flag
resume 'return to main program
enable
end
Bookmarks