微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 简单菜单系统 Proteus pg12864 液晶

简单菜单系统 Proteus pg12864 液晶

时间:11-13 来源:互联网 点击:



Mega16单片机


程序 interface.h

/*
移植时要实现以下函数:

LcdClrScrn(); //清屏
ShowARROW(SysSclt); //在某一行显示箭头
DisShowARROW(SysSclt); //在某一行不显示箭头
ShowLine(0, "Copy Right"); //在某一行显示字符串
uchar GetKey(); //按键检测函数。
返回Key_Up Key_Down Key_Right Key_Left
*/

#ifndef __INTERFACE_H__
#define __INTERFACE_H__

#include "KEY.h"
//extern void Interface(void);

#define GOTO_CHILD 0XFC
#define FROM_FATHER 0XFC

#define GOTO_FATHER 0XFD //之前设置为0xff 不对,有问题,子界面返回时,不刷新
#define FROM_CHILD 0XFD

//##########################################################
#define INT8U unsigned char

INT8U Key; //系统按键.
INT8U KeyDir = FROM_FATHER; //用来各个界面之间的切换时传递参数.

//==============================================================
//系统界面函数声明区.(一定要声明!) 有几个不同的界面就有几个函数
void UI_Idle(void);
void UI_Help(void);
void UI_Time();
void UI_Temperature();
void UI_Play();
void UI_Set();

void (*pUI)()=UI_Idle; //界面指针初始化为IDLE函数. 函数指针

//pUI();为当前while()大循环下执行的函数
#define UI_GOTO(index) {pUI=(index);}
#define UI_GOTO_CHILD(index) {pUI=(index); KeyDir=GOTO_CHILD;}
#define UI_GOTO_FATHER(index) {pUI=(index); KeyDir=GOTO_FATHER;}

//========================================================================
//以下是各个界面的函数实现.每个函数都要在上面声明!

//空闲状态下的循环.
void UI_Idle()
{
static INT8U SysSclt=0; //当前选中的是哪一项

switch(Key)
{
//进入菜单.
case FROM_FATHER:
case FROM_CHILD:
//case GOTO_FATHER:
LcdClrScrn();
// 0 1 2 3 4
#define IDLE_MENU_MAX 4
ShowLine(0,"1.Temperature");
ShowLine(1,"2.Time");
ShowLine(2,"3.Play Games");
ShowLine(3,"4.Set ");
ShowLine(4,"5.Help");
ShowLine(7," select");
ShowARROW(SysSclt);
break;
//箭头上移
case Key_Up:
DisShowARROW(SysSclt);
if(SysSclt==0)SysSclt=IDLE_MENU_MAX;
else SysSclt--;
ShowARROW(SysSclt);
break;
//箭头下移
case Key_Down:

DisShowARROW(SysSclt);
SysSclt++;
if(SysSclt>IDLE_MENU_MAX)SysSclt=0;
ShowARROW(SysSclt);
break;
//确定 进入 子项
case Key_Right:

if(SysSclt == 0) //Temperature
{
UI_GOTO_CHILD(UI_Temperature);
//KeyDir = GOTO_CHILD;

break;
}
if(SysSclt == 1) //Time
{
UI_GOTO_CHILD(UI_Time);
//KeyDir = GOTO_CHILD;

break;
}
if(SysSclt == 2) //Time
{
UI_GOTO_CHILD(UI_Play);
//KeyDir = GOTO_CHILD;

break;
}
if(SysSclt == 3) //Time
{
UI_GOTO_CHILD(UI_Set);
//KeyDir = GOTO_CHILD;

break;
}
if(SysSclt == 4) //help
{
UI_GOTO_CHILD(UI_Help);
//KeyDir = GOTO_CHILD;

break;
}

default:break;
}//switch

}
void UI_Temperature()
{
switch(Key)
{
//进入菜单.
case FROM_FATHER:
//case FROM_CHILD:
LcdClrScrn();
ShowLine(0, "The");
ShowLine(2, "Temperature");
ShowLine(4, "is 27");
//改天加DS18B20实际测一个
ShowLine(7, "back");
break;
case Key_Left:

UI_GOTO_FATHER(UI_Idle);

break;
default:break;
}//switch
}

void UI_Time()
{
switch(Key)
{
//进入菜单.
case FROM_FATHER:
//case FROM_CHILD:
LcdClrScrn();
ShowLine(0, "The Time is ");
ShowLine(2, "09-12-24");
ShowLine(4, "0:01 1234567890");
ShowLine(7, "back");
break;
case Key_Left:

UI_GOTO_FATHER(UI_Idle);

break;
default:break;
}//switch

}
void UI_Play()
{
switch(Key)
{
//进入菜单.
case FROM_FATHER:
//case FROM_CHILD:
LcdClrScrn();
ShowLine(0, "YOU get to ");
ShowLine(1, "go back to");
ShowLine(2, "STUDY");
ShowLine(4, "Made dy LYQ");
ShowLine(7, "back");
break;
case Key_Left:

UI_GOTO_FATHER(UI_Idle);

break;
default:break;
}//switch
}
void UI_Set()
{
switch(Key)
{
//进入菜单.
case FROM_FATHER:
//case FROM_CHILD:
LcdClrScrn();
ShowLine(0, "Nothing NOW");

ShowLine(7, "back");
break;
case Key_Left:

UI_GOTO_FATHER(UI_Idle);

break;
default:break;
}//switch
}
void UI_Help()
{
switch(Key)
{
//进入菜单.
case FROM_FATHER:
//case FROM_CHILD:
LcdClrScrn();
ShowLine(0, "Copy Right");
ShowLine(2, "I love China");
ShowLine(4, "Made dy LYQ");
ShowLine(7, "back");
break;
case Key_Left:

UI_GOTO_FATHER(UI_Idle);

break;
default:break;
}//switch

}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top