CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Has anybody got a good template for a menu structure?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
darryl groom
Guest







Has anybody got a good template for a menu structure?
PostPosted: Thu Feb 06, 2003 9:36 am     Reply with quote

I am currently using the PIC16F877 and need to write a comprehensive menu structure and wonder if anybody has god an efficient way of going about this as the amount of code space this routine is allowed to take up is quite critical.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11358
Trampas Stern
Guest







Re: Has anybody got a good template for a menu structure?
PostPosted: Thu Feb 06, 2003 11:18 am     Reply with quote

What type of menu, text based?

I do mine using linked lists. For example imagine a menu selection system like the following:

Menu1
Sub_menu_a
Sub_menu-b
Menu2
Sub_menu_c

Then I create a structure to hold the menus:

//Menu actions, note pointers to functions would be perfect
// but they do not work in CCS
#define UNDEFINED 0 //undefined menu
#define SUB_MENU 1 //go to sub menu
#define ACTION_1 2 //some action
#define ACTION_2 3 //some other action
#define ACTION_3 4 //more actions

typedef struct s_menus {
char Action; //action to perform if menu selected
char Name[15];
struct s_menus *sub_menus;
struct s_menus *next_menu;
} Menu;

Menu sub_menus[]={
{ACTION_1,"sub_menu_a",0,&sub_menus[1]}, //next menu is sub_menu
{ACTION_2,"sub_menu_b",0,0}, //end of menu no next
{ACTION_3,"sub_menu_c",0,0}, //end of menu no next
{UNDEFINED ,"",0,0} //use undefined to signal end
};

Menu top_level[]={
{SUB_MENU,"Menu1",&sub_menus[0],&top_level[1]},
{SUB_MENU,"Menu2",&sub_menus[2],0},
{UNDEFINED ,"",0,0} //use undefined to signal end
};


Then you can create a function to show menus

void Display_menu(Menu *menus)
{

Menu *ptrMenu;
//check for null pointers and so forth

ptrMenu=menus;
do {
printf("\%s",ptrMenu->name);
ptrMenu=ptrMenu->next_menu;
while (ptrMenu!=0);

//implement your selection method

//then determine action

//take action
//note here is where recrusive function call would be nice
}

However you may want to try it another way until the CCS compiler is fixed.

Trampas


:=I am currently using the PIC16F877 and need to write a comprehensive menu structure and wonder if anybody has god an efficient way of going about this as the amount of code space this routine is allowed to take up is quite critical.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11362
Tomi
Guest







Re: Has anybody got a good template for a menu structure?
PostPosted: Thu Feb 06, 2003 11:33 am     Reply with quote

What is about using an external EEPROM to store string data for menus? I did it using a 24LC256. If you define a uniformed length string array in the EEPROM then you can easily calculate the address of a string and use a function something like this:

void DisplayString(char menuitem)
{
unsigned long addr;
char actaddr,ki;

addr = menuitem;
addr <<= 6; // mult. by 64
addr += 0x7A00; // string are stored at top of EEPROM
ClearDisplay(); // there is something similar in lcd.c
SetDisplayAddress(0); // my "set LCD address" function
actaddr = 0;
while (1) {
ki = ReadRAM(addr); // my read_ext_eeprom() function
if (!ki || (ki == 0xFF)) break; // the string is either NULL terminated (C string) or "0xFF-terminated" (un-initialized EEPROM area)
WriteDisplayData(ki); // my LCD_putc()
addr++;
actaddr++;
if (actaddr >= 40) break; // I use it with a 2x20 LCD
if (actaddr == 20) SetDisplayAddress(64); // auto-wrap to the next line
}
}

Note that I use variables MainMenu and Submenu and because a mainmenu can contain up to 8 submenus I use something like this:

char StringToDisplay;
StringToDisplay = (MainMenu << 3) + (Submenu & 0x07);
DisplayString(StringToDisplay);


:=I am currently using the PIC16F877 and need to write a comprehensive menu structure and wonder if anybody has god an efficient way of going about this as the amount of code space this routine is allowed to take up is quite critical.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11363
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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