没有吗?我自己写一个!还没有完成,后续再补! 希望大家指点!
#define MAX_MENU_NUM 20 //菜单总数量 #define MAX_funMENU_NUM 2 //功能型菜单数量(有要执行函数的) #define MAX_LED_DIGIT 4 //显示屏最大可以显示的位数
unsigned int curMenuIndex=0; //当前的菜单索引 unsigned char curLedValue; //当前Led显示的值 unsigned char ledFlashPos=MAX_LED_DIGIT; //led闪动的位置,0:个位,不在范围内,不闪动 unsigned char key_value; //按键值
struct menu_struct{ //菜单的结构定义 unsigned int menu_id; //菜单唯一的标识码 unsigned char menu_name[MAX_LED_DIGIT]; //菜单内容 unsigned char menu_Menu_num; //本级菜单的菜单数量,只有1个,代表是输入框 unsigned int menu_confirm_key_id; //按下"确认"键时转向下一级菜单标识码 unsigned int menu_left_key_id; //按下"向左"键时转向上一级的菜单标识码 unsigned int menu_up_key_id; //按下"向上"键时转向当前菜单的下一级的菜单标识码 };
struct menu_struct menu[MAX_MENU_NUM]; /*还没有完 ={ //菜单数组 {0X00, "no",0x04,0X01,0X00,0x00}, //顶层 {0X01, "main1", 0x04, 0x11,0X02, 0x00}, { 0X11, "main11", 1, 0X12, 0x14, {0x111,"blank",0 { 0X12, "main12", 1, 0X13, 0x11, {0x111,"blank",0 { 0X13, "main13", 1, 0X14, 0x12, {0x111,"blank",0 { 0X14, "main14", 1, 0X11, 0x13, {0X02, "main2", 0x04, 0x21,0X03, 0x00, { 0X21, "main21", 1, 0X22, 0x24, {0x111,"blank",0 { 0X22, "main22", 1, 0X23, 0x21, {0x111,"blank",0 { 0X23, "main23", 1, 0X24, 0x22, {0x111,"blank",0 { 0X24, "main24", 1, 0X21, 0x23, {0X03, "main3", 0x04, 0x31,0X04, 0x00, { 0X31, "main31", 1, 0X32, 0x34, {0x111,"blank",0 { 0X32, "main32", 1, 0X33, 0x31, {0x111,"blank",0 { 0X33, "main33", 1, 0X34, 0x32, {0x111,"blank",0 { 0X34, "main34", 1, 0X31, 0x33, {0X04, "main4", 0x04, 0x41,0X01, 0x00, { 0X41, "main41", 1, 0X42, 0x44, {0x111,"blank",0 { 0X42, "main42", 1, 0X43, 0x41, {0x111,"blank",0 { 0X43, "main43", 1, 0X44, 0x42, {0x111,"blank",0 { 0X44, "main44", 1, 0X41, 0x43, } */
unsigned int getMenuIndex(unsigned int id){ //返回菜单标识码对应的菜单数组中的索引 unsigned int i; for( i=0;i<MAX_MENU_NUM;i++) if(menu.menu_id=id) return(i); return(0); }
void menuFunction111(void){ //功能函数 }
void menuFunction112(void){ //功能函数 } struct function_menu_table{ //有功能函数的菜单 int MenulD; void(*pfmenu)(void); }FunTab[MAX_funMENU_NUM]={ 0x111,menuFunction111, // fmenul11为功能菜单的函数名称 0x112,menuFunction112, };
void main(){
do{ switch(key_value){ case 0: //confirm_key: if((menu[curMenuIndex].menu_Menu_num==1)&&(curLedValue==1)) //输入菜单 curMenuIndex=getMenuIndex(menu[curMenuIndex].menu_confirm_key_id); //1:进入子菜单 else curMenuIndex=getMenuIndex(menu[curMenuIndex].menu_up_key_id); //其它:进入下一个菜单
for(i=0;i<MAX_funMENU_NUM;i++){ //查找当前菜单是否有功能函数 if(FunTab.MenulD==menu[curMenuIndex].menu_id){ //如果有就执行 (FunTab.pfmenu)(); // 执行功能型菜单 / break; // 根据ID号查找函数指针 / } } break; case 1://left_key: if(menu[curMenuIndex].menu_Menu_num==1){ //输入菜单 ledFlashPos++; if(ledFlashPos>MAX_LED_DIGIT) ledFlashPos=0; //ledFlashPos==MAX_LED_DIGIT,不闪烁 } else curMenuIndex=getMenuIndex(menu[curMenuIndex].menu_left_key_id); //进入下一个菜单 break; case 2://up_key: if((menu[curMenuIndex].menu_Menu_num==1)&&(ledFlashPos<MAX_LED_DIGIT)) //输入菜单,且在输入状态 { unsigned int temp=1; for(i=0;i<ledFlashPos;i++) temp*=10; curLedValue+=temp; } else curMenuIndex=getMenuIndex(menu[curMenuIndex].menu_up_key_id); //进入下一个菜单 break; default: ; }; }while(1); }
//增加和修改功能型菜单时只需要修改变量“FunTab[]无须修改执行代码。 /* 代码的移值 以上实现了1个菜单代码, 现在, 只要修改以下数据就可以构造任意内容的树型菜单, 步骤如下: ① 画出菜单树, 按照上述原则给每个菜单1个ID号: ② 编写MENU menus[]结构数组, 定义每个结构变量(显示位置和内容); ③ 编写不同功能菜单函数; ④ 编写struct function_menu_table FunTab[]结构数组, 定义每个结构变量。 完成后编译执行, 1个菜单界面的应用软件就完成了。 */ |