Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
March 28, 2024, 11:39:57 11:39


Login with username, password and session length


Pages: [1]
Print
Author Topic: 4x4 keyboard and LCD menu  (Read 8035 times)
0 Members and 1 Guest are viewing this topic.
jesalf
Guest
« 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.
Logged
Parmin
Hero Member
*****
Offline Offline

Posts: 582

Thank You
-Given: 494
-Receive: 133


Very Wise (and grouchy) Old Man


« Reply #1 on: April 01, 2008, 12:47:01 00:47 »

Use a buffer and close the string when a "space" character is entered.
Logged

If I have said something that offends you, please let me know, so I can say it again later.
aal
Guest
« Reply #2 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:
Logged
yavuz
Active Member
***
Offline Offline

Posts: 106

Thank You
-Given: 62
-Receive: 216


WCSCG?


« Reply #3 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 Smiley
Logged
Kloswiski
Guest
« Reply #4 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
Logged
niktesla
Cracking Team
Active Member
****
Offline Offline

Posts: 214

Thank You
-Given: 166
-Receive: 280



« Reply #5 on: October 29, 2008, 12:51:40 00:51 »

@ aal

You could share the lcdtart.c file?


niktesla  Wink
Logged

Ensinar é aprender, compartilhar é se tornar mais forte!!!<br />Teaching is learning, sharing is becoming stronger!<br />NikTesla
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC