18f4550 LCD and keypad Interface help

Status
Not open for further replies.

plugo

New Member
Hello guys,

I am starting a project to interface an LCD and a keypad. I have the LCD working correctly and putting a char to the screen. However, i am having trouble getting the keypad to input the key. here is my code: i have only done so for the first 4th column to test it I am using port B pins 0-4 and PORTA pins 0-2. Hope that you guys can help. Thanx!


//////////////////////// main.c /////////////////////////////////////////////\

#include <p18f4550.h>
#include <delays.h>
#include "io.h"
#define LCD_DATA PORTD

void main(void)
{
//// Pin Set Up
// LCD Pins |RS |R/W| E |D0 |D1 |D2 |D3 |D4 |D5 |D6 |D7 |
//Port on PIC |RC1|RC0|RC2|RD0|RD1|RD2|RD3|RD4|RD5|RD6|RD7|
char xc;
TRISD = 0x00;
TRISC = 0x00;

// delay for ~15ms
Delay10KTCYx(18);

InitIO();

ClearScreen();

GotoXY(0,0);
xc=get_key();

............................................................................................................................................................................................................................................................................................................................................

}

char get_key(void){

TRISA=0x00;
TRISB=0x0F;

//while(1){
PORTBbits.RB0 = 1;
PORTBbits.RB1 = 1;
PORTBbits.RB2 = 1;
PORTBbits.RB3 = 1;

if (PORTAbits.RA2 == 0){

if(!(PORTBbits.RB3)){ //is key D presed
Delay10KTCYx(156); //delay 20 ms
if(!(PORTBbits.RB3))
PutChar('D');
}
if((PORTBbits.RB2 != 1)){ // is key C pressed
Delay10KTCYx(156); //delay 20 ms
if(!(PORTBbits.RB2))
PutChar('C');
}
else if((PORTBbits.RB1 != 1)){ // is key B pressed
Delay10KTCYx(156);
if(!(PORTBbits.RB1))
PutChar('B');
}
else if((PORTBbits.RB0 != 1)){ // is key A pressed
Delay10KTCYx(156);
if(!(PORTBbits.RB0))
PutChar('A');
}

}
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…