i want to enable a RB on port change interrupt, (i have a keypad connected in RB0-RP7 ports)
the project displays a message in first line of a LCD display and after the interrupt enabled from a key pressed on a keypad a new message will be displayed in the second line. my problem is that i make probably something wrong and the interrupt doesnt work.
my code (subroutines for lcd initialization and display message are tested and the messages are displayed on the screen but my problem is that when i press any key no message in the second line occurs and i think my interrupt is wrong coded) :
edit: NEW CODE POSTED BUT INTERRUPT STILL DOESNT WORK
keypad is connects to portb
i use internal pull ups
also pin1,3,5 --> column0,1,2 is connected to 5V through 10K resistors
the project displays a message in first line of a LCD display and after the interrupt enabled from a key pressed on a keypad a new message will be displayed in the second line. my problem is that i make probably something wrong and the interrupt doesnt work.
my code (subroutines for lcd initialization and display message are tested and the messages are displayed on the screen but my problem is that when i press any key no message in the second line occurs and i think my interrupt is wrong coded) :
edit: NEW CODE POSTED BUT INTERRUPT STILL DOESNT WORK
keypad is connects to portb
i use internal pull ups
also pin1,3,5 --> column0,1,2 is connected to 5V through 10K resistors
Code:
List p=pic16f877
include "P16F877.INC"
__CONFIG _CP_OFF & _WDT_OFF &_BODEN_OFF & _PWRTE_ON & _HS_OSC & _WDT_OFF & _LVP_OFF & _CPD_OFF
ERRORLEVEL -302
#define E_line 0 ;from wiring
#define RS_line 1 ; -//-
#define RW_line 2 ; -//-
#define rbif 0
#define rbie 3
#define gie 7
cblock 0x20
delay_counter1
delay_counter2
temp ;variable store 8-bit data to send to LCD
GPR1
wtemp
pclathtemp
statustemp
endc
status equ 0x03
portd equ 0x08
porte equ 0x09
portb equ 0x06
porta equ 0x05
portc equ 0x07
intcon equ 0x0B
org 0h
goto portIni
org 04h ;interrupt vector
goto isr
; PORTS INITIALIZATION
;WIRING:
; PortD PortE PortB
; 0 --> lcd bus 0 0 --> lcd RS 0 --> keypad row0
; 1 --> lcd bus 1 1 --> lcd E 1 --> keypad row1
; 2 --> lcd bus 2 2 --> lcd R/W 2 --> keypad row2
; 3 --> lcd bus 3 3 --> keypad row3
; 4 --> lcd bus 4 4 --> not used
; 5 --> lcd bus 5 5 --> keypad column0
; 6 --> lcd bus 6 6 --> keypad column1
; 7 --> lcd bus 7 7 --> keypad column2
portIni
banksel porta
CLRF PORTA
CLRF PORTB
CLRF PORTE
CLRF PORTD
banksel TRISB
movlw b'00000111'
movwf TRISB
banksel TRISD
MOVLW B'00000000'
MOVWF TRISD
MOVWF TRISE
banksel OPTION_REG
movlw b'00001000'
movwf OPTION_REG
banksel ADCON1
MOVLW 0X06
MOVWF ADCON1
MOVLW 0xCF
MOVWF TRISA
BCF STATUS,RP0 ; Bank 0
BCF STATUS,RP1 ; Bank 0
main
call initializeLCD
call display_initial_message
;initialise interrupt
banksel portb
clrf portb
banksel intcon
bcf intcon,rbif
bsf intcon,rbie
bsf intcon,gie
banksel OPTION_REG
bcf OPTION_REG,7 ;RBPU: 0=portb pull ups are enabled
loop goto loop
isr
;saving registers
movwf wtemp
banksel status
swapf status,w
clrf status
movwf statustemp
banksel PCLATH
movf PCLATH,w
movwf pclathtemp
clrf PCLATH
banksel intcon
btfsc intcon,rbif
goto routine
goto isrend
routine
banksel lcd_line2
call lcd_line2
banksel clearLCD
call clearLCD
banksel display_initial_message
call display_initial_message
banksel intcon
bcf intcon,rbif
bsf intcon, rbie
;restore registers
movf pclathtemp,w
banksel PCLATH
movwf PCLATH
swapf statustemp,w
banksel status
movwf status
swapf wtemp,f
swapf wtemp,w
isrend
retfie
initializeLCD
call delay_20ms ;Wait 20ms for LCD to power up
bsf porte,E_line ;enable bit is high
bcf porte,RS_line ; RS is set for command mode
bcf porte,RW_line ; RW is set for write mode
call delay_1ms
movlw b'00111000' ;8bit data, 2 lines, 5x8 character
MOVWF portd ; Move Working Register to PORTB
CALL toggle_E ; Enter
CALL delay_1ms
movlw b'00001100' ; Display On, Cursor Underline Off, Blink Off
MOVWF portd
CALL toggle_E ; Enter
CALL delay_1ms
movwf b'00000110' ; cursor auto increment right, shift off
MOVWF portd
CALL toggle_E ; Enter
CALL delay_1ms
movwf b'00000001' ;clear display
MOVWF portd
CALL toggle_E ; Enter
CALL delay_1ms
BSF porte, RS_line ; LCD in Character mode
return
clearLCD
BCF porte, RS_line ; LCD in Command mode
MOVLW B'00000001' ; Command: Clear Display
MOVWF portd ; Move Working Register to PORTB
CALL toggle_E ; Enter
CALL delay_1ms
BSF porte, RS_line ; LCD in Character mode
RETURN
toggle_E
bcf porte,E_line ;data is enter on the falling edge
call delay_1ms
bsf porte,E_line ;E_line ready for the next data string
return
lcd_line2
bcf porte,RS_line
movlw b'11000000'
movwf portd
call toggle_E
call delay_1ms
bsf porte, RS_line
return
;lcd display initial message
display_initial_message
movlw d'0' ;table line to start printing from
movwf GPR1
call display_message
return
;routine for displaying characters on the lcd
display_message
movf GPR1,w
call message_table
movwf portd
xorlw b'00000000'
btfsc status,2
goto $+5
call toggle_E
call delay_1ms
incf GPR1
goto display_message
return
message_table
addwf PCL,f
retlw A'h' ;0
retlw A'e' ;1
retlw A'l' ;3
retlw A'l' ;4
retlw A'o' ;5
retlw A' ' ;6
retlw A'w' ;7
retlw A'o' ;8
retlw A'r' ;9
retlw A'l' ;10
retlw A'd' ;11
retlw H'0' ;12
; Delay Routines
;4MHz clock frequency
delay_1ms
movlw 0xc6
movwf delay_counter1
movlw 0x01
movwf delay_counter2
delay_1ms_0
decfsz delay_counter1, f
goto $+2
decfsz delay_counter2, f
goto delay_1ms_0
goto $+1
nop
return
delay_20ms
movlw 0x9e
movwf delay_counter1
movlw 0x10
movwf delay_counter2
delay_20ms_0
decfsz delay_counter1,f
goto $+2
decfsz delay_counter2,f
goto delay_20ms_0
goto $+1
nop
return
stop
goto stop
end
Last edited: