The simple code below is intended to capture which button is pressed between RB7-RB4 that initiated an interrupt. During the interrupt the value of portb is saved to TEMP and the upper and lower nibble swapped of TEMP swapped. TEMP is then sent to porta for viewing. When any of the switches for RB7-RB4 is pressed the corresponding bit is set on PORTA and its LED illuminated. However, the LED is only turned on for the time the putton is pressed. Why is is this happening? I had expected the value on PORTA to remain until the next interrupt.
I hope my meny questions are helping others. I am now getting real value out of my development board and all the software I purchased and a lot of fun. Thank you for the great help you have been able to offer.
Code: Select all
; The following line embeds configuration data into the PICmicro
__CONFIG H'3FF9' ; XT mode
; __CONFIG _CP_OFF & _XT_OSC & _WDT_OFF & _PWRTE_OFF
; At start LED A0 should illunimate to show programm has started. When RB7-RB4 trigger interrupt this should
; illuminate a corresponding bit on portA to should which switch was pressed.
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
INCLUDE "C:\PROGRA~1\MPLAB\P16F84A.INC"
#DEFINE PAGE0 BCF STATUS,5
#DEFINE PAGE1 BSF STATUS,5
TEMP EQU H'21'
ORG 0
GOTO 5
ORG 4
GOTO INT_ROUTINE
ORG 5
CLRF PORTA
CLRF PORTB
BCF INTCON,RBIF ;CLEAR RB PORT CHANGE INTERRUPT FLAG
BSF INTCON,RBIE ;ENABLE RB PORT CHANGE INTERRUPT
BSF INTCON,GIE ;ENABLE GLOBAL INTERRUPT
PAGE1
MOVLW H'F0'
MOVWF TRISB ;CONFIG PORTB AS INPUTS
MOVLW H'0'
MOVWF TRISA ;CONFIG PORTA AS OUTPUTS
PAGE0
MOVLW H'1'
MOVWF PORTA ;TURN ON LED A0
WAIT
GOTO WAIT
INT_ROUTINE
PAGE0
MOVFW PORTB
MOVWF TEMP
SWAPF TEMP,0 ;SWAP UPPER AND LOWER NIBBLE OF TEMP AND SAVE IN WREG
MOVWF PORTA
BCF INTCON,RBIF ;CLEAR RB PORT CHANGE INTERRUPT FLAG
RETFIE
END