简单菜单系统 Proteus pg12864 液晶
//系统的大循环.
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;i
}
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;//没有键按下返回0
}
unsigned 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&=~(1<1)
#define RD_H() PORTD|=(1<1)
#define CE_L() PORTD&=~(1<2)
#define CE_H() PORTD|=(1<2)
#define CD_L() PORTD&=~(1<3)
#define CD_H() PORTD|=(1<3)
#define RST_L() PORTD&=~(1<4)
#define RST_H() PORTD|=(1<4)
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<15;i++)
if(i>=8)
display_HZ(1,i-8,HZ2[i]);
else
display_HZ(0,i,HZ2[i]);
while(1);
//{//调整文本区首地址,可以实现移屏;
////i++;
// write_cmd3(i++,0,0x40);//文本区首地址;
// delay(10000);
//}
}
*/
//#include pg12864.h>
//处在x y处显示汉字hz
void display_HZ(uchar x,uchar y,uchar *hz)////x 0-3 y 0-7
{
uchar i,j=0;
for(i=0;i<16;i++)
{
write_cmd3(((j/2)<4)|(y*2),x,0x24);//地址指针设置..低地址,高地址,命令
write_cmd2(hz[j++],0xc0);
write_cmd2(hz[j++],0xc0);
}
}
//处在x y处显示ch
void display_char(uchar x,uchar y, uchar ch)//x 0-7 y 0-15
{
write_cmd3((((x*2)<4)+y),0x00,0x24);//地址指针位置
write_cmd2(ch-32,0xc0);//t6963c字符表与ASCII差32@@@@@@@@@@@@@@@@
}
void display_string(uchar x,uchar y, uchar *s)
{
uchar i=0;
while(*s)
{
display_char( x, y+(i++),*s);
s++;
if(i>=16)
{
x++;
i=0;
}
}
}
void delay(uint t)
{
uint i,j;
for(i=0;i
}
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 N0
}
void 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 N0
}
菜单系统Proteuspg12864液 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)