《带菜单的液晶显示,基于st7920的12864》由会员分享,可在线阅读,更多相关《带菜单的液晶显示,基于st7920的12864(23页珍藏版)》请在金锄头文库上搜索。
1、带菜单的液晶显示带菜单的液晶显示, ,基于基于 st7920st7920 的的 1286412864程序 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_#i
2、nclude “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; /用来各个界面之间的切换时传递参数./=/系统界面函数声明区.(一定要声明!) 有几个不同的界面就有几个函数v
3、oid 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
4、) 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.P
5、lay 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(SysScltIDLE_MENU_MAX)SysSclt
6、=0;ShowARROW(SysSclt);break;/确定 进入 子项case Key_Right: if(SysSclt = 0) /TemperatureUI_GOTO_CHILD(UI_Temperature);/KeyDir = GOTO_CHILD;break; if(SysSclt = 1) /TimeUI_GOTO_CHILD(UI_Time);/KeyDir = GOTO_CHILD;break; if(SysSclt = 2) /TimeUI_GOTO_CHILD(UI_Play);/KeyDir = GOTO_CHILD;break; if(SysSclt = 3) /
7、TimeUI_GOTO_CHILD(UI_Set);/KeyDir = GOTO_CHILD;break; if(SysSclt = 4) /helpUI_GOTO_CHILD(UI_Help);/KeyDir = GOTO_CHILD;break; default:break;/switchvoid UI_Temperature()switch(Key)/进入菜单.case FROM_FATHER:/case FROM_CHILD:LcdClrScrn();ShowLine(0, “The“);ShowLine(2, “Temperature“);ShowLine(4, “is 27“);/
8、改天加 DS18B20 实际测一个ShowLine(7, “back“);break; case Key_Left:UI_GOTO_FATHER(UI_Idle);break;default:break;/switchvoid 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; cas
9、e Key_Left:UI_GOTO_FATHER(UI_Idle);break;default:break;/switchvoid 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_
10、Idle);break;default:break;/switchvoid 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;/switchvoid UI_Help()switch(Key)/进入菜单.case FROM_FATHER:/case FROM_CHILD:LcdClr
11、Scrn();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/系统的大循环.void Interface(void)/=/以下为按键的处理.Key = GetKey();if(KeyDir!=0) /KeyDir=GOTO_CHILD or KeyDir=GOTO_FATHER;/建立一种传递信息的
12、变量.Key = KeyDir;KeyDir = 0;/=/以下为界面的相互调用pUI();#endif =#ifndef _KEY_H_#define _KEY_H_#define Key_Up 0x11#define Key_Down 0x12#define Key_Left 0x13#define Key_Right 0x14/uchar Key_Scan();void delay_ms(unsigned int t)unsigned int i,j;for(i=0;i#define uchar unsigned char#define uint unsigned int#define
13、WR_L() PORTDelsedisplay_HZ(0,i,HZ2i);while(1);/调整文本区首地址,可以实现移屏;/i+;/ write_cmd3(i+,0,0x40);/文本区首地址;/ delay(10000);/*/#include /处在 x y 处显示汉字 hzvoid display_HZ(uchar x,uchar y,uchar *hz)/x 0-3 y 0-7uchar i,j=0;for(i=0;i=16)x+;i=0; void delay(uint t)uint i,j;for(i=0;it;i+)for(j=0;j1141;j+);void init_txt_12864()/初始化端口DDRD=0XFF;DDRB=0XFF;PORTB=0XFF;/液晶复位RST_L();delay(1);RST_L();/所有控制引脚置高WR_H();RD_H();CE_H();CD_H();RST_H();/初始化指令check_status();write_cmd3(0x01,0x00,0x21);/光标指针设置check_status();write_cmd3(0x00,0x00,0x40);/文本区首地址