STC15 12864多级菜单可以自己添加的,亲测。
单片机源程序如下:
- #include "lcd12864.h"
- #include "key.h"
- #include "menu.h"
- #include "delay.h"
- static const unsigned char FunctionMiMa[] = "123456";
- static const unsigned char SuperMiMa[] = "111111";
- static PT_Menu g_pt_MenuHead = NULL;
- static PT_Menu g_pt_CurrentMenu = NULL;
- static int StrCmp(char *Source, char *Dist)
- {
- int i =0;
- if(Source == NULL || Dist == NULL)
- return -1;
- while(1){
- if (Source[i] != Dist[i]){
- break;
- }
- if(Source[i] == '\0')
- return 0;
- i++;
- }
- return 1;
- }
- static void RegisterPage(PT_Menu pt_Menu)
- {
- PT_Menu pt_Temp;
-
- pt_Menu->pt_Next = NULL;
- if(g_pt_MenuHead == NULL){
- g_pt_MenuHead = pt_Menu;
- }
- else{
- pt_Temp = g_pt_MenuHead;
-
- while(pt_Temp->pt_Next != NULL){
- pt_Temp = pt_Temp->pt_Next;
- }
-
- pt_Temp->pt_Next = pt_Menu;
- }
- }
- static PT_Menu GetMenu(char *pc_name)
- {
- PT_Menu pt_Temp;
- pt_Temp = g_pt_MenuHead;
- while(pt_Temp){
- if(StrCmp(pt_Temp->name,pc_name) == 0){
- return pt_Temp;
- }
- else{
- pt_Temp = pt_Temp->pt_Next;
- }
- }
- return NULL;
- }
- PT_Menu GetCurrentMenu(void)
- {
- return g_pt_CurrentMenu;
- }
- void SetCurrentMenu(PT_Menu pt_Menu)
- {
- g_pt_CurrentMenu = pt_Menu;
- }
- static unsigned char Verify(unsigned char *CheckMiMa){
- char MiMa[7];
- unsigned char Key = 20;
- char i=0;LCD_Clear();
- LCD_ShowString(1,1,12,"请输入密码: "); //????????LCD12864?????
- for(i=0; i<6; i++){
- delay_ms(1000);
- do{
- Key = Key_Service();
- }while(10 <= Key);
- LCD_ShowString(2,i,1,"X");
- MiMa[i] = Key + '0';
- }
- MiMa[i] = '\0';
- if(StrCmp(MiMa, CheckMiMa) == 0)
- return 1;
- return 0;
- }
- static void DrawMainMenu(void)
- {
- LCD_Clear();
- LCD_ShowString(1,0,16,"XXXXXXXXXXXXXXXX"); //????????LCD12864?????
- LCD_ShowString(2,6,4,"正\xfd常\xfd");
- LCD_ShowString(3,4,8," DC1:OUT");
- LCD_ShowString(4,0,4,"0591");
- LCD_ShowString(4,3,4,"自动");
- LCD_ShowString(4,5,6,"DC2:IN");
- }
- static PT_Menu MainMenuRun(void)
- {
- unsigned char Key = 20;
- while(1){
- do{
- Key = Key_Service();
- }while(20 == Key);
- if(11 == Key){
- delay_ms(3000);
- Key = Key_Service();
- if(11 == Key){
- if(Verify(FunctionMiMa))
- return GetMenu("Function");
- }
- }
- }
- return NULL;
- }
- static T_Menu MainMenu = {"Main", MainMenuRun, DrawMainMenu};
- static void DrawFunctionMenu(void)
- {
- LCD_Clear();
- LCD_ShowString(1,0,2,"1 ");
- LCD_ShowString(1,1,8,"?时间设置");
- LCD_ShowString(2,0,2,"2 ");
- LCD_ShowString(2,1,8,"背光设置");
- LCD_ShowString(3,0,2,"3 ");
- LCD_ShowString(3,1,8,"自动定时");
- LCD_ShowString(4,0,2,"4 ");
- LCD_ShowString(4,1,8,"查询功能");
- }
- static PT_Menu FunctionMenuRun(void)
- {
- unsigned char Flag = 0;
- unsigned char Key = 20;
- while(1){
- do{
- Key = Key_Service();
- }while(20 == Key);
- switch(Key){
- case 1:
- //SetTime
- break;
- case 2:
- //SetBlack
- break;
- case 3:
- //AutoTime
- break;
- case 4:
- return GetMenu("Query");
- case 9:
- if(Flag){
- if(Verify(SuperMiMa))
- return GetMenu("SuperFunction");
- Flag = 0;
- DrawFunctionMenu();
- }else
- Flag = 1;
- break;
- case 13:
- return GetMenu("Main");
- default:
- Flag = 0;
- break;
- }
-
- }
- return NULL;
- }
- static T_Menu FunctionMenu = {"Function", FunctionMenuRun, DrawFunctionMenu};
- static void DrawQueryMenu(void)
- {
- LCD_Clear();
- LCD_ShowString(1,0,2,"1 ");
- LCD_ShowString(1,1,8,"查询电池");
- LCD_ShowString(1,5,2,"IN");
- LCD_ShowString(1,6,4,"时长");
- LCD_ShowString(2,0,2,"2 ");
- LCD_ShowString(2,1,8,"查询电池");
- LCD_ShowString(2,5,4,"OUT ");
- LCD_ShowString(3,0,4,"时长");
-
- }
- static PT_Menu QueryMenuRun(void)
- {
- unsigned char Key = 20;
- while(1){
- do{
- Key = Key_Service();
- }while(20 == Key);
- switch(Key){
- case 1:
- //IN
- break;
- case 2:
- //OUT
- break;
- case 13:
- return GetMenu("Function");
- default:
- break;
- }
-
- }
- return NULL;
- }
- static T_Menu QueryMenu = {"Query", QueryMenuRun, DrawQueryMenu};
- static void DrawSuperFunctionMenu(void)
- {
- LCD_Clear();
- LCD_ShowString(1,0,2,"1 ");
- LCD_ShowString(1,1,10,"区域码设置");
-
- LCD_ShowString(2,0,2,"2");
- LCD_ShowString(2,2,8,"权限设置");
-
- LCD_ShowString(3,0,2,"3 ");
- LCD_ShowString(3,1,4,"预置");
- LCD_ShowString(3,3,4,"OUT ");
- LCD_ShowString(3,5,6,"时长判断");
- LCD_ShowString(4,0,2,"4 ");
- LCD_ShowString(4,1,12,"查询高级功能");
- }
- static PT_Menu SuperFunctionMenuRun(void)
- {
- unsigned char Key = 20;
- while(1){
- do{
- Key = Key_Service();
- }while(20 == Key);
- switch(Key){
- case 1:
- //区域码设置
- break;
- case 2:
- //权限设置
- break;
- case 3:
- ///预置OUT时长判定
- break;
- case 4:
- return GetMenu("SuperQuery");
- case 13:
- return GetMenu("Function");
- default:
- break;
- }
-
- }
- return NULL;
- }
- static T_Menu SuperFunctionMenu = { "SuperFunction", SuperFunctionMenuRun, DrawSuperFunctionMenu};
- static void DrawSuperQueryMenu(void)
- {
- LCD_Clear();
- LCD_ShowString(1,0,2,"1 ");
- LCD_ShowString(1,1,10,"查询电池");
- LCD_ShowString(1,5,2,"IN");
- LCD_ShowString(1,6,4,"时长");
-
- LCD_ShowString(2,0,2,"2 ");
- LCD_ShowString(2,1,10,"查询电池");
- LCD_ShowString(2,5,4,"OUT ");
- LCD_ShowString(2,7,4,"时长");
-
- LCD_ShowString(3,0,2,"3 ");
- LCD_ShowString(3,1,8,"查询电池");
- LCD_ShowString(3,5,2,"IN");
- LCD_ShowString(3,6,4,"次数\xfd");
- }
- static PT_Menu SuperQueryMenuRun(void)
- {
- unsigned char Key = 20;
- while(1){
- do{
- Key = Key_Service();
- }while(20 == Key);
- switch(Key){
- case 1:
- //查询电池IN时长
- break;
- case 2:
- //查询电池OUT时长
- break;
- case 3:
- ///查询电池IN次数
- break;
- case 13:
- return GetMenu("SuperFunction");
- default:
- break;
- }
-
- }
- return NULL;
- }
- static T_Menu SuperQueryMenu = { "SuperQuery", SuperQueryMenuRun, DrawSuperQueryMenu};
- void MenuInit(void)
- {
- RegisterPage(&MainMenu);
- RegisterPage(&FunctionMenu);
- RegisterPage(&QueryMenu);
- RegisterPage(&SuperFunctionMenu);
- RegisterPage(&SuperQueryMenu);
- SetCurrentMenu(GetMenu("Main"));
- }
复制代码
所有资料51hei提供下载:
多级菜单.rar
(2.25 KB, 下载次数: 96)
|