;===============================================================================
; PROGRAM JUMP TO START.
;===============================================================================
org RESET_V ;RESET VECTOR LOCATION.
goto START
;=============================================================================
;THIS IS THE INTERUPT ROUTINE. sss
;=============================================================================
SERVICE_INTRPT
org ISRV_V ;INTERRUPT VECTOR LOCATION.
movwf W_ISR_TEMP ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf STATUS_ISR_TEMP ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf PCLATH_ISR_TEMP ; save off contents of PCLATH register
movf PORTB,W ; read PORTB to clear any mismatch condition
bcf INTCON,GIE ;DISABLE ALL INTERRUPTS.
bcf INTCON,RBIF ;clear portb intrf
bcf flags,0 ;clear the key pressed flags bit
movf PORTB,W ;check sense of portb intr
andlw 0xf0
sublw 0x00 ;if PORTB 7~4 are high the key has been released
btfss STATUS,Z
bsf flags,0 ;else a key is pressed down
nop
;call DELAY30
ISREND
movf PCLATH_ISR_TEMP,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf STATUS_ISR_TEMP,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf W_ISR_TEMP,f
swapf W_ISR_TEMP,w ; restore pre-isr W register contents
retfie ; return from interrupt
;===============================================================================
; PROGRAM STARTS HERE.
;===============================================================================
START: ;sss
call PIC_INIT ;INITIALIZE FOR RC0-7 TO BE OUTPUTS.
call LCD_INIT ;NOW INITIALIZE THE LCD FOR 4 BIT OPERATION.
call DISPLAY ;DISPLAY "HELLO WORLD".
;===============================================================================
;ENABLE INTERRUPTS.
;===============================================================================
clrf PIE1
clrf INTCON ; clr ALL intr
movf PORTB,W ;read PORTB
bcf INTCON,INTF ;CLEAR INTERRUPT FLAG.
bsf INTCON,RBIE ;ENABLE INTERRUPT ON RB4-7 CHANGE.
bsf INTCON,GIE ;ENABLE ALL INTERRUPTS.
LOOP
;bsf INTCON,GIE ;restore intr
btfss flags,0 ;TEST FOR KEYPAD f=flags bit
goto LOOP ;not set so loop
bcf flags,0 ;clear the flag
call GETKEY ;KEY PRESSED NOW IN W (0 - 15).
;iorlw 0x30
;Call LCD_DISP_CHAR
call EVAL_KEY
bsf INTCON,GIE ;restore the intr
goto LOOP