menudrive.h
来自「这是用proteus做的基于51核的一个菜单仿真的程序开发环境keil 没有使用」· C头文件 代码 · 共 432 行
H
432 行
//---------------------------------------------
// the general menu driver using the tree struct
// write by liujianwei 2005-7-1
// e-mail:liujianwei@ruyi.com
// qq:361299856
//---------------------------------------------
//----------------------------------------------------------------------------------
// the globle varible declar here
//---------------------------------------------------------------------------------
//#include <keypaddrive.h>
//#include <lcddrive.h>
#define RUNING 0x01
#define OVER_RUN 0x00
#define NULL 0xffff
#define unchar unsigned char
typedef struct MENU{
unchar Horizon; //heng zuo biao
unchar *MenuTitle ;
struct MENU *pSonMenu;
struct MENU *pFatheMenu;
struct MENU *pBrotheNext;
struct MENU *pBrothePrev;
void (*CurrentOperation)();
};
void Function0();
void Function1();
void Function2();
void Function3();
void Function4();
void Function5();
void Function6();
unchar menu1[]="the menu1";
unchar menu2[]="the menu2";
unchar menu3[]="the menu3";
unchar menu4[]="the menu4";
unchar subm5[]="the menu5";
unchar subm6[]="the menu6";
unchar subm7[]="the menu7";
struct MENU code MyMenu [7]={
{0,&menu1 ,NULL,NULL,&MyMenu[1],NULL,Function0 },
{1,&menu2 ,&MyMenu[4],NULL,&MyMenu[2],&MyMenu[0],Function1},
{2,&menu3 ,NULL,NULL,&MyMenu[3],&MyMenu[1],Function2},
{3,&menu4 ,NULL,NULL,NULL,&MyMenu[2],Function3},
{0,&subm5 ,&MyMenu[6],&MyMenu[1],&MyMenu[5],NULL,Function4},
{1,&subm6 ,NULL,&MyMenu[1],NULL,&MyMenu[4],Function5},
{0,&subm7 ,NULL,&MyMenu[4],NULL,NULL,Function6},
};
struct MENU *pCurrentMenu=&MyMenu[0];
struct MENU *pCurrentMenu1=&MyMenu[0];
unchar MenuStatus=0;
unchar CurrentOperations=RUNING;
unchar FunctionStatus=0;
unchar Delay;
//------------------------------------
//initialzation menu
//------------------------------------
// pCurrentMenu =&MyMenu[0]; //can't be set here but i don't know why??????????
// pCurrentMenu1 =&MyMenu[0];
void MenuFunction()
{
unchar Chars,i;
switch(MenuStatus)
{
case 0:
{
Chars=GetKey();
if (Chars==ESC_KEY)
{
ClrScreen();
if (pCurrentMenu1->pFatheMenu!=NULL)
{
// pCurrentMenu1=pCurrentMenu1->pFatheMenu;
// pCurrentMenu1=pCurrentMenu1->pSonMenu;
}
else
while(pCurrentMenu1->pBrothePrev!=NULL)
pCurrentMenu1=pCurrentMenu1->pBrothePrev;
i=0;
while(pCurrentMenu1->pBrotheNext!=NULL)
{
AdressPointSet((6+i*32)%256,(6+i*32)/256);
DisplayString(pCurrentMenu1->MenuTitle);
i++;
pCurrentMenu1=pCurrentMenu1->pBrotheNext;
}
AdressPointSet((6+i*32)%256,(6+i*32)/256);
DisplayString(pCurrentMenu1->MenuTitle);
AdressPointSet((GRAPHIC_HOME_ADRESS+6+pCurrentMenu->Horizon*32)%256,(GRAPHIC_HOME_ADRESS+6+pCurrentMenu->Horizon*32)/256);
GraphicAttribAutoWrite(05,10);
MenuStatus=1;
}
break;
}
case 1:
{
switch(GetKey())
{
case ENTER_KEY:
ClrScreen();
if (pCurrentMenu->pSonMenu==NULL)
MenuStatus=2;
else
{
pCurrentMenu=pCurrentMenu->pSonMenu;
pCurrentMenu1=pCurrentMenu;
if (pCurrentMenu1->pFatheMenu!=NULL)
{
pCurrentMenu1=pCurrentMenu1->pFatheMenu;
pCurrentMenu1=pCurrentMenu1->pSonMenu;
}
else
while(pCurrentMenu1->pBrothePrev!=NULL)
pCurrentMenu1=pCurrentMenu1->pBrothePrev;
i=0;
while(pCurrentMenu1->pBrotheNext!=NULL)
{
AdressPointSet((6+i*32)%256,(6+i*32)/256);
DisplayString(pCurrentMenu1->MenuTitle);
i++;
pCurrentMenu1=pCurrentMenu1->pBrotheNext;
}
AdressPointSet((6+i*32)%256,(6+i*32)/256);
DisplayString(pCurrentMenu1->MenuTitle);
AdressPointSet((GRAPHIC_HOME_ADRESS+6+pCurrentMenu->Horizon*32)%256,(GRAPHIC_HOME_ADRESS+6+pCurrentMenu->Horizon*32)/256);
GraphicAttribAutoWrite(05,10);
}
break;
case UP_KEY:
if (pCurrentMenu->pBrothePrev!=NULL)
{
AdressPointSet((GRAPHIC_HOME_ADRESS+6+pCurrentMenu->Horizon*32)%256,(GRAPHIC_HOME_ADRESS+6+pCurrentMenu->Horizon*32)/256);
GraphicAttribAutoWrite(00,10); // clr the 反白显示
pCurrentMenu=pCurrentMenu->pBrothePrev;
AdressPointSet((GRAPHIC_HOME_ADRESS+6+pCurrentMenu->Horizon*32)%256,(GRAPHIC_HOME_ADRESS+6+pCurrentMenu->Horizon*32)/256);
GraphicAttribAutoWrite(05,10); //使之反白显示
}
break;
case DOWN_KEY:
if (pCurrentMenu->pBrotheNext!=NULL)
{
AdressPointSet((GRAPHIC_HOME_ADRESS+6+pCurrentMenu->Horizon*32)%256,(GRAPHIC_HOME_ADRESS+6+pCurrentMenu->Horizon*32)/256);
GraphicAttribAutoWrite(00,10);
pCurrentMenu=pCurrentMenu->pBrotheNext;
AdressPointSet((GRAPHIC_HOME_ADRESS+6+pCurrentMenu->Horizon*32)%256,(GRAPHIC_HOME_ADRESS+6+pCurrentMenu->Horizon*32)/256);
GraphicAttribAutoWrite(05,10);
}
break;
case ESC_KEY:
if(pCurrentMenu->pFatheMenu!=NULL)
{
pCurrentMenu=pCurrentMenu->pFatheMenu;
ClrScreen();
pCurrentMenu1=pCurrentMenu;
if (pCurrentMenu1->pFatheMenu!=NULL)
{
pCurrentMenu1=pCurrentMenu1->pFatheMenu;
pCurrentMenu1=pCurrentMenu1->pSonMenu;
}
else
while(pCurrentMenu1->pBrothePrev!=NULL)
pCurrentMenu1=pCurrentMenu1->pBrothePrev;
i=0;
while(pCurrentMenu1->pBrotheNext!=NULL)
{
AdressPointSet((6+i*32)%256,(6+i*32)/256);
DisplayString(pCurrentMenu1->MenuTitle);
i++;
pCurrentMenu1=pCurrentMenu1->pBrotheNext;
}
AdressPointSet((6+i*32)%256,(6+i*32)/256);
DisplayString(pCurrentMenu1->MenuTitle);
AdressPointSet((GRAPHIC_HOME_ADRESS+6+pCurrentMenu->Horizon*32)%256,(GRAPHIC_HOME_ADRESS+6+pCurrentMenu->Horizon*32)/256);
GraphicAttribAutoWrite(05,10);
}
else
{
ClrScreen();
AdressPointSet(0,0);
DisplayString("please enter menukey to in the menu");
pCurrentMenu=&MyMenu[0];
MenuStatus=0;
}
case 0: break;
default: break;
}
break;
}
case 2:
(pCurrentMenu->CurrentOperation)();
if (CurrentOperations==OVER_RUN)
{ Chars=GetKey();
if (Chars==ESC_KEY)
{
CurrentOperations=RUNING;
FunctionStatus=0;
pCurrentMenu1=pCurrentMenu;
if (pCurrentMenu1->pFatheMenu!=NULL)
{
pCurrentMenu1=pCurrentMenu1->pFatheMenu;
pCurrentMenu1=pCurrentMenu1->pSonMenu;
}
else
while(pCurrentMenu1->pBrothePrev!=NULL)
pCurrentMenu1=pCurrentMenu1->pBrothePrev;
ClrScreen();
i=0;
while(pCurrentMenu1->pBrotheNext!=NULL)
{
AdressPointSet((6+i*32)%256,(6+i*32)/256);
DisplayString(pCurrentMenu1->MenuTitle);
i++;
pCurrentMenu1=pCurrentMenu1->pBrotheNext;
}
AdressPointSet((6+i*32)%256,(6+i*32)/256);
DisplayString(pCurrentMenu1->MenuTitle);
AdressPointSet((GRAPHIC_HOME_ADRESS+6+pCurrentMenu->Horizon*32)%256,(GRAPHIC_HOME_ADRESS+6+pCurrentMenu->Horizon*32)/256);
GraphicAttribAutoWrite(05,10);
MenuStatus=1;
}
}
break;
}
}
void Function0()
{
if (CurrentOperations==RUNING)
{
switch (FunctionStatus)
{
case 0:
CurrentOperations=RUNING;
AdressPointSet(14*32%256,14*32/256);
DisplayString("this is the first menu Function");
FunctionStatus=1;
Delay=0;
break;
case 1:
if (Delay>=0xf7 )
CurrentOperations=OVER_RUN ;
}
}
}
void Function1()
{
if (CurrentOperations==RUNING)
{
switch (FunctionStatus)
{
case 0:
CurrentOperations=RUNING;
AdressPointSet(14*32%256,14*32/256);
DisplayString("this is the secend menu Function");
FunctionStatus=1;
Delay=0;
break;
case 1:
if (Delay>=0xf7 )
CurrentOperations=OVER_RUN ;
}
}
}
void Function2()
{
if (CurrentOperations==RUNING)
{
switch (FunctionStatus)
{
case 0:
CurrentOperations=RUNING;
AdressPointSet(14*32%256,14*32/256);
DisplayString("this is the third menu Function");
FunctionStatus=1;
Delay=0;
break;
case 1:
if (Delay>=0xf7 )
CurrentOperations=OVER_RUN ;
}
}
}
void Function3()
{
if (CurrentOperations==RUNING)
{
switch (FunctionStatus)
{
case 0:
CurrentOperations=RUNING;
AdressPointSet(14*32%256,14*32/256);
DisplayString("this is the forth menu Function");
FunctionStatus=1;
Delay=0;
break;
case 1:
if (Delay>=0xf7 )
CurrentOperations=OVER_RUN ;
}
}
}
void Function4()
{
if (CurrentOperations==RUNING)
{
switch (FunctionStatus)
{
case 0:
CurrentOperations=RUNING;
AdressPointSet(14*32%256,14*32/256);
DisplayString("this is the fifh menu Function");
FunctionStatus=1;
Delay=0;
break;
case 1:
if (Delay>=0xf7 )
CurrentOperations=OVER_RUN ;
}
}
}
void Function5()
{
if (CurrentOperations==RUNING)
{
switch (FunctionStatus)
{
case 0:
CurrentOperations=RUNING;
AdressPointSet(14*32%256,14*32/256);
DisplayString("this is the sixth menu Function");
FunctionStatus=1;
Delay=0;
break;
case 1:
if (Delay>=0xf7 )
CurrentOperations=OVER_RUN ;
}
}
}
void Function6()
{
if (CurrentOperations==RUNING)
{
switch (FunctionStatus)
{
case 0:
CurrentOperations=RUNING;
AdressPointSet(14*32%256,14*32/256);
DisplayString("this is the seveth menu Function");
FunctionStatus=1;
Delay=0;
break;
case 1:
if (Delay>=0xf7 )
CurrentOperations=OVER_RUN ;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?