This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

array of structs with fixed content

Hi you all.

I need to creat an LCD based user interface.
Therefore , I decided to use a struct for each LCD menu:

typedef struct Menu {
	char lcd_first_line[16];
	char lcd_second_line[16];
	struct Menu * child_pointer;
	float menu_number;
	// pointer to run function
}MenuItem;
and to declare an array of menus:
MenuItem xdata main_menu[5];
but I need to init the values of the struct (xdata) , and I want them to be fixed (code).

Does someone have an idea how to do that ?


Thanks


Guy

Parents Reply Children
  • That is, like this:

    typedef struct Menu {
        char lcd_first_line[16];
        char lcd_second_line[16];
        struct Menu * child_pointer;
        float menu_number;
        // pointer to run function
    }MenuItem;
    
    MenuItem xdata main_menu[5] =
    
        {   {   "menu", "00000", &main_menu[1], 3.0 },
            {   "menu", "11111", &main_menu[2], 3.0 },
            {   "menu", "22222", &main_menu[3], 3.0 },
            {   "menu", "33333", &main_menu[4], 3.0 },
            {   "menu", "44444", &main_menu[0], 3.0 },
        };
    

  • If you want the data to reside in the code space, then make the declaration

    const MenuItem code main_menu[5] =

    If you want the data to reside in xdata, then you'll need to be sure your startup code executes the code in INIT.A51 to actually copy the initializer values from ROM to the xdata RAM.