MCU通用资源
返回
登录/注册
一个经典的液晶菜单程序
楼主
DC 于 2006-08-18 12:31:31
一个经典的液晶菜单程序
[P]转载:ahong007
[CODE]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);
}
}
[/CODE][/P]
回复
1楼
贝壳与海 于 2007-02-12 14:47:36
谢谢啦!!
回复
2楼
LSY135511 于 2007-03-01 15:02:34
谢谢
回复
3楼
蓝色理想 于 2007-03-08 08:28:11
DC,这个程序能不能移植到我们那块MC430F14这块板上啊,用KM12232F实现呢???
回复
4楼
DC 于 2007-03-08 10:39:21
我认这没什么好移植的,主要是理解和参考别人的程序思路.理解了思路,可以自行模仿或重新设计适合自己的.
回复
5楼
kuncskm 于 2007-04-06 08:25:32
参考一下
回复
1
2
电脑版
Page created in 0.6875 seconds width 5 queries.