assembly - PIC16F84_A Interrupt not working -
just started learning pic microcontrollers. reason, portb
remains 0x00
, interrupt never occurs.
;*** counter interrupt *** ;***** pic16fa4_a ************* org 0h status equ 03h porta equ 05h portb equ 06h trisa equ 85h trisb equ 86h intcon equ 0bh count equ 0ch count1 equ 08h count2 equ 09h goto main ;** interrup routine ** org 04h incf count,1 clrf portb ; clear rbo movlw 0ah subwf count btfss status,0 ;test carry flag goto go_on goto clear go_on bcf intcon,1 retfie clear clrf count bcf intcon,1 retfie ;** end of inerrupt routine ** main bsf intcon,7; global interrupt enable bsf intcon,4; rb0 interrupt enable bcf intcon,1; clear interrupt flag in case on bsf status,5 movlw 00h ;all ra pins output pins movwf trisa movlw 01h ;rb0 pin input pin movwf trisb bcf status,5 loop movfw count movwf porta ;put count in porta call delay ;delay movlw 01h movwf portb ;set rb0 ;expect program control go 04h (org) doesn't ;also, using watch option in debugger, portb stays 0h ;can help? goto loop delay loop1 decfsz count1,1 goto loop1 loop2 decfsz count2 goto loop2 return end
it seems want programatically trigger external interrupt on pin rb0/int
. this, need set rb0
pin output.
if @ figure 4-4 in page 17 of pic16f84a datasheet, can see block diagram pins rb3:rb0
. rb0/int
signal connected directly hardware pin via schmitt trigger buffer. means whatever signal present on pin going drive interrupt.
when set trisb0
bit 1
, 3-state buffer output in high impedance, meaning thing can drive rb0/int
signal external electrical signal connected pin.
if set trisb0
bit 0
, logic level write rb0
should able trigger interrupt.
Comments
Post a Comment