lzm2010 发表于 2018-7-9 22:46:36

傻孩子菜单结构无法进入子菜单,烦请指教。

本帖最后由 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 keydownGPIO_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 Down2                            //
#define        Enter 3
#define Esc   4

static unsigned intfunc_index=0;

void NullSubs(void)                                            //
{                                   }

struct         MenuItem         SysTemSet;      //
struct         MenuItem         BaudRatE;           //
struct         MenuItem         EquipmenT;           //

//*------------------------------------------------------------------------------
//*
//*------------------------------------------------------------------------------
struct         MenuItem                           //
{                 unsigned char         MenuCount;         //
            unsigned char         *DisplayString;    //
            unsigned char         (*Subs)();         //
            struct MenuItem         *ChildrenMenus;//
            struct MenuItem         *ParentMenus;//
}menu;

struct        MenuItem        MainMenu =      //
{       
                {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,"1.DatASet   ",NullSubs,NULL,MainMenu},
                {5,"2.TimESet   ",NullSubs,NULL,MainMenu},
                {5,"3.AlarM Set   ",NullSubs,NULL,MainMenu},
                {5,"4.BacKLedSet",NullSubs,NULL,MainMenu},
                {5,"5.Password Set",NullSubs,NULL,   NULL},
};

struct         MenuItem         BaudRatE =           //
{
                {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,"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.MenuCount;      //
                DisplayPoint = DisplayStart;
                if (MaxItems > LCD1602MaxDisplaYLinE){          //
                        for (i = 1;i < LCD1602MaxDisplaYLinE;i++){
                                        display_string_5x8_1(i,8,MenuPoint.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.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.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.DisplayString);
//              display_string_5x8_1(n,8,MenuPoint.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.Subs) != NullSubs){
                              (*MenuPoint.Subs)();
                            }
                            if (MenuPoint.ChildrenMenus != NULL){
                              MenuPoint        = MenuPoint.ChildrenMenus;//
                                                Option               = UserChoose;
                              UserChoose        = 0;
                              DisplayStart = 0;
                            }
                       break;
                                case Esc:
                            if (MenuPoint.ParentMenus != NULL){                                
                                    MenuPoint        = MenuPoint.ParentMenus;                        //

                                                UserChoose   = Option;        //
                                          UserChoose        = 0;
                                    DisplayStart = 0;
                            }
                       break;                                
                        }
                        //*--------------------------------------------------------------------
                        //*
                        if ((UserChoose <= DisplayStart) || (UserChoose >= (DisplayStart + 1 ))){
                          DisplayStart = UserChoose;
                  }
                        //*--------------------------------------------------------------------
                //        LCD1602CLEARDisplaY();
                        //clear_screen();
                  ShowMenu();               
                        //GetKeyNum=0;
                }
}

#endif



Gorgon_Meducer 发表于 2018-7-10 21:54:39

你单步试过了么?特别是代码215行这里,你在这里切换完菜单以后,立即ShowMenu跟踪下。

另外,推荐你看下我写的新的文章:

https://www.amobbs.com/thread-5688720-1-1.html

lzm2010 发表于 2018-7-10 22:55:31

Gorgon_Meducer 发表于 2018-7-10 21:54
你单步试过了么?特别是代码215行这里,你在这里切换完菜单以后,立即ShowMenu跟踪下。

另外,推荐你看下 ...

感谢回复,刚进去debug了一下,发现是TB山寨杜邦线害死人啊,没想到进入子菜单的杜邦线是断路的,坑爹,换线后程序能正常工作,您的新帖我再琢磨琢磨。{:smile:}

Gorgon_Meducer 发表于 2018-7-10 23:37:07

lzm2010 发表于 2018-7-10 22:55
感谢回复,刚进去debug了一下,发现是TB山寨杜邦线害死人啊,没想到进入子菜单的杜邦线是断路的,坑爹, ...

哈哈。问题解决就好。建议你早日转换到新结构上。
页: [1]
查看完整版本: 傻孩子菜单结构无法进入子菜单,烦请指教。