📄 menu.c
字号:
/**********************************多级菜单LCD显示********************************************/
/*********作者:王胜文。QQ:95201972 email:nunk@163.com 希望与大家交流2007。08。03**********/
#include<reg51.h>
#include<drive_functions.h>
#include<get_keys.h>
#include<characters.h>
#include<menu_functions.h>
void (*current_operation_index)();
uchar func_index=0;
uchar func_index;
bit enter_flag=0;
typedef struct
{
uchar current; //当前执行的函数索引
uchar up; //按向上键时转向执行函数的索引
uchar down; //按向下键时转向执行函数的索引
uchar enter; //按回车键时转向执行函数的索引
void (*current_operation)(); //当前执行函数的指针
} key_table;
key_table code table[28]=
{
{0,24,8,1,(*fun0)}, //第一层,显示[贵州],四川,广东,返回
{1,7,3,2,(*fun1)},//按回车,进第二层,显示[贵阳],刘盘水,黄平,返回
{2,2,2,1,(*fun2)},//enter>guiyang is the capital of guizhou,[return]
{3,1,5,4,(*fun4)},//向下,显示贵阳,[六盘水],黄平,返回
{4,4,4,3,(*fun5)},//liupanshui is a base of coal mine of southern of china
{5,3,7,6,(*fun7)},//向下,显示贵阳,六盘水,[黄平],返回
{6,6,6,5,(*fun8)}, //huangping is my hometown,[return]
{7,5,1,0,(*fun10)},//贵阳,六盘水,黄平,[返回][
{8,0,16,9,(*fun12)},//贵州,[四川],广东,返回
{9,15,11,10,(*fun13)},//[成都],绵阳,乐山,返回
{10,10,10,9,(*fun14)},//chengdu is the capital of sichuan province,[return]
{11,9,13,12,(*fun16)},//成都,[绵阳],乐山,返回
{12,12,12,11,(*fun17)},//miangyang is a technology city of western china,[return]
{13,11,15,14,(*fun19)},//成都,绵阳,[乐山],返回
{14,14,14,13,(*fun20)},//leshan have leshan dafu,[return]
{15,13,9,8,(*fun22)},//down>成都,绵阳,乐山,[返回]
{16,8,24,17,(*fun24)},//down>贵州,四川,[广东],返回
{17,23,19,18,(*fun25)},//enter>[深圳],广州,惠州,返回
{18,18,18,17,(*fun26)},//enter>i'm now in shenzhen,[return]
{19,17,21,20,(*fun28)},//down>深圳,[广州],惠州,返回
{20,20,20,19,(*fun29)}, //enter>guangzhou is the capital of guangdong,return
{21,19,23,22,(*fun31)},//down>深圳,广州,[惠州],返回
{22,22,22,21,(*fun32)},//i'm in huizhou in 1997,[return]
{23,21,17,16,(*fun34)},//深圳,广州,惠州,[返回]
{24,16,0,25,(*fun36)},//贵州,四川,广东,[返回]
{25,26,26,27,(*fun37)},//[关闭],重启
{26,25,25,0,(*fun38)}, //关闭,[重启]
{27,27,27,27,(*fun39)}//关闭
};
void main(void)
{
current_operation_index=fun0;//初始化函数指针,使程序运行时执行第一个函数功能
while(1)
{
if(CheckState()) //检查是否有键按下
{
delay(); //延时去抖动
if(CheckState())
{
key=GetKeys(); //读取键盘值
/*******************find index****************************/
switch(key)
{
case 0x14:
func_index=table[func_index].up; //向上翻
break;
case 0x24:
func_index=table[func_index].enter;//回车
enter_flag=1;
break;
case 0x44:
func_index=table[func_index].down;//向下翻
break;
default:
break;
}
}
current_operation_index=table[func_index].current_operation;
if(enter_flag==1){ClearLCD();enter_flag==0;} //如果按了回车则需要清屏
}
// fun40();//显示左屏固定信息
(*current_operation_index)();//执行当前操作函数
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -