51/AVR单片机技术驿站!  <在线翻译>     便利工具    特色网址   无弹窗、无插件的绿色站点...  英才招聘   学历查询  喜欢>>收藏我站 

当前位置:首页 > 单片机源码 > 详细内容
LCD 菜单程序的思路跟源码(C语言)
发布时间:2009/6/4  阅读次数:1569  字体大小: 【】 【】【

作者:tamson     来源:21IC.COM

LCD 菜单程序的思路:定义一个变量,记录菜单的级别序号,另一个变量记录某一级别下的菜单项序号。这样你可以用一个数组保存你的菜单结构,比如叫 menu_table[NUMS_LEVEL][NUMS_ITEM_PER_LEVEL];然后你在按键处理里面根据按键记录菜单级别及其相应的菜单项序号,进行相应的处理就行了。

unsigned char tempin,tempout,temprun;
unsigned char Key_Value();
unsigned char Change_Value(unsigned char);
void Delay_1(unsigned int m);
void Run_Satus();
char * MainMenuTitle = "主菜单";
const char * MainMenuItems[] = {
      "1.室内温度调整",
      "2.室外温度调整",
      "3.运行时间调整",
      "4.ESC      退出",
};
TMenu MainMenu;
void OnSelectMainMenu(int index)
{           
      if (index < 0 || index >= sizeof(MainMenuItems) / sizeof(char *)) return;
      ClearScreen();
      switch (index) {
      case 0:
             TextOut(0, 1, "室内调整开始 ");
             tempin=Change_Value(tempin);
             TextOut(0, 1, "室内调整完毕");
             Delay_1(300000);
             break;
      case 1:
           TextOut(0, 1, "室外调整开始 ");
           tempout=Change_Value(tempout);
           TextOut(0, 1, "室外调整完毕");
             Delay_1(300000);
             break;
      case 2:
           TextOut(0, 1, "运行时间调整开始");
           tempout=Change_Value(temprun);
             TextOut(0, 1, "运行时间完毕");
              Delay_1(300000);
             break;
      case 3:
           break;
      }
      ClearScreen();
}
UINT OnMainMenuOk(void * arg)
{
      TMenu * pMenu = (TMenu *)arg;
      if (pMenu) OnSelectMainMenu(pMenu->Current);
      return 0;
}
UINT OnMainMenuCancel(void * arg)
{
      TMenu * pMenu = (TMenu *)arg;
      if (pMenu) {
             CloseMenu(pMenu);
      }
      return 0;
}
UINT OnMainMenuOtherKey(void * arg)
{
      TMenu * pMenu = (TMenu *)arg;
      char key;
      if (pMenu) {
             key = pMenu->EventArg;
             OnSelectMainMenu(key - '1');
             DrawMenu(pMenu);
      }
      return 0;
}
void InitMenu()
{
      InitializeMenu(&MainMenu, MainMenuTitle, MainMenuItems, sizeof
(MainMenuItems) / sizeof(char *));
      MainMenu.OnOk = OnMainMenuOk;
      MainMenu.OnOtherKey = OnMainMenuOtherKey;
      MainMenu.OnCancel = OnMainMenuCancel;
}
unsigned char Key_Value()
{
   unsigned char KeyTemp;
   KeyTemp=GetKey();
   switch(KeyTemp)
   {   case(VK_ESCAPE):
                return(0);
                break;
         case(VK_ENTER):
                return(1);
                break;
         case(VK_UP):
                return(2);
                break;
         case(VK_DOWN):
                return(3);
                break;
                }
}
unsigned char Change_Value(unsigned char temp2)
{ unsigned char temp3;
     temp3=temp2;
while((Key_Value()!=0)&&(Key_Value()!=1))
             {
             if(Key_Value()==2)temp3++;
             else if(Key_Value()==3)temp3--;
             ClearLine(1);
             TextOut(0, 1, "调整状态%d", temp3);
             }
             if(Key_Value()==1)return(temp3);
             else if(Key_Value()==0) return(temp2);
}
  void Delay_1(unsigned int m)
  {while(m--);
  }
void Run_Satus()
{
  ClearScreen();
  TextOut(0, 0, "室内温度   %d",tempin);
  TextOut(0, 1, "室外温度   %d",tempout);
  TextOut(0, 2, "运行时间   %d",temprun);
  TextOut(0, 3, "ENTER 进入调整");
}
void tmain()
{
        tempin=30;
        tempout=30;
        temprun=30;
      unsigned char key;
      InitMenu();
      while(1)
      {
      Run_Satus();
      key=GetKey();
      if(key==VK_ENTER)ShowMenu(&MainMenu);
}
}

  

我要评论
  • 匿名发表
  • [添加到收藏夹]
  • 发表评论:(匿名发表无需登录,已登录用户可直接发表。) 登录状态:未登录
最新评论
所有评论[0]
    暂无已审核评论!

网站导航 管理登陆 ┊ 免责声明 问题反馈  友链说明
本站部分内容来自网络共享资源,如有冒犯您的权利请来信告之删除或纠正!
不得对本站进行复制、盗链或镜像,转载内容须获得同意或授权;欢迎友情链接、站务合作!

    我要报警 Alexa
 mcusy_cn#126.com (请把#改成@) 交流:522422171
本站学习交流群:138..158(高级群1-)、77930286(高级群2)、61804809(群3)
Copyright© MCUSY All Rights Reserved
本站网警备案号: WZ36040002485
  ICP备案证书号:粤ICP备09034963号