Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interfacing LCD and Keypad

Status
Not open for further replies.

ancymuhammed

Newbie level 5
Newbie level 5
Joined
Jan 11, 2010
Messages
10
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
ernakulam
Activity points
1,367
Hi all, I'm still new in here and need help about my project. i use the 4x3 keypad to enter the number and the number will be displayed in LCD. If here anyone has the mikroC code about it and please help me.I am using pic16f877a Thanks!!!!!
 

The code I tried is shown below,but it doesnot work,please help me

//RB1,RB2,RB3 are columns & RB4,RB5,RB6,RB7 are rows,A pull down resistor of 10K are attached to rows and a resistor of 470ohm is connected in series with columns
unsigned short kp ;
void interrupt() {
INTCON.GIE = 0; // Global interrupt OFF
PORTB.F1 = 1;
if(PORTB.F4 == 1) kp = '3';
if(PORTB.F5 == 1) kp = '6';
if(PORTB.F6 == 1) kp = '9';
if(PORTB.F7 == 1) kp = '#';
PORTB.F1 = 0;
PORTB.F2 = 1;
if(PORTB.F4 == 1) kp = '2';
if(PORTB.F5 == 1) kp = '5';
if(PORTB.F6 == 1) kp = '8';
if(PORTB.F7 == 1) kp = '0';
PORTB.F2 = 0;
PORTB.F3 = 1;
if(PORTB.F4 == 1) kp = '1';
if(PORTB.F5 == 1) kp = '4';
if(PORTB.F6 == 1) kp = '7';
if(PORTB.F7 == 1) kp = '*';
Lcd_Custom_Config(&PORTD,7,6,5,4,&PORTD,0,1,2);
Lcd_Custom_Cmd(LCD_CLEAR); // Clear display
Lcd_Custom_Cmd(LCD_CURSOR_OFF); // Cursor off
Lcd_Custom_Out(1, 1, "Key :");
Lcd_Custom_Chr(1, 10, kp);
PORTB = 0x00;
INTCON.RBIF = 0; // Reset the interrupt flag
INTCON.RBIE = 1; // RB Change interrupt ON
INTCON.GIE = 1; // Global interrupts ON
}
void main() {
Keypad_Init(&PORTB);
PORTB = 0x00;
INTCON = 0x00; // Interrupts are OFF
TRISB = 0xF1;
OPTION_REG = 0x00;
INTCON = 0x88; // Global interrupts & RB Change interrupts ON
}
 

Hai,

Try below program.Here i use LCD and 4*2 Keypad. Write some additional code for 4*4 keypad

unsigned short kp, cnt, oldstate = 0;
char txt[5];

void main()
{
cnt = 0;
trisc=0x00;
trisb=0xf0;
Lcd8_Config(&portc,&portd,1,3,2,7,6,5,4,3,2,1,0);
Lcd8_Cmd(LCD_CLEAR); // Clear display
Lcd8_Cmd(LCD_CURSOR_OFF); // Cursor off
Lcd8_Out(1,1,"start");

while(1)
{
portb=0x01;
while(portb.f4==1)
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,"1");
}
while(portb.f5==1)
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,"5");
}
while(portb.f6==1)
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,"9");

}
while(portb.f7==1)
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,"menue");
}





portb=0x02;
while(portb.f4==1)
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,"2");
}
while(portb.f5==1)
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,"6");
}
while(portb.f6==1)
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,"0");

}
while(portb.f7==1)
{
// Lcd8_Cmd(lcd_clear);
Lcd8_Out_CP("rst");
}
/* wirte rest key scanning code*/
}
}
 

try this code with with isis Untitled-2.jpg
unsigned short kp, cnt, oldstate = 0;
char txt[6];

// Keypad module connections
char keypadPort at PORTD;
// End Keypad module connections

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

void main() {
cnt = 0; // Reset counter
Keypad_Init(); // Initialize Keypad
//ANSEL = 0; // Configure AN pins as digital I/O
// ANSELH = 0;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 1, "1");
Lcd_Out(1, 1, "Key :"); // Write message text on LCD
Lcd_Out(2, 1, "Times:");

do {
kp = 0; // Reset key code variable

// Wait for key to be pressed and released
do
// kp = Keypad_Key_Press(); // Store key code in kp variable
kp = Keypad_Key_Click(); // Store key code in kp variable
while (!kp);
// Prepare value for output, transform key to it's ASCII value
switch (kp) {
//case 10: kp = 42; break; // '*' // Uncomment this block for keypad4x3
//case 11: kp = 48; break; // '0'
//case 12: kp = 35; break; // '#'
//default: kp += 48;

case 1: kp = 49; break; // 1 // Uncomment this block for keypad4x4
case 2: kp = 50; break; // 2
case 3: kp = 51; break; // 3
case 4: kp = 65; break; // A
case 5: kp = 52; break; // 4
case 6: kp = 53; break; // 5
case 7: kp = 54; break; // 6
case 8: kp = 66; break; // B
case 9: kp = 55; break; // 7
case 10: kp = 56; break; // 8
case 11: kp = 57; break; // 9
case 12: kp = 67; break; // C
case 13: kp = 42; break; // *
case 14: kp = 48; break; // 0
case 15: kp = 35; break; // #
case 16: kp = 68; break; // D

}

if (kp != oldstate) { // Pressed key differs from previous
cnt = 1;
oldstate = kp;
}
else { // Pressed key is same as previous
cnt++;
}

Lcd_Chr(1, 10, kp); // Print key ASCII value on LCD

if (cnt == 255) { // If counter varialble overflow
cnt = 0;
Lcd_Out(2, 10, " ");
}

WordToStr(cnt, txt); // Transform counter value to string
Lcd_Out(2, 10, txt); // Display counter value on LCD
} while (1);
}
 
  • Like
Reactions: Daham

    Daham

    Points: 2
    Helpful Answer Positive Rating
Any one have schematic and software( preferably in C) for PIC18*, LCD(text) and a PC keyboard with rs232.

That is a Dumb terminal with bi-directional communication between PC and Micro with Local Echo.
LCD can be GLCD too.

PIC is not mandatory, a 89c/s 2051/4051 is also most welcome. actually any Cheap and DIP package micro is ok.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top