简单菜单系统Proteuspg12864液晶.doc_第1页
简单菜单系统Proteuspg12864液晶.doc_第2页
简单菜单系统Proteuspg12864液晶.doc_第3页
简单菜单系统Proteuspg12864液晶.doc_第4页
简单菜单系统Proteuspg12864液晶.doc_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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(SysScltIDLE_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;/switchvoid 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;/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; case 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_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: 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/系统的大循环.void Interface(void)/=/以下为按键的处理.Key = GetKey(); if(KeyDir!=0) /KeyDir=GOTO_CHILD or KeyDir=GOTO_FATHER; /建立一种传递信息的变量. 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;it;i+) for(j=0;j1141;j+);unsigned char Key_Scan()unsigned char key;DDRA|=0X0f; /输出PORTA|=0Xff; /上拉DDRA&=0X0f; /输入if(PINA=0xfe) delay_ms(10); if(PINA=0xfe) while(PINA=0xfe); /等待松手 return Key_Up; if(PINA=0xfd) delay_ms(10); if(PINA=0xfd) while(PINA=0xfd); return Key_Down; if(PINA=0xfb) delay_ms(10); if(PINA=0xfb) while(PINA=0xfb); return Key_Left; if(PINA=0xf7) delay_ms(10); if(PINA=0xf7) while(PINA=0xf7); return Key_Right; return 0;/没有键按下返回0unsigned char GetKey()return Key_Scan();#endif =#-=#ifndef _PG12864_H_#define _PG12864_H_#include #define uchar unsigned char#define uint unsigned int#define WR_L() PORTD&=(1)#define WR_H() PORTD|=(1)#define RD_L() PORTD&=(11)#define RD_H() PORTD|=(11)#define CE_L() PORTD&=(12)#define CE_H() PORTD|=(12)#define CD_L() PORTD&=(13)#define CD_H() PORTD|=(13)#define RST_L() PORTD&=(14)#define RST_H() PORTD|=(14)void delay(uint t);uchar read_status()uchar status;DDRB=0;/端口b置为输入RD_L();WR_H();CE_L();CD_H();status=PINB;return status;void check_status()uchar s;DDRB=0XFF;/端口b置为输出while(s&0x03)!=0x03) s=read_status();/等待位1,2置为。命令读写准备好。数据读写准备好/void init_txt_12864();void write_data(uchar data);void write_cmd1(uchar cmd);void write_cmd2(uchar data,uchar cmd);void write_cmd3(uchar data1,uchar data2,uchar cmd);/uchar read_status();/void clear_screen();void display_char(uchar x,uchar y,uchar ch);/void init_graphic_12864();/void display_HZ(uchar x,uchar y,uchar *hz); /x 0-3 y 0-7/void display_string(uchar x,uchar y,uchar *s);/*int main() uchar i,j=0; init_txt_12864(); display_string(0,0,ch); delay(100); clear_screen(); init_graphic_12864(); for(i=0;i=8) display_HZ(1,i-8,HZ2i); else display_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;i16;i+) write_cmd3(j/2)4)|(y*2),x,0x24);/地址指针设置.低地址,高地址,命令 write_cmd2(hzj+,0xc0); write_cmd2(hzj+,0xc0);/处在x y处显示chvoid display_char(uchar x,uchar y, uchar ch)/x 0-7 y 0-15write_cmd3(x*2)=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);/文本区首地址check_status();/加上下面2行代码,只显示4行?而不是8行!/write_cmd3(16,0x00,0x41);/文本区宽度。字节数/行&/check_status();write_cmd1(0x80);/显示方式设置,正常显示check_status();write_cmd1(0x94);/。显示状态设置 1 0 1 0 N3 N2 N1 N0 文本显示,光标不显示,不闪烁/write_cmd1(0x98);/图形方式显示,不显示字母,只打点check_status();write_cmd1(0xa1);/光标形状设置1 0 1 0 0 N2 N1 N0void init_graphic_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,0x42);/图形区首地址check_status();write_cmd3(16,0x00,0x43);/图形区宽度check_status();write_cmd1(0x80);/显示方式设置,正常显示check_status();/write_cmd1(0x94);/。显示状态设置 1 0 1 0 N3 N2 N1 N0 文本显示,光标不显示,不闪烁write_cmd1(0x98);/图形方式显示,不显示字母,只打点check_status();write_cmd1(0xa0);/光标形状设置1 0 1 0 0 N2 N1 N0void clear_screen()uint i;write_cmd3(0x00,0x00,0x24);/地址指针设置check_status();write_cmd1(0xb0);/数据自动写,每写一次,地址指针自动加一check_status();for(i=0;i8192;i+) check_status(); write_data(0X00);check_status();write_cmd1(0xb2);/数据自动写结束void write_data(uchar data)RD_H();CD_L();CE_L();WR_L();PORTB=data;asm(nop);/delay(1);WR_H();CE_H();CD_H();void write_cmd1(uchar cmd)RD_H();CD_H();CE_L();WR_L();PORTB=cmd;asm(nop);/delay(1);/须延时80ns左右WR_H();CE_H();CD_L();/先送参数,再送指令void write_cmd2(uchar data,uchar cmd)check_status();write_data(data);check_status();write_cmd1(cmd);void write_cmd3(uchar data1,uchar data2,uchar cmd)check_status();write_data(data1);check_status();write_data(data2);check_status();write_cmd1(cmd);/#pragma data:codeuchar HZ432=0x00,0xF8,0x3F,0x90,0x12,0x10,0x09,0x20,0x3F,0xFE,0x22,0x02,0x42,0x00,0x3F,0xFC,0x04,0x00,0x07,0xF0,0x0C,0x20,0x0B,0x40,0x10,0xC0,0x63,0x30,0x8C,0x0E,0x30,0x04,/*爱,0*/0x06,0x40,0x38,0x50,0x08,0x48,0x08,0x48,0x08,0x40,0xFF,0xFE,0x08,0x40,0x08,0x48,0x0E,0x28,0x38,0x30,0xC8,0x20,0x08,0x50,0x09,0x92,0x08,0x0A,0x28,0x06,0x10,0x02,/*我,1*/0x01,0x00,0x01,0x00,0x21,0x08,0x3F,0xFC,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,/*中,2*/0x08,0x80,0x0C,0x88,0x10,0x9C,0x30,0xE0,0x53,0x80,0x90,0x84,0x10,0x84,0x10,0x7C,0x11,0x00,0x01,0x00,0x7F,0xFE,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00/*华,3*/;uchar HZ232=0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x7F,0xFC,0x20,0x04,0x00,0x00,/*山,0*/0x02,0x00,0x02,0x00,0x7F,0xFC,0x04,0x00,0x08,0x80,0x08,0x80,0x10,0x80,0x1F,0xF8,0x00,0x80,0x08,0xA0,0x0C,0x90,0x18,0x88,0x10,0x8C,0x22,0x84,0x01,0x80,0x00,0x80,/*东,1*/0x08,0x00,0x0B,0xFE,0x48,0x20,0x48,0x20,0x4B,0xFE,0x4A,0x22,0x4A,0x22,0x4A,0x22,0x4A,0x22,0x52,0x22,0x52,0x2A,0x12,0x24,0x20,0x20,0x40,0x20,0x80,0x20,0x00,0x20,/*师,2*/0x04,0x20,0x04,0x20,0xFF,0xFE,0x04,0x60,0x40,0x00,0x31,0xF8,0x91,0x08,0x61,0x08,0x49,0x08,0x09,0x38,0x11,0x10,0xE1,0x00,0x21,0x04,0x21,0x04,0x20,0xFC,0x20,0x00,/*范,3*/0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x01,0x00,0x02,0x80,0x02,0x80,0x02,0x40,0x04,0x40,0x04,0x20,0x08,0x10,0x10,0x18,0x20,0x0E,0x40,0x04,/*大,4*/0x01,0x08,0x10,0x8C,0x0C,0xC8,0x08,0x90,0x7F,0xFE,0x40,0x04,0x8F,0xE8,0x00,0x40,0x00,0x80,0x7F,0xFE,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x02,0x80,0x01,0x00,/*学,5*/0x10,0x80,0x10,0x80,0x50,0x80,0x51,0xFC,0x7D,0x54,0x52,0x54,0x94,0x94,0x14,0x94,0x19,0x24,0x32,0x24,0xD4,0x44,0x10,0x84,0x11,0x04,0x12,0x04,0x14,0x28,0x00,0x10,/*物,6*/0x00,0x00,0x03,0xFC,0xFA,0x44,0x22,0x44,0x23,0xFC,0x22,0x44,0xFA,0x44,0x23,0xFC,0x22,0x44,0x20,0x40,0x23,0xFC,0x38,0x40,0xC0,0x40,0x00,0x40,0x0F,0xFE,0x00,0x00,/*理,7*/0x00,0x00,0x08,0x00,0x08,0x04,0x0F,0xFE,0x08,0x00,0x08,0x00,0x0F,0xFC,0x00,0x04,0x00,0x04,0x00,0x24,0x7F,0xF4,0x00,0x04,0x00,0x04,0x00,0x48,0x00,0x30,0x00,0x00,/*与,8*/0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x01,0x02,0x01,0x02,0x00,0xFE,0x00,0x00,/*电,9*/0x00,0x00,0x3F,0x

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论