黑夜11:
给你个1602的菜单显示界面,哈哈#ifndef_Menu_#define_Menu_#include"Function.h"//功能函数#include//==================================================//LCD1602多级菜单显示//BY:JH单片机//Ifyouwanttousetheprogramortheprogramreferencedinthearticle,//pleasespecifyinwhichdataandproceduresfromJHMCU.com////Web:www.JHMCU.com出自傻孩子菜单界面//==================================================#definekeyin(P1IN&0x0f)#defineADD0xfb//上页#defineSUB0xf7//下页#defineSET0x0e//设置、确定#defineBACK0x0d//返回#defineNull0//菜单目录结构体声明structMenuItemMainMenu_zhu[2];structMenuItemMainMenu[7];structMenuItemPriority_Menu[2];structMenuItemBaud_Menu[6];structMenuItemPmax_Menu[1];structMenuItemBuzzer_Menu[2];structMenuItemAbout_Menu[2];unsignedcharkeysacn(void);voidShowMenu();voidChangeMenu(unsignedcharkeynum);voidL_R_Move();voidBuzzer_ON(void);voidBuzzer_OFF(void);voidExit_o(void);//菜单使用的全局变量#defineLcdMaxLine2//定义LCD最多显示菜单数目structMenuItem(*MenuPoint)=MainMenu_zhu;//结构体菜单指针指向主菜单constunsignedcharshuzi[10]={"0123456789"};//固定字符串//constunsignedcharyt[16]={"T:24.3°P:510W"};//15个字符串unsignedcharyu[16]={"52400W"};//可更改字符串//unsignedcharBuz_flag=1;unsignedcharDisplayStart=0;//显示菜单的开始位置unsignedcharUserChoose=0;//用户的选择unsignedcharDisplayPoint=0;//显示菜单的编号unsignedcharR_L_cnt=0;//全局变量unsignedcharMaxItems=0;//菜单的数量unsignedcharUp_Down=0;//==========================================================================//目录结构体定义//==========================================================================structMenuItem{unsignedcharMenuCount;//菜单的数目unsignedchar*DisplayString;//显示的字符串void(*Subs)();//菜单指向的功能函数使用方法:Subs=&函数名字;structMenuItem*ChildrenMenus;//子节点structMenuItem*ParentMenus;//父节点unsignedcharType_o;//显示类型};//==========================================================================//菜单结构体链表//==========================================================================//主界面显示structMenuItemMainMenu_zhu[2]={{2,"Systemis",NullSubs,MainMenu,MainMenu_zhu,0x01},//->显示主界面{2,"beingtested",NullSubs,MainMenu,MainMenu_zhu,0x01},//->显示主界面};//==========================================================================//菜单结构体链表//==========================================================================//主菜单-第一级菜单structMenuItemMainMenu[7]=//结构体主菜单{{7,"S/N_Priority",NullSubs,Priority_Menu,Null,0x00},//->逆变优先级设置{7,"SetBaudRate",NullSubs,Baud_Menu,Null,0x00},//->设置波特率{7,"SetPmax",NullSubs,Pmax_Menu,Null,0x00},//->设置最大功率{7,"BuzzerSW",NullSubs,Buzzer_Menu,Null,0x00},//->蜂鸣器开关{7,"Exit",NullSubs,MainMenu_zhu,Null,0x00},//->退出(返回主界面){7,"About",NullSubs,About_Menu,Null,0x00},//->关于{7,"Power_off",Power_off,Null,Null,0x00},//->关机};structMenuItemPriority_Menu[2]=//优先级菜单{{2,"ElectricCity",NullSubs,Null,MainMenu,0x00},{2,"Inverter",NullSubs,Null,MainMenu,0x00},};structMenuItemBaud_Menu[6]=//波特率菜单{{6,"2400",NullSubs,Null,MainMenu,0x00},{6,"4800",NullSubs,Null,MainMenu,0x00},{6,"9600",NullSubs,Null,MainMenu,0x00},{6,"19200",NullSubs,Null,MainMenu,0x00},{6,"38400",NullSubs,Null,MainMenu,0x00},{6,"76800",NullSubs,Null,MainMenu,0x00},};structMenuItemPmax_Menu[1]=//最大功率设置{{1,yu,L_R_Move,Null,MainMenu,0x02},};structMenuItemBuzzer_Menu[2]=//蜂鸣器开关{{2,"BuzzerON",Buzzer_ON,Null,MainMenu,0x00},{2,"BuzzerOFF",Buzzer_OFF,Null,MainMenu,0x00},};structMenuItemAbout_Menu[2]=//关于{{2,"Smallraccoon",NullSubs,Null,MainMenu,0x00},//小浣熊{2,"Electronics",NullSubs,Null,MainMenu,0x00},//电子};unsignedcharkeysacn(void)//{unsignedchartemp,k_num;if(keyin!=0x0f)//键值有改变{IE1|=WDTIE;//开看门狗中断_NOP();//延时消抖if(keyin!=0x0f)//再次检测按键状态{temp=keyin;while(keyin!=0x0f);//等待按键被放开IE1&=~WDTIE;//关闭看门狗中断P6OUT|=BIT7;//输出高电平switch(temp)//转换键值{case0x0e://设置、确定k_num=SET;break;case0x0d://返回k_num=BACK;break;case0x0b://上页k_num=ADD;break;case0x07://下页k_num=SUB;break;default:k_num=Null;break;}}}returnk_num;//输出键值}//==================================================//功能能函数//INPUT://OUTPUT://FUNCTION://==================================================voidPower_off(void)//关机程序{;//P2OUT^=BIT0;//灯全灭}voidBuzzer_ON(void){_EINT();}voidBuzzer_OFF(void){_DINT();}//==================================================//最大功率设置光标移动函数//INPUT://OUTPUT://FUNCTION://==================================================voidL_R_Move(){DispStr(0,1,"Maximumpower");//显示最大功率字符if(++R_L_cnt>4)R_L_cnt=0;//右移5次//P2OUT^=BIT1;//灯全灭}//==================================================//LCD1602菜单显示通用函数//INPUT:结构体链表,UserChoose//OUTPUT:NONE//FUNCTION:LCD1602液晶显示屏上显示菜单功能//==================================================voidShowMenu(){for(unsignedchari=0;i