Sonsivri

Electronics => Pic C Languages => Topic started by: jesalf on March 31, 2008, 11:17:36 23:17



Title: 4x4 keyboard and LCD menu
Post by: jesalf on March 31, 2008, 11:17:36 23:17
Hi,

I´m working on a "menu option" with a PIC16F877, LCD and 4x4 keypad, the question, is how can I get a string from the keypad? I know how to get a char but what about a string.

Thanks.


Title: Re: 4x4 keyboard and LCD menu
Post by: Parmin on April 01, 2008, 12:47:01 00:47
Use a buffer and close the string when a "space" character is entered.


Title: Re: 4x4 keyboard and LCD menu
Post by: aal on April 04, 2008, 10:05:28 22:05
#include <16F877.h>
#device adc=10
#fuses HS,NOWDT,PROTECT,NOLVP
#use delay(clock=20000000)    //one instruction=0.2us
#use rs232(baud=9600, xmit=PIN_c6, rcv=PIN_c7)
#include <lcdtart.c>

#define  COLON_0  PIN_B0
#define  COLON_1  PIN_B1
#define  COLON_2  PIN_B2
#define  COLON_3  PIN_B3
#define  ROW_0    PIN_B4
#define  ROW_1    PIN_B5
#define  ROW_2    PIN_B6
#define  ROW_3    PIN_B7
void colon0()
{
output_high(COLON_0);
//delay_ms(100);
if (input(ROW_0))
{
//lcd_gotoxy( 1, 1);
printf(lcd_putc,"7");
printf("7");
}
else
{
if (input(ROW_1))
{
//lcd_gotoxy( 1, 1);
printf(lcd_putc,"8");
}
else
{
if (input(ROW_2))
{
//lcd_gotoxy( 1, 1);
printf(lcd_putc,"9");
}
else
{
if (input(PIN_B7))
{
//lcd_gotoxy( 1, 1);
printf(lcd_putc,"/");
}
/*else
{
lcd_gotoxy( 1, 1);
printf(lcd_putc," ");
}*/
}
}
}
output_low(COLON_0);
}

void colon1()
{
output_high(COLON_1);
//delay_ms(100);
if (input(ROW_0))
{
//lcd_gotoxy( 1, 1);
printf(lcd_putc,"4");
}
else
{
if (input(ROW_1))
{
//lcd_gotoxy( 1, 1);
printf(lcd_putc,"5");
}
else
{
if (input(ROW_2))
{
//lcd_gotoxy( 1, 1);
printf(lcd_putc,"6");
}
else
{
if (input(PIN_B7))
{
//lcd_gotoxy( 1, 1);
printf(lcd_putc,"X");
}
/*else
{
lcd_gotoxy( 1, 1);
printf(lcd_putc," ");
}*/
}
}
}
output_low(COLON_1);
}

void colon2()
{
output_high(COLON_2);
//delay_ms(100);
if (input(ROW_0))
{
//lcd_gotoxy( 1, 1);
printf(lcd_putc,"1");
}
else
{
if (input(ROW_1))
{
//lcd_gotoxy( 1, 1);
printf(lcd_putc,"2");
}
else
{
if (input(ROW_2))
{
//lcd_gotoxy( 1, 1);
printf(lcd_putc,"3");
}
else
{
if (input(PIN_B7))
{
//lcd_gotoxy( 1, 1);
printf(lcd_putc,"-");
}
/*else
{
lcd_gotoxy( 1, 1);
printf(lcd_putc," ");
}*/
}
}
}
output_low(COLON_2);
}

void colon3()
{
output_high(COLON_3);
//delay_ms(100);
if (input(ROW_0))
{
lcd_gotoxy( 1, 1);
//printf(lcd_putc,"C");
printf(lcd_putc,"                ");
lcd_gotoxy( 1, 1);
}
else
{
if (input(ROW_1))
{
//lcd_gotoxy( 1, 1);
printf(lcd_putc,"0");
}
else
{
if (input(ROW_2))
{
//lcd_gotoxy( 1, 1);
printf(lcd_putc,"=");
}
else
{
if (input(ROW_3))
{
//lcd_gotoxy( 1, 1);
printf(lcd_putc,"+");
}
/*else
{
lcd_gotoxy( 1, 1);
printf(lcd_putc," ");
}*/
}
}
}
output_low(COLON_3);
}

void main()
{
lcd_init();
lcd_gotoxy( 1, 1);
while(true)
{
colon0();
colon1();
colon2();
colon3();
delay_ms(200);
}
}
Code:
Code:


Title: Re: 4x4 keyboard and LCD menu
Post by: yavuz on April 07, 2008, 11:52:33 11:52
use a buffer like MyBuffer[20], as you know you can now put 19 characters in this buffer.
if your strings are fixed for example always 5 chars, test if the 6th char is pressed, or use
* or # or any other button for entering the string. Don't forget to collect the previous chars in the buffer.

for example:

Code:
char MyBuffer[20],input;  // buffer and current key input
int i=0;   // counter

while (input != '#')  // "#" key is assumed as ENTER key
{
  input = MyBuffer[i];
  i++;
}

hope this helps :)


Title: Re: 4x4 keyboard and LCD menu
Post by: Kloswiski on April 13, 2008, 04:21:20 04:21
CCS C compiler has a rich library and a lot of drivers. One of them deal with keyboard and keypad reading. check picc folder for some examples on this


Title: Re: 4x4 keyboard and LCD menu
Post by: niktesla on October 29, 2008, 12:51:40 00:51
@ aal

You could share the lcdtart.c file?


niktesla  ;)