Hi everyone. I'm struggling a bit to set up a basic external interrupt that makes LEDs flash a set numbe of times each time that it is triggered. In the simulations in MPLABX it works when i make a pulse hi stimulus input but when I practically input a high (5V) into my PIC18F45K22 chip it does not respond at all. I used INT0 which is mapped to pin RB0. Here is the code:
Help would be much appreciated.
Code:
list p=PIC18f45K22
#include "p18f45K22.inc"
;========== Definition of variables ==========
cblock 0x00 ;start at first address in general purpose memory
Delay1 ; Define two file registers for the
Delay2 ; delay loop
Count ; counter register address
endc
; Assign constant value to No_of_blinks
No_of_blinks set 0x03 ; check the difference between set and equ
;No_of_blinks equ 0x03 ; alternative to set
;========== Configuration bits ==========
CONFIG FOSC = INTIO67 ; Oscillator Selection bits (Internal oscillator block, port function on RA6 and RA7)
CONFIG WDTEN = OFF ; Watchdog Timer Enable bit (WDT is controlled by SWDTEN bit of the WDTCON register)
;========== Reset vector ==========
org 00h
goto Setup
;========== Interrupt vector ==========
org 08h
goto ISR ;goto interrupt service routine
;========== Setup ==========
Setup
; Initialize Port A
MOVLB 0xF
CLRF PORTA ; Initialize PORTA by clearing output data latches
CLRF LATA ; Alternate method to clear output data latches
CLRF ANSELA ; Configure I/O
CLRF TRISA ; All digital outputs
MOVLB 0x00
; Set up Port B pin B.0 for external interrupt
BSF TRISB,0x00 ; make IO Pin B.0 an input
CLRF ANSELB
; Set oscillator speed at 4 MHz
bsf OSCCON,IRCF0
bcf OSCCON,IRCF1
bsf OSCCON,IRCF2
; Set up external interrupt
CLRF INTCON ; clear all interrupt bits
BSF INTCON,INT0IE ; enable RB0 interrupt
BSF INTCON,GIE ; enable interrupts
;========== Main program ==========
Main
BSF PORTA,4 ; turn on LED A.4
NOP
NOP
NOP
GOTO Main
;========== Interrupt service routine ==========
ISR ; GIE automatically cleared upon branching to interrupt vector
MOVLW No_of_blinks
MOVWF Count
flash BCF PORTA,4 ; turn off LED
CALL Delay_loop
BSF PORTA,4 ; turn on LED
CALL Delay_loop
DECFSZ Count,1
GOTO flash
BCF INTCON,INT0IF ; clear RB0 interrupt flag
RETFIE ;GIE automatically set upon return from ISR
;========== Delay subroutine ==========
Delay_loop
MOVLW 0xAA
MOVWF Delay2
Go1
MOVLW 0xBB
MOVWF Delay1
Go2
DECFSZ Delay1,f
GOTO Go2
DECFSZ Delay2,f
GOTO Go1
RETURN
end