Interfacing LCD and Keypad

General discussion on mikroC.
Post Reply
Author
Message
ansiya
Posts: 3
Joined: 04 Dec 2010 13:30

Interfacing LCD and Keypad

#1 Post by ansiya » 29 Dec 2010 05:37

I was new in mikroc,I am doing a project in which the number will be entered through 4*3 keypad and it will be displayed in an lcd.The code 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
}

sophtware
Posts: 60
Joined: 05 Jun 2008 02:35
Location: Dacula, GA
Contact:

Re: Interfacing LCD and Keypad

#2 Post by sophtware » 30 Dec 2010 05:12

Have you looked at the keypad example? It does exactly what you are trying to do.
Kind Regards,
Michael Lange

Post Reply

Return to “mikroC General”