[C51代码]菜单函数[用于LCD1602]
#define __menu_h__
#include "head.h"
#include "LCD1602_2.h"
#include "DS18B20.h"
#define Null 0
/***********************
* 函数声明 *
***********************/
void ShowMenu(void);
void Menu_Change(uchar KeyNum);
/***********************
* 按键功能键宏定义 *
***********************/
#define up 1
#define down 2
#define back 4
#define ok 5
/**********************
* 目录结构体定义 *
**********************/
struct MenuItem
{
uchar MenuCount; //当前层节点数
uchar *DisplayString; //菜单标题
void (*Subs)(); //节点函数
struct MenuItem *ChildrenMenus; //子节点
struct MenuItem *ParentMenus; //父节点
};
/***********************
* 调用子函数区 *
***********************/
void NullSubs(void)
{
}
/***********************
* 结构体区 *
***********************/
struct MenuItem NameMenu[2];
struct MenuItem NumberMenu[2];
struct MenuItem MainMenu[3];
struct MenuItem NameMenu[2]=
{ //MenuCount DisplayString Subs ChildrenMenus ParentMenus
{2, "WeiMen",NullSubs, Null, MainMenu},
{2, "Back",NullSubs, MainMenu, MainMenu},
};
struct MenuItem NumberMenu[2]=
{ //MenuCount DisplayString Subs ChildrenMenus ParentMenus
{2, "0500320128", NullSubs, Null, MainMenu},
{2, "Back",NullSubs,MainMenu, MainMenu},
};
struct MenuItem MainMenu[3]=
{ //MenuCount DisplayString Subs ChildrenMenus ParentMenus
{3, "1.Show Name ", NullSubs, NameMenu, Null},
{3, "2.Show Number",NullSubs, NumberMenu, Null},
{3, "3.Back", MainMenu, MainMenu},
};
/***********************
* 全局变量声明区 *
***********************/
struct MenuItem (*MenuPoint) = MainMenu; //结构体指针,指向结构体后由内部函数指针指向功能函数
uchar DisplayStart = 0; //显示时的第一个菜单项
uchar UserChoose = 0; //用户所选菜单项
uchar DisplayPoint = 0; //显示指针
uchar MaxItems; //同级最大菜单数
uchar ShowCount=2; //同屏显示菜单数
/***********************
*显示函数区*
***********************/
void ShowMenu(void)
{
unsigned char n;
MaxItems = MenuPoint[0].MenuCount;//定义最大同级菜单
DisplayPoint = DisplayStart;
for(n=0;DisplayPoint
LCDDispListChar(0,n,"->");
LCDDispListChar(2,n,MenuPoint[DisplayPoint++].DisplayString);
}
}
void Menu_Change(unsigned char KeyNum)
{
if(KeyNum)
{
switch(KeyNum)
{
case up:
UserChoose --;
if (UserChoose ==255)
{
UserChoose = 0;//上翻截至,如果要回滚赋值MaxItems-1
}
break;
case down:
UserChoose ++;
if (UserChoose == MaxItems)
{
UserChoose = MaxItems-1;//下翻截至,如要回滚赋值为0
}
break;
case back:
if (MenuPoint[UserChoose].ParentMenus != Null)
{
MenuPoint = MenuPoint[UserChoose].ParentMenus;
UserChoose = 0;
DisplayStart = 0;
}
break;
case ok:
if (MenuPoint[UserChoose].Subs != NullSubs)
{
(*MenuPoint[UserChoose].Subs)();
}
else if (MenuPoint[UserChoose].ChildrenMenus != Null)
{
MenuPoint = MenuPoint[UserChoose].ChildrenMenus;
UserChoose = 0;
DisplayStart = 0;
}
break;
default:break;
}
if (UserChoose%ShowCount==0) //一屏只能显示ShowCount行
DisplayStart = UserChoose;
else if(UserChoose==1||UserChoose== 3)
DisplayStart = UserChoose-1; //实现滚屏的关键
LCDWriteCmd(DispClear); //液晶清屏,根据不同液晶函数自行修改
delay1ms(2); //液晶为慢速器件
ShowMenu();
}
}
#endif
C51代码菜单函数LCD160 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)