|
本帖最后由 lzm2010 于 2018-7-9 22:48 编辑
如题,在使用傻孩子菜单架构的时候,如下程序能正常切换上下菜单,但是无法进入子菜单,不知道问题出在哪里?请坛友指点,感谢。
- #ifndef _Menu_H_
- #define _Menu_H_
- #include "T32.h"
- #include "T32_board.h"
- #include "TFT_Driver.h"
- #include "stdio.h"
- #define keydown GPIO_ReadInBit(T32_GPIOC,GPIO_PIN_10)
- #define keyup GPIO_ReadInBit(T32_GPIOC,GPIO_PIN_9)
- #define keyenter GPIO_ReadInBit(T32_GPIOC,GPIO_PIN_11)
- #define keyreturn GPIO_ReadInBit(T32_GPIOC,GPIO_PIN_8)
- #define LCD1602MaxDisplaYLinE 5 //
- #define UP 1 //
- #define Down 2 //
- #define Enter 3
- #define Esc 4
- static unsigned int func_index=0;
- void NullSubs(void) //
- { }
- struct MenuItem SysTemSet[5]; //
- struct MenuItem BaudRatE[7]; //
- struct MenuItem EquipmenT[4]; //
- //*------------------------------------------------------------------------------
- //*
- //*------------------------------------------------------------------------------
- struct MenuItem //
- { unsigned char MenuCount; //
- unsigned char *DisplayString; //
- unsigned char (*Subs)(); //
- struct MenuItem *ChildrenMenus;//
- struct MenuItem *ParentMenus; //
- }menu;
- struct MenuItem MainMenu[4] = //
- {
- {4,"1.SysTem Set ",NullSubs,SysTemSet,NULL},
- {4,"2.EquipmenT ID ",NullSubs,EquipmenT,NULL},
- {4,"3.BaudRatE ",NullSubs,BaudRatE, NULL},
- {4,"4.System Infor ",NullSubs,NULL, NULL},
- };
- struct MenuItem SysTemSet[5] = //
- {
- {5,"1.DatA Set ",NullSubs,NULL,MainMenu},
- {5,"2.TimE Set ",NullSubs,NULL,MainMenu},
- {5,"3.AlarM Set ",NullSubs,NULL,MainMenu},
- {5,"4.BacKLed Set ",NullSubs,NULL,MainMenu},
- {5,"5.Password Set ",NullSubs,NULL, NULL},
- };
- struct MenuItem BaudRatE[7] = //
- {
- {7,"1.2400 ",NullSubs,NULL,MainMenu},
- {7,"2.4800 ",NullSubs,NULL,MainMenu},
- {7,"3.9600 ",NullSubs,NULL,MainMenu},
- {7,"4.19200 ",NullSubs,NULL,MainMenu},
- {7,"5.38400 ",NullSubs,NULL,MainMenu},
- {7,"6.57600 ",NullSubs,NULL,MainMenu},
- {7,"7.115200 ",NullSubs,NULL,MainMenu},
- };
- struct MenuItem EquipmenT[4] = //
- {
- {4,"1.No.01 ",NullSubs,NULL,MainMenu},
- {4,"2.No.02 ",NullSubs,NULL,MainMenu},
- {4,"3.NO.03 ",NullSubs,NULL,MainMenu},
- {4,"4.No.04 ",NullSubs,NULL,MainMenu},
- };
- struct MenuItem (*MenuPoint) = MainMenu;
- unsigned char DisplayStart = 0; //
- unsigned char UserChoose = 0; //
- unsigned char DisplayPoint = 0; //
- unsigned char MaxItems = 0; //
- unsigned char Option = 0; //
- unsigned char ShowCount=2;
- //*------------------------------------------------------------------------------
- //*
- //*------------------------------------------------------------------------------
- void ShowMenu(void)
- {
- unsigned char i = 0;
- MaxItems = MenuPoint[0].MenuCount; //
- DisplayPoint = DisplayStart;
- if (MaxItems > LCD1602MaxDisplaYLinE){ //
- for (i = 1;i < LCD1602MaxDisplaYLinE;i++){
- display_string_5x8_1(i,8,MenuPoint[DisplayPoint].DisplayString);
- if ((DisplayPoint) == (UserChoose)){
- display_string_5x8_1(1,1,">"); //
- }
- else{
- display_string_5x8_1(i,1," "); //
- }
- DisplayPoint += 1; //
- if ((DisplayPoint) >= (MaxItems)){
- DisplayPoint = 0;
-
-
- }
- }
- }
- else{
- for (i = 1;i < LCD1602MaxDisplaYLinE;i++){
- display_string_5x8_1(i,8,MenuPoint[DisplayPoint].DisplayString);
- if ((DisplayPoint) == (UserChoose)){
- display_string_5x8_1(1,1,">"); //
- }
- else{
- display_string_5x8_1(i,1," "); //
- }
- DisplayPoint += 1; //
- if ((DisplayPoint) >= (MaxItems)){
- DisplayPoint = 0;
-
- }
- }
- }
- }
- //void ShowMenu(void)
- //{
- // unsigned char n;
- // MaxItems = MenuPoint[0].MenuCount;//
- // DisplayPoint = DisplayStart;
- // for(n=0;DisplayPoint<MaxItems&&n<ShowCount;n++)
- // {
- // if(DisplayPoint==UserChoose)
- // //LCD_write_string(0,n,"->");
- // display_string_5x8_1(1,n,">");
- // // LCD_write_string(2,n,MenuPoint[DisplayPoint++].DisplayString);
- // display_string_5x8_1(n,8,MenuPoint[DisplayPoint].DisplayString);
- // }
- //}
- void __Delay(u32 count)
- {
- volatile u32 i=0,j=0;
- for(i=0;i<count;i++)
- for(j=0;j<1200;j++)
- {
- __NOP(); // Prevent delay loop be optimized
- }
- }
- unsigned int KEY_Scan(void)
- {
- if((keyup==0)||(keydown==0)||(keyenter==0)||(keyreturn==0))
- {
- __Delay(50);//
- if(keyup==0)
- {
- func_index=1; //
- while(!keyup);//
- }
- if(keydown==0)
- {
- func_index=2; //
- while(!keydown);
- }
- if(keyenter==0)
- {
- func_index=3; //
- while(!keyenter);
- }
- if(keyreturn==0)
- {
- func_index=4; //
- while(!keyreturn);
- }
-
- }
- else
- {
- func_index=5;
- }
- return func_index;
- }
- //*------------------------------------------------------------------------------
- //*
- //*------------------------------------------------------------------------------
- void ChangeMenu(void)
- { unsigned char GetKeyNum;
- GetKeyNum = KEY_Scan();
- if (GetKeyNum != 5){ //
- ShowMenu(); //
- switch (GetKeyNum){
- case UP:
- UserChoose--; //
- if (UserChoose == 0){
- UserChoose = MaxItems - 1;
- }
- break;
- case Down:
- UserChoose++;
- if (UserChoose >= MaxItems){
- UserChoose = 0;
- }
- break;
- case Enter:
- if ((MenuPoint[UserChoose].Subs) != NullSubs){
- (*MenuPoint[UserChoose].Subs)();
- }
- if (MenuPoint[UserChoose].ChildrenMenus != NULL){
- MenuPoint = MenuPoint[UserChoose].ChildrenMenus; //
- Option = UserChoose;
- UserChoose = 0;
- DisplayStart = 0;
- }
- break;
- case Esc:
- if (MenuPoint[0].ParentMenus != NULL){
- MenuPoint = MenuPoint[0].ParentMenus; //
- UserChoose = Option; //
- UserChoose = 0;
- DisplayStart = 0;
- }
- break;
- }
- //*--------------------------------------------------------------------
- //*
- if ((UserChoose <= DisplayStart) || (UserChoose >= (DisplayStart + 1 ))){
- DisplayStart = UserChoose;
- }
- //*--------------------------------------------------------------------
- // LCD1602CLEARDisplaY();
- //clear_screen();
- ShowMenu();
- //GetKeyNum=0;
- }
- }
- #endif
复制代码
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
有时候所谓难以割舍的感情,事实上只是不甘心而已。 (出处:黄舒骏《不要只因为他亲吻了你》)
|