|
|
View previous topic :: View next topic |
Author |
Message |
John Goss Guest
|
Any Ideas how to cycle through a menu list? |
Posted: Fri Sep 21, 2001 3:42 pm |
|
|
Hi all,
I am using the 16F877 with a LCD display and I am porting code over from another program to run a menu list. This routine was used with a different compiler.
Does anyone here know how CCS could format it to do the same thing, or maybe there is an even better way to cycle through a menu? This method may be overkill anyway. Any hints??
I have three buttons UP, DOWN, & ENTER, as I push UP or DOWN it cycles through the messages, if Enter, it will either go to another section of display messages (a sub menu) or it will execute some function.
Any help would be appreciated,
Thanks,
John
// This creates the messages to be displayed:
char *MenuTitle[] = {"-- MAIN MENU --",
"--COMMAND MENU--",
"--CONFIG MENU--"};
char *CmdMenu[] = {"1) READ VOLTAGES",
"2) RESET W/TEST ",
"3) RESET NO/TEST",
"4) READ TALLYS ",
"5) RESET TALLYS ",
"6) RESET EEPROM ",
"7) TALLY SERVICE"};
// This creates an array of pointers to the pointers of the text
// in ROM.
// MenuPointer is a pointer to array of pointers to text in ROM
// The structure is based upon where to point after a button
// press
// Array Data Structure:
//[0] = pointer to TEXT in ROM, [1] = UP, [2] = DOWN, [3] = ENTER
char *RomPointer;
char *MenuPointer[] =
{&MenuTitle[0], //0 - Main Menu
&MenuTitle[1], //1 - Command Menu
&MenuTitle[2], //2 - Config Menu
&CmdMenu[0] , //3 - Read Voltages
&CmdMenu[1] , //4 - Reset w/Test
&CmdMenu[2] , //5 - Reset No/Test
&CmdMenu[3] , //6 - Read Tallys
&CmdMenu[4] } //7 - Reset Tallys
//This actually
// Menu List Linker [0] = UP, [1] = Down, [2] = Enter
char MenuLinker[][3] =
{ {0x00,0x01,0x00}, //0 - Main Menu
{0x00,0x02,0x03}, //1 - Command Menu
{0x01,0x00,0x0A}, //2 - Config Menu
{0x01,0x04,0x00}, //3 - Read Voltages
{0x03,0x05,0x00}, //4 - Reset w/Test
{0x04,0x06,0x00}, //5 - Reset No/Test
{0x05,0x07,0x00}, //6 - Read Tallys
{0x06,0x08,0x00}, //7 - Reset Tallys
{0x07,0x09,0x00}, //8 - Reset EEPROM
//...etc.
___________________________
This message was ported from CCS's old forum
Original Post ID: 342 |
|
|
Tomi Guest
|
Re: Any Ideas how to cycle through a menu list? |
Posted: Sat Sep 22, 2001 11:19 am |
|
|
Your main problem is that the PIC uses Harward architecture so you are not able to generate and use any type of pointers to the ROM space (except using Read_program_eeprom() but I don't recommend it).
I have a similar application (except I have a 4th button ESC). Especially in that application I use the internal data EEPROM of the 16F877 to store the strings (16 chars each) so you can try the following (usually I store the strings in an external EEPROM):
// check the string lengths; maybe I left something wrong
#ROM 0x2100 = {'-','-',' ','M','A','I','N',' ','M','E','N','U',' ','-','-',0x00}
#ROM 0x2110 = {'-','-','C','O','M','M','A','N','D',' ','M','E','N','U','-','-'}
#ROM 0x2120 = {'-','-','C','O','N','F','I','G',' ','M','E','N','U','-','-',0x00}
#ROM 0x2130 = {'1',')',' ','R','E','A','D',' ','V','O','L','T','A','G','E','S'}
#ROM 0x2140 = {'2',')',' ','R','E','S','E','T',' ','W','/','T','E','S','T',0x00}
#ROM 0x2150 = {'3',')',' ','R','E','S','E','T',' ','N','O','/','T','E','S','T'}
#ROM 0x2160 = {'4',')',' ','R','E','A','D',' ','T','A','L','L','Y','S',0x00}
#ROM 0x2170 = {'5',')',' ','R','E','S','E','T',' ','T','A','L','L','Y','S',0x00}
#ROM 0x2180 = {'6',')',' ','R','E','S','E','T',' ','E','E','P','R','O','M',0x00}
#ROM 0x2190 = {'7',')',' ','T','A','L','L','Y',' ','S','E','R','V','I','C','E'}
char gMenu,gSubMenu; // globals
void DisplayString(char stridx) // display a string by ID (0..9)
{
char daddr,cnt,data;
daddr = (stridx << 4);
for (cnt=0;cnt<16;cnt++) {
data = Read_eeprom(daddr);
daddr++;
if (!data) break; // NULL termination
WriteDisplayData(data); // send the char to LCD
}
}
Note that if you use external EEPROM to store strings, modify the "daddr = (stridx << 4);" line to calculate the external address and use Read_external_eeprom() function instead of Read_eeprom() (plus you must have a PC program to download the strings).
// a simple rolling (I know that you want submenus, but you can easy modify these lines to use both gMenu and gSubMenu variables)
if (UP) {
gMenu++;
if (gMenu > 9) gMenu = 0;
} else
if (DOWN) {
gMenu--;
if (gMenu > 254) gMenu = 9; // gMenu is (unsigned) char so 0-- = 255
} else if (ENTER) {
}
// gMenu updated, write out the actual menu string
DisplayString(gMenu); // display the string associated with the menu ID
Hope this helps
___________________________
This message was ported from CCS's old forum
Original Post ID: 346 |
|
|
John Goss Guest
|
Re: Any Ideas how to cycle through a menu list? |
Posted: Sun Sep 23, 2001 5:04 pm |
|
|
Yes, thank you, this helps!!
:=Your main problem is that the PIC uses Harward architecture so you are not able to generate and use any type of pointers to the ROM space (except using Read_program_eeprom() but I don't recommend it).
:=I have a similar application (except I have a 4th button ESC). Especially in that application I use the internal data EEPROM of the 16F877 to store the strings (16 chars each) so you can try the following (usually I store the strings in an external EEPROM):
:=
:=// check the string lengths; maybe I left something wrong
:=#ROM 0x2100 = {'-','-',' ','M','A','I','N',' ','M','E','N','U',' ','-','-',0x00}
:=#ROM 0x2110 = {'-','-','C','O','M','M','A','N','D',' ','M','E','N','U','-','-'}
:=#ROM 0x2120 = {'-','-','C','O','N','F','I','G',' ','M','E','N','U','-','-',0x00}
:=#ROM 0x2130 = {'1',')',' ','R','E','A','D',' ','V','O','L','T','A','G','E','S'}
:=#ROM 0x2140 = {'2',')',' ','R','E','S','E','T',' ','W','/','T','E','S','T',0x00}
:=#ROM 0x2150 = {'3',')',' ','R','E','S','E','T',' ','N','O','/','T','E','S','T'}
:=#ROM 0x2160 = {'4',')',' ','R','E','A','D',' ','T','A','L','L','Y','S',0x00}
:=#ROM 0x2170 = {'5',')',' ','R','E','S','E','T',' ','T','A','L','L','Y','S',0x00}
:=#ROM 0x2180 = {'6',')',' ','R','E','S','E','T',' ','E','E','P','R','O','M',0x00}
:=#ROM 0x2190 = {'7',')',' ','T','A','L','L','Y',' ','S','E','R','V','I','C','E'}
:=
:=char gMenu,gSubMenu; // globals
:=
:=void DisplayString(char stridx) // display a string by ID (0..9)
:={
:=char daddr,cnt,data;
:=
:=daddr = (stridx << 4);
:=for (cnt=0;cnt<16;cnt++) {
:=data = Read_eeprom(daddr);
:=daddr++;
:=if (!data) break; // NULL termination
:=WriteDisplayData(data); // send the char to LCD
:=}
:=}
:=
:=Note that if you use external EEPROM to store strings, modify the "daddr = (stridx << 4);" line to calculate the external address and use Read_external_eeprom() function instead of Read_eeprom() (plus you must have a PC program to download the strings).
:=
:=// a simple rolling (I know that you want submenus, but you can easy modify these lines to use both gMenu and gSubMenu variables)
:=if (UP) {
:=gMenu++;
:=if (gMenu > 9) gMenu = 0;
:=} else
:=if (DOWN) {
:=gMenu--;
:=if (gMenu > 254) gMenu = 9; // gMenu is (unsigned) char so 0-- = 255
:=} else if (ENTER) {
:=}
:=// gMenu updated, write out the actual menu string
:=DisplayString(gMenu); // display the string associated with the menu ID
:=
:=Hope this helps
___________________________
This message was ported from CCS's old forum
Original Post ID: 354 |
|
|
|
|
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
|