A menu system Applicable for various microcntroller projects ,Not fully completed only for learning the full code and proteus are available below to download for learning purpose thanking you
/* * push_button__lcdMenu.c * * Created: 7/30/2017 11:48:27 AM * Author: Krishna */ #include#include "lcd.h" #include "delay.h" #include "button_key.h" # define F_CPU 1000000UL struct menu s1= {0}; //s1.menu_up-key =1; int main(void) { int a; struct menu s1= {0}; //s1.menu_up-key =1; const char *menu_display[10]; menu_display[0] = " Select Menu"; menu_display[1] = " Set Time"; menu_display[2] = " Set Date"; menu_display[3] = " Set Alaram"; menu_display[4] = " Set Alaram "; //sub menu menu_display[5] = " Enter Time "; menu_display[6] = " Enter Date "; menu_display[7] = " Enter Alarm "; menu_display[8] = " Enter Alarm"; LCD_SetUp(PB_0,PB_1,PB_2,P_NC,P_NC,P_NC,P_NC,PB_4,PB_5,PB_6,PB_7); LCD_Init(2,16); LCD_GoToLine(0); DELAY_ms(100); //LCD_Clear(); while(1) { // key_display( key_value); menu_key_display (s1,menu_display); LCD_Clear(); for(a=0; a<5 a="" d="" lcd_printf="" pre="" s1.time=""> 5>
/* * button_key.c * * Created: 7/30/2017 12:02:39 PM * Author: Krishna */ #include#include "delay.h" #include "button_key.h" #include "lcd.h" void menu_key_display(struct menu s1,const char *menu_display[]); void UP_Down_Keyvalue(struct menu s1,int i,int j); /* Function Key Value For get key */ int Key_pressed(void) { while(1){ if (LEFT_S) { while(LEFT_S);return 1; } if (RIGHT_S){ while(RIGHT_S);return 2; } if (UP_S) { while(UP_S); return 3; } if (DOWN_S) { while(DOWN_S);return 4 ; } if (OK_S) { while(OK_S);return 5 ; } } } /* Function Key Value For Up Key & Enter*/ void menu_key_display(struct menu s1,const char *menu_display[]) { int ch; int a; int menu_position =0; LCD_DisplayString(menu_display[menu_position]); do{ repat: ch = Key_pressed(); if(ch==1||ch==2) { if(ch==2) { if(ch==2) { if(s1.menu_side_key==4) s1.menu_side_key = 0; LCD_Clear(); LCD_GoToLine(0); LCD_DisplayString(*((++s1.menu_side_key)+menu_display)); menu_position=1; } } else if(ch==1) { if(ch==1) {if(s1.menu_side_key==1 ||s1.menu_side_key==0) { s1.menu_side_key=5; } LCD_Clear(); LCD_DisplayString(*((--s1.menu_side_key)+menu_display)); menu_position=1; } } } if(menu_position==0) goto repat; }while(ch!=5); a = s1.menu_side_key; switch(a) { case 1: // set time { LCD_Clear(); LCD_GoToLine(0); LCD_DisplayString(menu_display[5]); LCD_GoToLine(1); LCD_DisplayString(" HH:MM:SS:PM/AM"); UP_Down_Keyvalue(s1,2,4); break; } case 2: // Set date { LCD_Clear(); LCD_GoToLine(0); LCD_DisplayString(menu_display[6]); LCD_GoToLine(1); LCD_DisplayString(" DD:MM:YY"); UP_Down_Keyvalue(s1,2,3); break; } case 3: // set alarm { LCD_Clear(); LCD_GoToLine(0); LCD_DisplayString(menu_display[7]); LCD_GoToLine(1); LCD_DisplayString(" HH:MM:SS:AM/PM"); UP_Down_Keyvalue(s1,2,4); break; } case 4: // set alarm { LCD_Clear(); LCD_GoToLine(0); LCD_DisplayString(menu_display[8]); LCD_GoToLine(1); LCD_DisplayString(" HH:MM:SS:PM/AM"); UP_Down_Keyvalue(s1,2,4); break; } } while(Key_pressed()!=5); } /* Function Key Value For UP_Down Key */ void UP_Down_Keyvalue(struct menu s1,int i,int j) { int ch,lower,upper; do{ if(j==4) { if(i==2)upper=1; if(i==3)upper=9; if(i==5)upper=5; if(i==8)upper =5; if(i==9)upper =9; } if(UP_S) { while(UP_S); if(s1.menu_up_key==upper) s1.menu_up_key = lower-1; LCD_GoToXY(1,i); LCD_Printf("%d",++s1.menu_up_key); s1.time[i-2]=s1.menu_up_key; } else if(DOWN_S) // down { while(DOWN_S); if (s1.menu_up_key==lower) s1.menu_up_key = upper+1; LCD_GoToXY(1,i); LCD_Printf("%d",--s1.menu_up_key); s1.time[i-2]=s1.menu_up_key; } if(RIGHT_S) { while(RIGHT_S); s1.menu_up_key=0; if(i==9) goto exit1; if(i==3||i==6) ++i; i++; } exit1: if (LEFT_S) { while(LEFT_S); s1.menu_up_key=0; if(i==2) goto exit2; if(i==5||i==8) --i; i--; } exit2:continue; } while (ch!=5); // if Okay key exit loop }