************************ mneu.h *************************** #ifndef menu_h #define menu_h struct MENU; struct MENU_ENTRY { const unsigned char *Entry_Name; const struct MENU *SubMenu; void ( *Function )(void); }; struct MENU { const unsigned char *Menu_Name; int NrEntries; const struct MENU_ENTRY *Entries; }; // Texte der Menüeinträge // Strings Mainmenue static const char menu_main_str[] PROGMEM = "Hauptmenue"; static const char menu_set_str[] PROGMEM = "Einstellungen"; static const char menu_par_str[] PROGMEM = "Parameter"; // Strings Settingsmenue static const char set1_str[] PROGMEM = "Set 1"; static const char set2_str[] PROGMEM = "Set 2"; // Strings Parametermenue static const char par1_str[] PROGMEM = "Par 1"; static const char par2_str[] PROGMEM = "Par 2"; static const char exit_str[] PROGMEM = "Exit"; extern void update_menue(void); extern void update_display(void); extern void func0(void); extern void func1(void); extern void func2(void); extern void func3(void); extern void getback(void); #endif ********************************** menu.c ********************************* UINT ActEntry = 0; UINT ActEntryOld = 0; char HelpStr[16]; // --------------------------- prototypes ------------------------------------ // --------------------------------------------------------------------------- const struct MENU_ENTRY MENU_SET_ENTRIES[] ={ { set1_str, NULL, func0 }, { set2_str, NULL, func1 }, { exit_str, NULL, getback } }; const struct MENU MENU_SET ={ menu_set_str, sizeof( MENU_SET_ENTRIES ) / sizeof( *MENU_SET_ENTRIES ), MENU_SET_ENTRIES }; const struct MENU_ENTRY MENU_PAR_ENTRIES[] ={ { par1_str, NULL, func2 }, { par2_str, NULL, func3 }, { exit_str, NULL, getback } }; const struct MENU MENU_PAR ={ menu_par_str, sizeof( MENU_PAR_ENTRIES ) / sizeof( *MENU_PAR_ENTRIES ), MENU_PAR_ENTRIES }; const struct MENU_ENTRY MENU_MAIN_ENTRIES[] ={ { menu_set_str, &MENU_SET, NULL }, { menu_par_str, &MENU_PAR, NULL } }; const struct MENU MENU_MAIN = { menu_main_str, sizeof( MENU_MAIN_ENTRIES ) / sizeof( *MENU_MAIN_ENTRIES ), MENU_MAIN_ENTRIES }; //und zuguter letzt haben wir noch den Pointer //auf das zunächst oberste Menü: const struct MENU *ActMenu = &MENU_MAIN; void update_menue(void) // Die Menüfunktionen { if( get_key_press( 1<= ActMenu->NrEntries) // Begrenzung auf max Anzahl der Entries ActEntry = ActMenu->NrEntries - 1; if( get_key_press( 1<Entries[ActEntry].SubMenu != NULL ) { ActMenu = ActMenu->Entries[ActEntry].SubMenu; ActEntry = 0; update_display(); } else if( ActMenu->Entries[ActEntry].Function != NULL ) { ActMenu->Entries[ActEntry].Function(); } } if( ActEntry != ActEntryOld) update_display(); } void update_display(void) // Update der Anzeige { lcd_clrscr(); lcd_gotoxy(0,0); strcpy_P(HelpStr, ActMenu->Menu_Name); lcd_puts(HelpStr); lcd_gotoxy(0,1); strcpy_P(HelpStr, ActMenu->Entries[ActEntry].Entry_Name); lcd_puts(HelpStr); ActEntryOld = ActEntry; } //Menüfunktionen void func0(void) { lcd_gotoxy(0,2); lcd_puts("Funktion 1"); } void func1(void) { lcd_gotoxy(0,2); lcd_puts("Funktion 2"); } void func2(void) { lcd_gotoxy(0,2); lcd_puts("Funktion 3"); } void func3(void) { lcd_gotoxy(0,2); lcd_puts("Funktion 4"); } void getback(void) { ActMenu = &MENU_MAIN; }