![]() | ![]() | ![]() |
| | #1 |
|
How would I make a menu like this one: YouTube - Menu LCD y PIC16F877A I would like to write a menu in c, similar to the one above I am using the pic16f628. I am able to have a button display a message and then go back to the main screen but i have no idea how to go any further to achieve the above. Can anyone help or point me in the right direction please? | |
| |
| | #2 |
| Code:
if (youdidit_once)
{
do it again
else
trysome_more
}
__________________ Creationists have a world of evidence Last edited by AllVol; 23rd October 2009 at 11:16 PM. | |
| |
| | #3 |
|
Only if it was that easy heh.... You should first make A flowchart of how u want your menu to work this way you won't get to confused later on. Once u have done that u can write code to show the menu items fairly simple.. Since I don't work tomorrow I will take u through a few steps showing u how to make a simple menu. But it will be for my temp sensor. The idea is to teach u how to go about doing it and not just doing ur work for you. Sorry I'd there are any typos I'm using a iPod touch to write this heh
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #4 |
|
Here is my menu layout. Draft:
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #5 |
|
Here is some of my main menu code so far... do you understand it?: Code: void MainMenu(void){
unsigned char POS = 0; //Used for cursor ONLY!
unsigned char done = 0;
unsigned char x;
unsigned char ITEM=0;
LCD_CLEAR(5);
while(!done){
for(x=0;x<2;x++){
LCD_LINE(x+1);
if(x == POS)
LCD_DATA('>',1);
else
LCD_DATA(' ',1);
LCD_STR(MainMenuLIST[x]);
}
switch(WaitForInput()){
case UP:
if(POS>0){
POS--;
ITEM--;
}
break;
case DOWN:
if(POS<1){
POS++;
ITEM++;
}
break;
case ENTER:
done = 0xFF;
break;
}
}
// ITEM contains what item is selected
// POS isnt used incase larger then 2 menu...
switch(ITEM){
case 0:
//Code to toggle C or F
break;
case 1:
//Code to jump to new menu system
break;
}
//Bring our title back.. cuz we are done with the menu...
LCD_LINE(1);
LCD_STR((unsigned rom char*)" AtomSoftTech ");
}
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #6 | |
| Quote:
Thanks for the reply. My project is a thermostat so is very close to your example, however I am wanting to learn so am happy for you to just teach me the steps rather than doing it for me. I do not fully understand all your code but understand the basic principle of what you are doing: First you are waiting for an input and depending on which button is pressed you either increment ITEM or decrement it, when done is pressed ITEM is switched so that the relevant item info is displayed? I will have a go at making a flow diagram and see what I can come up with Thanks | ||
| |
| | #7 |
|
hi, I have had a look through the code to try and understand each step that is taken, I think I understand most of it but am struggling with this part: Code: for(x=0;x<2;x++){
LCD_LINE(x+1);
if(x == POS)
LCD_DATA('>',1);
else
LCD_DATA(' ',1);
LCD_STR(MainMenuLIST[x]);
}
Its the next line I have the problem with LCD_STR(MainMenuLIST[x]); I am guessing that you output your data like this lcd_out(LCD_LINE, LCD_DATA, LCD_STR) meaning that MainMenuLIST[x] would be the message you wish to display? but how do I make this list? is this a call to another void? | |
| |
| | #8 |
|
The below Sets the LINE to work on... Since we are using a loop which starts on 0 we add 1 so : Code: LCD_LINE(x+1);.... Code: x = 0 + 1 = 1 (LINE 1) x= 1 + 1 = 2 (LINE 2) Code: if(x == POS)
LCD_DATA('>',1);
else
LCD_DATA(' ',1);
This sends a string to the LCD.. Code: LCD_STR(MainMenuLIST[x]); Its a multidimension array... 2 x 16 since my first main menu has 2 items and the max length is 16 characters. You should make all items in any menu the same length by using spaces. Will solve a lot of issues. Code: unsigned rom char MainMenuLIST[2][16] = {
{"Change View "},
{"Change Speed"}
};
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #9 |
|
Thanks for clearing that up I now have a better understanding how it works.I have not used arrays yet so will have to find out how they work as im getting a syntax error. could you please explain how your WaitForInput() function works? I currently detect inputs like: if (Button(&PORTA, 4, 1, 0)) { do somethiong } so would it work something like this: Code: void WaitForInput() {
if (Button(&PORTA, 3, 1, 0)) {
spmehow return up
}
if (Button(&PORTA, 4, 1, 0)) {
spmehow return down
}
if (Button(&PORTA, 4, 1, 0)) {
spmehow return enter
}
}
| |
| |
| | #10 |
|
Sorry about not posting it in full but i like questions ![]() Ok here is my wait for input Code: unsigned char WaitForInput(void){
unsigned char temp1; //TEMP DATA HOLDER
unsigned char done = 0; //DONE Var will determine if done
while(!done){ //while done == 0
if(KeyPORT>0){ //if KeyPORT aka PORTB&0x0F.. the &0x0f will make sure we
//return the lower part of port only RB0 to RB3
temp1 = KeyPORT; //Place the lower part of port into temp variable
while(KeyPORT==temp1); //Like a debounce for button press
done = 0xFF; //Set DONE Var so we know we are complete
}
}
return temp1; //Return our temp1 var
}
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics Last edited by AtomSoft; 24th October 2009 at 04:06 PM. | |
| |
| | #11 |
|
No need to appologise I like it this way they I get to learn how it works rather than just getting the code handed out. I dont really understand the way you detect which switch it is? or is keyPORT another array? | |
| |
| | #12 |
|
Oops heh I will post entire code in a little while just give me some time
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #13 |
|
ok I will read through what I have so far and try and figure out how it works.
| |
| |
| | #14 |
|
heh ok i have time now heh What i do is use definitions: Code: #define KeyPORT (PORTB&0x0F) #define KeyDIR TRISB #define MENU 1 #define ENTER 8 #define UP 2 #define DOWN 4 Code: switch(WaitForInput()) 0x01 which is 0000-0001 in binary aka MENU 0x02 which is 0000-0010 in binary aka UP 0x04 which is 0000-0100 in binary aka DOWN 0x08 which is 0000-1000 in binary aka ENTER Using it this way will let me use the words Code: switch(WaitForInput()){
case UP:
if(POS>0){
POS--;
ITEM--;
}
break;
case DOWN:
if(POS<1){
POS++;
ITEM++;
}
break;
case ENTER:
done = 0xFF;
break;
}
Code: switch(WaitForInput()){
case 0x02:
if(POS>0){
POS--;
ITEM--;
}
break;
case 0x04:
if(POS<1){
POS++;
ITEM++;
}
break;
case 0x08:
done = 0xFF;
break;
}
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #15 |
|
Thank you that makes much more sense now | |
| |
|
| Tags |
| lcd, menu |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| LCD menu in C? | picstudent | Micro Controllers | 1 | 13th September 2009 04:48 AM |
| LCD+keypad interface -> menu structure. Concepts sought. Assembly. PIC. | astronomerroyal | Micro Controllers | 23 | 29th August 2008 04:59 AM |
| LG CRT Repair and servce menu. | dark666 | General Electronics Chat | 0 | 7th June 2008 06:17 PM |
| Electronic Music Menu | cyprio7 | General Electronics Chat | 0 | 11th April 2008 04:50 PM |
| One menu, multiple pages. Anyone good at websites? | ThermalRunaway | Chit-Chat | 6 | 25th June 2006 11:45 AM |