Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 23rd October 2009, 10:36 PM   #1
Default lcd menu

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?
dawson is offline  
Old 23rd October 2009, 11:14 PM   #2
Default

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.
AllVol is offline  
Old 24th October 2009, 04:55 AM   #3
Default

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
AtomSoft is offline  
Old 24th October 2009, 05:56 AM   #4
Default

Here is my menu layout. Draft:

Attached Thumbnails
lcd menu-menu.jpg  
AtomSoft is offline  
Old 24th October 2009, 07:17 AM   #5
Default

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  ");
}
AtomSoft is offline  
Old 24th October 2009, 01:55 PM   #6
Default

Quote:
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
Hi,
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
dawson is offline  
Old 24th October 2009, 03:21 PM   #7
Default

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]);
	}
As far as I can see this is a loop to determine which line to display the menu item on in the list? POS being the line number?

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?
dawson is offline  
Old 24th October 2009, 03:30 PM   #8
Default

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);....
The loop is:
Code:
x = 0 + 1 = 1 (LINE 1)
x=  1  + 1 = 2 (LINE 2)
The below determines which item is selected and shows a '>' it the front of the line or a space if its not the line selected. POS is short for POSition....
Code:
		if(x == POS)
			LCD_DATA('>',1);
		else
			LCD_DATA(' ',1);

This sends a string to the LCD..

Code:
LCD_STR(MainMenuLIST[x]);
This is my string array:
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"}
};
AtomSoft is offline  
Old 24th October 2009, 03:52 PM   #9
Default

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
   }
}
dawson is offline  
Old 24th October 2009, 04:04 PM   #10
Default

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
}
Sorry if the comments suck heh do you understand the way i do it?

Last edited by AtomSoft; 24th October 2009 at 04:06 PM.
AtomSoft is offline  
Old 24th October 2009, 04:15 PM   #11
Default

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?
dawson is offline  
Old 24th October 2009, 04:20 PM   #12
Default

Oops heh I will post entire code in a little while just give me some time
AtomSoft is offline  
Old 24th October 2009, 04:24 PM   #13
Default

ok I will read through what I have so far and try and figure out how it works.
dawson is offline  
Old 24th October 2009, 04:36 PM   #14
Default

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
Now i can use:

Code:
switch(WaitForInput())
This will call WaitForInput which will return the lower half of portb. So portb can be:

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;
	}
instead of :
Code:
	switch(WaitForInput()){
		case 0x02:
			if(POS>0){
				POS--;
				ITEM--;
			}
			break;
		case 0x04:
			if(POS<1){
				POS++;
				ITEM++;
			}
			break;
		case 0x08:
			done = 0xFF;
			break;
	}
AtomSoft is offline  
Old 24th October 2009, 04:39 PM   #15
Default

Thank you that makes much more sense now
dawson is offline  
Reply

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



All times are GMT. The time now is 06:03 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker