keypad interfacing with PIC18F4520 and LCD

Thread Starter

issaR

Joined Jan 2, 2021
8
I am trying to catch a number from the keypad and display it on my lcd after i press on the button, i am using PIC18F4520 but things are not going well. U can see the circuit in the pic below

image_2021-01-02_201950.png


Code:
#INCLUDE <P18F4520.INC>
CONFIG WDT    = OFF
CONFIG PBADEN = OFF

WHAT_BUTTON EQU 0x00
TIME        EQU 0X00
LCD_DATA    EQU LATD
LCD_CTRL    EQU LATE
RS          EQU RE0
RW          EQU RE1
EN          EQU RE2


ORG  0x00
BRA  INIT

ORG 0x08
CLRF  WHAT_BUTTON
CALL   LCDCLEAR
CALL   PERMANENT_MSG1
CALL   DELAY
BTFSS  PORTA,3
BRA $-2
MOVLW  '1'
;CALL   CHECK_KEYPAD
CALL   LCDPUTCHAR
CALL   DELAY
BCF    INTCON,INT0IF    
RETFIE


PERMANENT_MSG1 
    CALL LCDLIN1
    CALL  DELAY
    MOVLW 'I'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'N'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'S'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'E'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'R'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'T' 
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW ' '
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'I'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'D'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW ':'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW ' '
    CALL  LCDPUTCHAR
    CALL  DELAY
    RETURN

TEMPORARY 
    CALL  DELAY
    MOVLW 'T'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'E'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'M'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'P'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'O'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'R' 
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'A'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'R'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'Y'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW ':'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW ' '
    CALL  LCDPUTCHAR
    CALL  DELAY
    RETURN

WELCOME
    CALL  LCDCLEAR
    CALL  LCDLIN1
    CALL  DELAY
    MOVLW 'W'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'E'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'L'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'C'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'O'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'M'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'E'
    CALL  LCDPUTCHAR
    CALL  DELAY
RETURN

;CHECK_KEYPAD
;
;   BSF   LATA,0               ;SEND 1 TO COLUMN 1
;   BSF   LATA,1               ;SEND 1 TO COLUMN 2
;   BSF   LATA,2               ;SEND 1 TO COLUMN 3
;
;   BTFSC PORTA,3               ;CHECK IF #1 PRESSED
;   MOVLW '1'                  ;IF YES PUT #1 IN W REGISTER
;   BTFSC PORTA,4               ;CHECK IF #4PRESSED
;   MOVLW '4'                 ;IF YES PUT #4 IN W REGISTER
;   BTFSC PORTA,5               ;CHECK IF #7 PRESSED 
;   MOVLW '7'                 ;IF YES PUT #7 IN W REGISTER                
;   
;   BTFSC PORTA,3               ;CHECK IF #2 PRESSED 
;   MOVLW '2'                 ;IF YES PUT #2 IN W REGISTER
;   BTFSC PORTA,4               ;CHECK IF #5 RESSED
;   MOVLW '5'                ;IF YES PUT #5 IN W REGISTER
;   BTFSC PORTA,5               ;CHECK IF #8 PRESSED
;   MOVLW '8'                 ;IF YES PUT #8 IN W REGISTER
;               
;                
;   BTFSC PORTA,3               ;CHECK IF #3 PRESSED 
;   MOVLW '3'                  ;IF YES PUT #3 IN W REGISTER
;   BTFSC PORTA,4               ;CHECK IF #6 PRESSED
;   MOVLW '6'                  ;IF YES PUT #6 IN W REGISTER
;   BTFSC PORTA,5               ;CHECK IF #9 PRESSED
;   MOVLW '9'                 ;IF YES PUT #9 IN W REGISTER

;   RETURN


LCDPUTCHAR
    MOVWF LCD_DATA
    BSF   LCD_CTRL,RS
    BCF   LCD_CTRL,RW
    BSF   LCD_CTRL,EN
    NOP
    BCF   LCD_CTRL,EN
    RETURN

LCDCLEAR
    MOVLW B'00000001'
    CALL  LCDPUTCMD
    RETURN
    
    
LCDLIN1
    MOVLW 0x80
    CALL  LCDPUTCMD
    RETURN
    
LCDLIN2
    MOVLW 0xC0
    CALL  LCDPUTCMD
    RETURN

LCDPUTCMD
    MOVWF LCD_DATA
    BCF   LCD_CTRL,RS
    BCF   LCD_CTRL,RW
    BSF   LCD_CTRL,EN
    NOP
    BCF   LCD_CTRL,EN
    RETURN

DELAY
    MOVLW  0xFF       
    MOVWF  TIME         
    LOOP1
        NOP
        NOP 
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP 
        NOP
        NOP              
        DECF   TIME
        MOVLW  0X00 
         CPFSEQ TIME  
        BRA    LOOP1         
    RETURN

LCD_INIT
    BCF   LCD_CTRL,EN
    CALL  DELAY
    MOVLW 0X38                  ;INIT LCD 2 LIGNE,5X7 MATRIX
    CALL  LCDPUTCMD
    CALL  DELAY
    MOVLW 0X0F                  ;DISPLAY ON CURSOR ON 
    CALL  LCDPUTCMD
    CALL  DELAY
    MOVLW 0X06                    ;SHIFT CURSOR RIGHT
    CALL  LCDPUTCMD
    CALL  DELAY
    MOVLW 0X01                  ;CLEAR DISPLAY
    CALL  LCDPUTCMD
    CALL  DELAY
    CALL  LCDLIN1
    CALL  DELAY
    MOVLW A'W'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW A'E'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW A'L'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW A'C'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW A'O'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW A'M'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW A'E'
    CALL  LCDPUTCHAR
    CALL  DELAY
RETURN

INIT 
   MOVLW B'11111000'
   MOVWF TRISA 
   BSF   LATA,0
   BSF   LATA,1
   BSF   LATA,2  
   CLRF  TRISD
   CLRF  TRISE 
   CALL  LCD_INIT
   BCF   INTCON2,RBPU
   BCF   INTCON,INT0IF
   BCF   INTCON2,INTEDG0
   BSF   INTCON,INT0IE
   BSF   INTCON,GIE

BCL
  BRA BCL
   
END

Moderator edit: added code to post.
 

Attachments

Last edited by a moderator:

MrChips

Joined Oct 2, 2009
22,536
Firstly, learn how to output a string of characters stored in memory. When you have to do something repeatedly, always ask yourself, is there a better way to do this?

Do one step at a time.
1) Set three columns to outputs and send LOW to all columns.
2) Configure four rows as inputs using interrupt on pin change (or LOW).
3) Write an ISR (interrupt service routine) and test that you get an interrupt when any key is pressed.
 

jpanhalt

Joined Jan 18, 2008
10,963
I am not familiar with that chip; however, your keypad is on PortA and you have a switch on PortB,0. (Is that your "wait_button?") It appears you have enabled a falling edge interrupt for that pin, but have not enabled a WPU or external pull-up on it. It's floating.

1) Please comment your code.
2) Let us know your labels mean.

EDIT:
3) Where do you set up the oscillator for the chip? Or, is it just simulation?
4) Do you set PortA and PortB to digital? While a simulator may ignore the oscillator, the simulator I use does not ignore the need to change analog pins to digital.
 
Last edited:

BobaMosfet

Joined Jul 1, 2009
1,294
I am trying to catch a number from the keypad and display it on my lcd after i press on the button, i am using PIC18F4520 but things are not going well. U can see the circuit in the pic below

View attachment 226545


Code:
#INCLUDE <P18F4520.INC>
CONFIG WDT    = OFF
CONFIG PBADEN = OFF

WHAT_BUTTON EQU 0x00
TIME        EQU 0X00
LCD_DATA    EQU LATD
LCD_CTRL    EQU LATE
RS          EQU RE0
RW          EQU RE1
EN          EQU RE2


ORG  0x00
BRA  INIT

ORG 0x08
CLRF  WHAT_BUTTON
CALL   LCDCLEAR
CALL   PERMANENT_MSG1
CALL   DELAY
BTFSS  PORTA,3
BRA $-2
MOVLW  '1'
;CALL   CHECK_KEYPAD
CALL   LCDPUTCHAR
CALL   DELAY
BCF    INTCON,INT0IF   
RETFIE


PERMANENT_MSG1
    CALL LCDLIN1
    CALL  DELAY
    MOVLW 'I'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'N'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'S'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'E'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'R'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'T'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW ' '
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'I'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'D'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW ':'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW ' '
    CALL  LCDPUTCHAR
    CALL  DELAY
    RETURN

TEMPORARY
    CALL  DELAY
    MOVLW 'T'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'E'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'M'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'P'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'O'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'R'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'A'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'R'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'Y'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW ':'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW ' '
    CALL  LCDPUTCHAR
    CALL  DELAY
    RETURN

WELCOME
    CALL  LCDCLEAR
    CALL  LCDLIN1
    CALL  DELAY
    MOVLW 'W'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'E'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'L'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'C'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'O'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'M'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'E'
    CALL  LCDPUTCHAR
    CALL  DELAY
RETURN

;CHECK_KEYPAD
;
;   BSF   LATA,0               ;SEND 1 TO COLUMN 1
;   BSF   LATA,1               ;SEND 1 TO COLUMN 2
;   BSF   LATA,2               ;SEND 1 TO COLUMN 3
;
;   BTFSC PORTA,3               ;CHECK IF #1 PRESSED
;   MOVLW '1'                  ;IF YES PUT #1 IN W REGISTER
;   BTFSC PORTA,4               ;CHECK IF #4PRESSED
;   MOVLW '4'                 ;IF YES PUT #4 IN W REGISTER
;   BTFSC PORTA,5               ;CHECK IF #7 PRESSED
;   MOVLW '7'                 ;IF YES PUT #7 IN W REGISTER               
;  
;   BTFSC PORTA,3               ;CHECK IF #2 PRESSED
;   MOVLW '2'                 ;IF YES PUT #2 IN W REGISTER
;   BTFSC PORTA,4               ;CHECK IF #5 RESSED
;   MOVLW '5'                ;IF YES PUT #5 IN W REGISTER
;   BTFSC PORTA,5               ;CHECK IF #8 PRESSED
;   MOVLW '8'                 ;IF YES PUT #8 IN W REGISTER
;              
;               
;   BTFSC PORTA,3               ;CHECK IF #3 PRESSED
;   MOVLW '3'                  ;IF YES PUT #3 IN W REGISTER
;   BTFSC PORTA,4               ;CHECK IF #6 PRESSED
;   MOVLW '6'                  ;IF YES PUT #6 IN W REGISTER
;   BTFSC PORTA,5               ;CHECK IF #9 PRESSED
;   MOVLW '9'                 ;IF YES PUT #9 IN W REGISTER

;   RETURN


LCDPUTCHAR
    MOVWF LCD_DATA
    BSF   LCD_CTRL,RS
    BCF   LCD_CTRL,RW
    BSF   LCD_CTRL,EN
    NOP
    BCF   LCD_CTRL,EN
    RETURN

LCDCLEAR
    MOVLW B'00000001'
    CALL  LCDPUTCMD
    RETURN
   
   
LCDLIN1
    MOVLW 0x80
    CALL  LCDPUTCMD
    RETURN
   
LCDLIN2
    MOVLW 0xC0
    CALL  LCDPUTCMD
    RETURN

LCDPUTCMD
    MOVWF LCD_DATA
    BCF   LCD_CTRL,RS
    BCF   LCD_CTRL,RW
    BSF   LCD_CTRL,EN
    NOP
    BCF   LCD_CTRL,EN
    RETURN

DELAY
    MOVLW  0xFF      
    MOVWF  TIME        
    LOOP1
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP             
        DECF   TIME
        MOVLW  0X00
         CPFSEQ TIME 
        BRA    LOOP1        
    RETURN

LCD_INIT
    BCF   LCD_CTRL,EN
    CALL  DELAY
    MOVLW 0X38                  ;INIT LCD 2 LIGNE,5X7 MATRIX
    CALL  LCDPUTCMD
    CALL  DELAY
    MOVLW 0X0F                  ;DISPLAY ON CURSOR ON
    CALL  LCDPUTCMD
    CALL  DELAY
    MOVLW 0X06                    ;SHIFT CURSOR RIGHT
    CALL  LCDPUTCMD
    CALL  DELAY
    MOVLW 0X01                  ;CLEAR DISPLAY
    CALL  LCDPUTCMD
    CALL  DELAY
    CALL  LCDLIN1
    CALL  DELAY
    MOVLW A'W'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW A'E'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW A'L'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW A'C'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW A'O'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW A'M'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW A'E'
    CALL  LCDPUTCHAR
    CALL  DELAY
RETURN

INIT
   MOVLW B'11111000'
   MOVWF TRISA
   BSF   LATA,0
   BSF   LATA,1
   BSF   LATA,2 
   CLRF  TRISD
   CLRF  TRISE
   CALL  LCD_INIT
   BCF   INTCON2,RBPU
   BCF   INTCON,INT0IF
   BCF   INTCON2,INTEDG0
   BSF   INTCON,INT0IE
   BSF   INTCON,GIE

BCL
  BRA BCL
  
END

Moderator edit: added code to post.
This isn't the way to do it... beyond that, why are you doing it in assembly? Just want to, or don't realize C is plenty fast enough....?
 

Thread Starter

issaR

Joined Jan 2, 2021
8
I am not familiar with that chip; however, your keypad is on PortA and you have a switch on PortB,0. (Is that your "wait_button?") It appears you have enabled a falling edge interrupt for that pin, but have not enabled a WPU or external pull-up on it. It's floating.

1) Please comment your code.
2) Let us know your labels mean.

EDIT:
3) Where do you set up the oscillator for the chip? Or, is it just simulation?
4) Do you set PortA and PortB to digital? While a simulator may ignore the oscillator, the simulator I use does not ignore the need to change analog pins to digital.
I am using PortB,0 as interrupt when i press the button the lcd display a message, then i want to katch a number from the keypad on my lcd. I am new to this field , am sending high and low on portA pins . i modified the circuit and put portA,0 1 2 3 as output to the keypad and Port B,4 5 6 as input from keypad to catch it as rb interrupt. shoud I make PortB pins digital?
portB pins are always high now idc why the micro is reading it as rb interrupt all the time
you can see the code in the file below
 

Attachments

jpanhalt

Joined Jan 18, 2008
10,963
I am using PortB,0 as interrupt when i press the button the lcd display a message, then i want to katch a number from the keypad on my lcd. I am new to this field , am sending high and low on portA pins . i modified the circuit and put portA,0 1 2 3 as output to the keypad and Port B,4 5 6 as input from keypad to catch it as rb interrupt. shoud I make PortB pins digital?
portB pins are always high now idc why the micro is reading it as rb interrupt all the time
you can see the code in the file below
As suggested, let's go step by step. Where do you set PortB 4,5,and 6 as inputs?

Yes, PortB needs to be digital.

EDIT: As asked before, you need to comment your code. We know what the Assembly instructions do. What we don't know is what you are trying to do. For example, I searched on "TrisB" and could not find that anywhere. So, where do you think those pins are set to digital input?
 

Thread Starter

issaR

Joined Jan 2, 2021
8
As suggested, let's go step by step. Where do you set PortB 4,5,and 6 as inputs?

Yes, PortB needs to be digital.

EDIT: As asked before, you need to comment your code. We know what the Assembly instructions do. What we don't know is what you are trying to do. For example, I searched on "TrisB" and could not find that anywhere. So, where do you think those pins are set to digital input?
1) yes you right i forgot trisB
2)CONFIG PBADEN = OFF makes portb pins digital
3)and here is the code:

Code:
#INCLUDE <P18F4520.INC>
CONFIG WDT    = OFF
CONFIG PBADEN = OFF



WHAT_BUTTON EQU 0x00
TIME        EQU 0x01
LCD_DATA    EQU LATD
LCD_CTRL    EQU LATE
RS          EQU RE0
RW          EQU RE1
EN          EQU RE2


ORG  0X00
BRA  INIT

ORG    0X08
BRA  HP


ORG 0X18         
BRA LP

HP
  BTFSC INTCON,INT0IF         
  CALL  LCDCLEAR
  CALL  PERMANENT_MSG1
  BCF   INTCON,INT0IF
  RETFIE


LP
  CALL   CHECK_KEYPAD
  CALL   DELAY
  CALL   LCDPUTCHAR
  BCF    INTCON2,RBIF
  RETFIE

PERMANENT_MSG1
    CALL  LCDLIN1
    CALL  DELAY
    MOVLW 'I'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'N'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'S'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'E'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'R'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'T'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW ' '
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'I'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'D'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW ':'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW ' '
    CALL  LCDPUTCHAR
    CALL  DELAY
    RETURN


WELCOME
    CALL  LCDCLEAR
    CALL  LCDLIN1
    CALL  DELAY
    MOVLW 'W'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'E'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'L'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'C'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'O'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'M'
    CALL  LCDPUTCHAR
    CALL  DELAY
    MOVLW 'E'
    CALL  LCDPUTCHAR
    CALL  DELAY
RETURN

CHECK_KEYPAD

   BTFSS PORTB,4              ;CHECK IF #1 PRESSED
   MOVLW '*'                  ;IF YES PUT #1 IN W REGISTER
   BTFSS PORTB,5               ;CHECK IF #4PRESSED
   MOVLW '0'                 ;IF YES PUT #4 IN W REGISTER
   BTFSS PORTB,6               ;CHECK IF #7 PRESSED
   MOVLW '#'                 ;IF YES PUT #7 IN W REGISTER
   CALL  DELAY           

   BSF   LATA,1
   BTFSS PORTB,4               ;CHECK IF #2 PRESSED
   MOVLW '7'                 ;IF YES PUT #2 IN W REGISTER
   BTFSS PORTB,5               ;CHECK IF #5 PRESSED
   MOVLW '8'                ;IF YES PUT #5 IN W REGISTER
   BTFSS PORTB,6               ;CHECK IF #8 PRESSED
   MOVLW '9'                 ;IF YES PUT #8 IN W REGISTER              
   CALL  DELAY
            
   BTFSS PORTB,4               ;CHECK IF #3 PRESSED
   MOVLW '4'                  ;IF YES PUT #3 IN W REGISTER
   BTFSS PORTB,5               ;CHECK IF #6 PRESSED
   MOVLW '5'                  ;IF YES PUT #6 IN W REGISTER
   BTFSS PORTB,6               ;CHECK IF #9 PRESSED
   MOVLW '6'                 ;IF YES PUT #9 IN W REGISTER
   CALL  DELAY
            
   BTFSS PORTB,4               ;CHECK IF #3 PRESSED
   MOVLW '1'                  ;IF YES PUT #3 IN W REGISTER
   BTFSS PORTB,5               ;CHECK IF #6 PRESSED
   MOVLW '2'                  ;IF YES PUT #6 IN W REGISTER
   BTFSS PORTB,6               ;CHECK IF #9 PRESSED
   MOVLW '3'                 ;IF YES PUT #9 IN W REGISTER
   CALL  DELAY

   RETURN


LCDPUTCHAR
    MOVWF LCD_DATA
    BSF   LCD_CTRL,RS
    BCF   LCD_CTRL,RW
    BSF   LCD_CTRL,EN
    NOP
    BCF   LCD_CTRL,EN
    RETURN

LCDCLEAR
    MOVLW B'00000001'
    CALL  LCDPUTCMD
    RETURN
 
 
LCDLIN1
    MOVLW 0X80
    CALL  LCDPUTCMD
    RETURN
 
LCDLIN2
    MOVLW 0XC0
    CALL  LCDPUTCMD
    RETURN

LCDPUTCMD
    MOVWF LCD_DATA
    BCF   LCD_CTRL,RS
    BCF   LCD_CTRL,RW
    BSF   LCD_CTRL,EN
    NOP
    BCF   LCD_CTRL,EN
    RETURN

DELAY
    MOVLW  0XFF    
    MOVWF  TIME      
    LOOP1
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP           
        DECF   TIME
        MOVLW  0X00
         CPFSEQ TIME
        BRA    LOOP1      
    RETURN

LCD_INIT
    BCF   LCD_CTRL,EN
    CALL  DELAY
    MOVLW 0X38                  ;INIT LCD 2 LIGNE,5X7 MATRIX
    CALL  LCDPUTCMD
    CALL  DELAY
    MOVLW 0X0F                  ;DISPLAY ON CURSOR ON
    CALL  LCDPUTCMD
    CALL  DELAY
    MOVLW 0X06                    ;SHIFT CURSOR RIGHT
    CALL  LCDPUTCMD
    CALL  DELAY
    MOVLW 0X01                  ;CLEAR DISPLAY
    CALL  LCDPUTCMD
    CALL  DELAY
    CALL  WELCOME
    RETURN

INIT
   CLRF  TIME
   CLRF  TRISA
   BSF   LATA,0
   BSF   LATA,1
   BSF   LATA,2
   BSF   LATA,3
   CLRF  TRISD
   CLRF  TRISE
   SETF  TRISB
   CALL  LCD_INIT
   BSF   INTCON,PEIE 
   BSF   RCON,IPEN 
   BCF   INTCON2,RBPU
   BCF   INTCON2,INTEDG0
   BCF   INTCON,INT0IF
   BSF   INTCON,INT0IE
   BCF   INTCON,RBIF
   BCF   INTCON2,RBIP
   BSF   INTCON,RBIE
   BSF   INTCON,GIEH
   BSF   INTCON,GIEL

BCL
  BRA BCL

END
Moderators note : Please use code tags for pieces of code
 
Last edited by a moderator:

Ian Rogers

Joined Dec 12, 2012
818
Two things.. The RB0 has no pullup / pulldown so is floating...

Secondly... Already pointed out that your keypad routine IS NOT selecting columns... you need to place each row to a zero state to read a key... Your code does not do this...
 

MrChips

Joined Oct 2, 2009
22,536
TS needs to do one thing at a time.
Do not change state of columns. Set all columns to output LOW.
MCU should respond to interrupt on any of the four rows going LOW when any key is pressed.
Once you can get this part working the rest is simply programming.
 
Top