|
|
View previous topic :: View next topic |
Author |
Message |
ATI Guest
|
Keypad and LCD menu system |
Posted: Fri Sep 18, 2009 5:08 am |
|
|
I plan to implement flex 4x4 keypd.
http://www.ccsinfo.com/forum/viewtopic.php?t=28022&start=14
The keypad should control the LCD menu on the way that you have one button for sliding down, one for confirmation and one for cancel.
Other buttons will be used for numeric stuff.
Suggestions ? |
|
|
carl
Joined: 06 Feb 2008 Posts: 240 Location: Chester
|
|
Posted: Fri Sep 18, 2009 8:09 am |
|
|
Hi ATI,
I used a menu sytem using a few buttons.
One button was - next option - this would just keep going around the options untill enter was pressed.
The second button was enter.
You will find the kbd_init(); helpful - this just needs to be changed to suit your needs. Here is an extract of my code I used:
Code: |
void main() { // perform main function.
menu_init(); // goto menu.c program.
while (1); // while true.
}
#use delay(clock=4000000) // Sets the delay times
void steady_init(void); // Declares steady_init as a void function
void menu_init(){ // Starts Menu program
char k; // Declares K as a character
lcd_init(); // Calls flex_lcd.c
kbd_init(); // Calls kbd.c
lcd_putc("\fPlease Choose\n"); // Write this to LCD
lcd_putc("Mode");
while (TRUE) { // While True
k=kbd_getc(); // Get value of button press
if(k!=0) // Carry on
if(k=='1'){ // If K = button 1 do this
lcd_putc("\fFor Steady State\n"); // Write this to LCD
lcd_putc("Press enter");
while (TRUE) { // While True
k=kbd_getc(); // Get value of button press
if(k!=0) // Carry on
if(k=='2'){ // If K = button 2 do this or else skip
lcd_putc("\fSteady State\n"); // Write this to LCD
lcd_putc("Chosen");
delay_ms(1500); // Delay loop
steady_init(); // Goto Steadystate.c
/////////////////////////////////////goto Steady State
Carl |
|
|
|
ATI Guest
|
|
Posted: Fri Sep 18, 2009 12:12 pm |
|
|
Thank you.
What do you think, what method would be the best way to switch between lcd messages but in up down manner. Like:
Message 1
- sub
Message 2
- sub
Message 3
- sub
Message 4
One key controls selection and one key is confirmation.
One key is canceling and one key is step back.
So, all together you have 4 control keys. |
|
|
Guest
|
|
Posted: Sat Sep 19, 2009 9:30 am |
|
|
This is the Thelmah solution but we have to find a way to set this to keypad reading. The code is arranged for multiple LCD messages ( 4 or 5 ) on 2x16 display. Suggestions ?
Code: | int8 menu(int8 max) {
//Routine to toggle between two displayed prompts, and allow one to be
//selected. Returns selected number.
int1 flag;
int8 selected;
int8 display_from;
int1 toggle;
//Start at the top of the list
selected=display_from=0;
toggle=true;
flag=true;
//Use zero relative for maximum
max--;
sys_tick=0;
LCD_PUTC('\f');
//Wait for key to be released
while (ENTER==0) ;
while (flag) {
while (sys_tick) ;
sys_tick=1;
if (toggle) {
LCD_GOTOXY(1,1);
printf(LCD_PUTC,"%s",&prompt[display_from][0]);
LCD_GOTOXY(1,2);
printf(LCD_PUTC,"%s",&prompt[display_from+1][0]);
toggle=false;
}
else {
if (selected==display_from) {
LCD_GOTOXY(1,1);
LCD_PUTC(" ");
LCD_GOTOXY(1,2);
printf(LCD_PUTC,"%s",&prompt[display_from+1][0]);
}
else {
LCD_GOTOXY(1,1);
printf(LCD_PUTC,"%s",&prompt[display_from][0]);
LCD_GOTOXY(1,2);
LCD_PUTC(" ");
}
toggle=true;
}
if (UP==0) {
if (selected>0) --selected;
if (selected<display_from) --display_from;
}
if (DOWN==0) {
if (selected<max) ++selected;
if (selected>(display_from+1)) ++display_from;
}
if (ENTER==0) flag=false;
}
return selected;
}
|
//-----------------------main--------------------
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);
// char k;
lcd_init(); // Always call this first.
kbd_init();
strcpy(&prompt[0][0],"FIRST MENU");
strcpy(&prompt[1][0],"SECOND MENU");
strcpy(&prompt[2][0],"THIRD MENU");
while(1)
{
int a;
a=menu(3);
} |
|
|
ATI Guest
|
|
Posted: Sat Sep 19, 2009 10:55 am |
|
|
Code: | void main()
{
char k;
kbd_init();
lcd_init();
printf(lcd_putc,"Line_1 \n"); // this is line one -- ONE
printf(lcd_putc,"Line_2 \n"); // this is line two -- TWO
printf(lcd_putc,"Line_3 \n"); // this is line three -- three
printf(lcd_putc,"Line_4 \n"); // this is line four -- four
while(TRUE)
{
k=kbd_getc();
if(k!=0)
{
if(k=='#')
printf(lcd_putc,"Confirm");
else if (k=='C')
printf(lcd_putc,"Back");
else if (k=='D')
printf(lcd_putc,"Main menu");
else
printf(lcd_putc,"%c", k);
}
}
} // main
|
i now i can not use line one, two three, four on such way , but i was thinking if there is other way to avoid using timers for such menu scroll ? |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|