液晶菜单程序.doc

上传人:m**** 文档编号:564377088 上传时间:2023-12-03 格式:DOC 页数:7 大小:42.51KB
返回 下载 相关 举报
液晶菜单程序.doc_第1页
第1页 / 共7页
液晶菜单程序.doc_第2页
第2页 / 共7页
液晶菜单程序.doc_第3页
第3页 / 共7页
液晶菜单程序.doc_第4页
第4页 / 共7页
液晶菜单程序.doc_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《液晶菜单程序.doc》由会员分享,可在线阅读,更多相关《液晶菜单程序.doc(7页珍藏版)》请在金锄头文库上搜索。

1、OCMJ4X8C液晶菜单显示程序(2008-08-08 09:13:13)标签:菜单程序液晶mainmenuit 刚刚花了3天写了一个比较完善的菜单显示程序,分享给大家。可能有很多不足,如果有什么bug请发Email到谢谢!未经作者允许请勿用于商业用途!菜单的数据结构定义/选项结构体的定义typedef struct optionsigned ID;/选项标志()int *Label;/菜单显示字,连向wordstruct menu *next;/选项的下级菜单,若非菜单则为0option;/菜单结构体的定义typedef struct menuunsigned Maxopts;/该菜单所包含

2、的选项数unsigned Maxoptsperpage;/定义LED每一页最多显示项目数(低2位有效,最多为3+1,最少为0+1)unsigned selection;struct menu *parmenu;/父菜单struct option *paropt;struct option *next;/该菜单的第一个项目menu;/主菜单结构体的定义typedef struct Mainmenuunsigned int Maxopts;/主菜单包含的项目数unsigned int maxhypes;/已定义的最大的层数(建立菜单时用到)struct option *curopt;/在建立菜单时

3、记录当前的选项struct menu *curmenu;/在建立菜单时记录当前所在的菜单/上面两数据在对菜单操作时指向当前页的第一项struct menu *next;/主菜单Mainmenu;菜单的处理函数定义/#include Menudefine.hMainmenu *Main_Menu;menu *Menu;option *Option;int Addmenu(unsigned *Label,unsigned maxopts,unsigned maxoptsperpage);int Addnext(unsigned *Label);Mainmenu * InitMainMenu(voi

4、d);/添加菜单/参数简介:Label存储项目显示内容的指针,maxopts该菜单的项目数/maxoptserpage该菜单下每页显示的项目数/返回值类型:整型/正常返回0,主菜单建立完毕返回-1,内存不被分配返回1int Addmenu(unsigned *Label,unsigned maxopts,unsigned maxoptsperpage)int j;Menu = 0;if(!(Menu = (menu *)malloc(Menusize)return 1;/内存空间申请失败,返回1Menu-Maxopts = maxopts;Menu-Maxoptsperpage = maxop

5、tsperpage;Menu-selection = 1;Option = 0;if(!(Option = (option *)malloc(maxopts * Optionsize)/内存空间申请失败,返回1return 1;Menu-next = Option;Option - ID = 0;/对Menu的初始化完毕if(Main_Menu-maxhypes)/如果不是主菜单if(!Main_Menu-curopt-ID)/如果是该菜单第一个项目,则给项目ID赋值Main_Menu-curopt-ID = Main_Menu-maxhypescuropt += 1;Main_Menu-cu

6、ropt-ID = (Main_Menu-curopt - 1)-ID +1;Main_Menu-curopt-next = Menu;Main_Menu-curopt-Label = Label;Menu-parmenu = Main_Menu-curmenu;Menu-paropt = Main_Menu-curopt;elseMain_Menu-next = Menu;Menu-parmenu = Menu;Menu-paropt = 0;Main_Menu-curopt = Option;Main_Menu-curmenu = Menu;Main_Menu-maxhypes +;ret

7、urn 0;/添加项目/参数简介:Label存储项目显示内容的指针/返回值类型:整型/正常返回0,主菜单建立完毕返回-1int Addnext(unsigned *Label)if(!Main_Menu-curopt-ID)/如果是该菜单第一个项目,第一项ID赋值Main_Menu-curopt-ID = Main_Menu-maxhypescuropt += 1;Main_Menu-curopt-ID = (Main_Menu-curopt - 1)-ID +1;Main_Menu-curopt-Label = Label;Main_Menu-curopt-next = 0;while(Ma

8、in_Menu-curopt-ID&0x000f) = (Main_Menu-curmenu-Maxopts - 1)/该层项目已经到达最大数,退出该层菜单if(Main_Menu-curmenu = Main_Menu-next)return -1;Main_Menu-curopt = Main_Menu-curmenu-paropt;Main_Menu-curmenu = Main_Menu-curmenu-parmenu;return 0;/初始化主菜单/Mainmenu * InitMainMenu()Main_Menu = (Mainmenu *)malloc(sizeof(Main

9、menu);Main_Menu-maxhypes = 0;Main_Menu-curmenu = 0;Main_Menu-curopt = 0;Main_Menu-next = 0;/Addmenu()Main_Menu添加菜单时Label可为0,其他参数根据用户需要自定义Addmenu(0,7,3);Addmenu(滨州学院,6,3);Addnext(物理系);Addnext(计算机系);Addnext(数学系);Addnext(政法系);Addnext(数学系);Addnext(自动化系);Addmenu(滨州政府,2,2);Addnext(市长办公室);Addnext(副市长办公室);A

10、ddnext(滨州人事局);Addnext(滨州法院);Addnext(滨州检察院);Addnext(滨州教育局);Addnext(滨州医学院);/此前代码需要用户自己填写Main_Menu-curmenu = Main_Menu-next;Main_Menu-curopt = Main_Menu-curmenu-next;return Main_Menu;/进入选择项目/入口参数:selection为以Main_Menu-curopt为第一项,选择的项目序号unsigned Enter(int selection)unsigned ID ;if(selection Main_Menu-cur

11、menu-Maxoptsperpage)/选项无效,直接返回0xffffreturn 0xffff;selection -;ID = Main_Menu-curopt-ID + selection;if(ID&0x0f) = Main_Menu-curmenu-Maxopts)/选项无效,直接返回0xffffreturn 0xffff;if(Main_Menu-curopt + selection)-next)/若选择菜单,则进入Main_Menu-curmenu = (Main_Menu-curopt + selection)-next;Main_Menu-curopt = Main_Menu-curmenu-next;return 0;else/若选择项目,则返回ID,外部函数根据返回值调用相关函数return Main_Menu-curopt-ID;/返回上一级void Esc()if(Main_Menu-curmenu != Main_Menu-next)/如果不是主菜单则返回上一级Main_Menu-curmenu = Main_Menu-curmenu-

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号