Here's the task: You will use the “External Interrupt” pin (pin name is “INT”) to generate an interrupt. This pin is tied to switch “S3” on the PICDEM 2 Plus eval board. Pushing this switch will generate the interrupt. We will configure this pin as in input, enable External Interrupts, enable Global Interrupts, and keep track of how many times we’ve generated this interrupt with a register we create called “Push_Count”.
Here's my code:
; PIC16F877A Configuration Bit Settings
; ASM source line config statements
#include <p16F877A.inc>
; CONFIG
; __config 0xFF7B
__CONFIG _FOSC_EXTRC & _WDTE_OFF & _PWRTE_OFF & _BOREN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _CP_OFF
cblock 0x020
COUNTERL
COUNTERH
PUSH_COUNT
endc
org 0x0000 ;put next line of code at address 0x0000
RESET_V goto START ;reset vector
START org 0x040
clrf PUSH_COUNT ;reset counter to 0
clrf INTCON ;clear INTCON register
bsf INTCON,INTE ;enable external int on INT pin
bsf INTCON,GIE ;enable global int
bsf STATUS,RP0 ;switch to bank 1
movlw b'00000001' ;set RB0 as input
movwf TRISB ;move value to TRISB
bcf STATUS,RP0 ;switch to bank
clrf PORTB ;clear PORTB output vector
bsf PORTB,0 ;turn on LED on RB0
goto $ ;loop here forever
INT_SERVICE org 0x004
call DELAY
incf PUSH_COUNT,f ;increment PUSH_COUNT
bcf INTCON,INTF ;clear int flag
retfie
DELAY decfsz COUNTERL ;decrement COUNTERL
goto DELAY ;if not zero, keep decrementing COUNTERL
decfsz COUNTERH ;decrement COUNTERH
goto DELAY ;if not zero, keep decrementing COUNTERH
return
END
My problem is that every time I'm pressing the S3 switch on PICDEM 2, the interrupt is not working and the value of the PUSH_COUNT register is not increasing/counting. Any problem with my code? I'm just new to PIC. Thanks
DELAYbe too long. How do you inspect the contents of 'PUSH_COUNT'? Are you running in debug mode? - jolati