📄 display.h
字号:
#define NOP asm volatile("nop\n\t"::)
//
// PORTA|=(1<<PA0);//背光初始化
// DDRA|=(1<<PA0);
//#define RS PA1 //RS(CS) 可直接接VCC -- 替代
#define RW PA2 //RW(SID)
#define E PA3 //E(sclk)
//#define RES PA5 //可以去掉
//#define PSB PA4 //可以直接接地 -- 替代
//#define LED PA6 // LED+
//#define CLRBIT_RS PORTA&=~(1<<RS)
#define CLRBIT_RW PORTA&=~(1<<RW)
#define CLRBIT_E PORTA&=~(1<<E)
//#define CLRBIT_PSB PORTA&=~(1<<PSB)
//#define CLRBIT_RES PORTA&=~(1<<RES)
#define CLRBIT_LED PORTA&=~(1<<LED)
//#define SETBIT_RS PORTA|=(1<<RS)
#define SETBIT_RW PORTA|=(1<<RW)
#define SETBIT_E PORTA|=(1<<E)
//#define SETBIT_PSB PORTA|=(1<<PSB)
//#define SETBIT_RES PORTA|=(1<<RES)
#define SETBIT_LED PORTA|=(1<<LED)
void initLCDM(void);
void Send(unsigned char senddata);
void SdCmd(unsigned char scmd);
void SdData(unsigned char DData);
void WriteTextScreen2(const prog_uchar *pstr);
/*************************************
功能:初始化液晶(串口模式)
参数:无
返回值:无
编写人:王志辉
时间:2007年6月13日
*************************************/
void initLCDM(void)
{
DDRA=0xFF;
CLRBIT_E;
CLRBIT_RW;
// CLRBIT_RS;
// CLRBIT_PSB;
// CLRBIT_RES;
// _delay_ms(1);
// SETBIT_RES;
SdCmd(0x20); // 8bit控制界面,基本指令集动作,绘图显示关
SdCmd(0x0C); // display on
SdCmd(0x06); // 进入点设定,游标右移
SdCmd(0x01); // 清除显示
}
/*************************************
功能:串行发送八位数据
参数:要发送的数据
返回值:无
编写人:王志辉
时间:2007年6月13日
*************************************/
void Send(unsigned char senddata)
{
unsigned char i;
for(i=0;i<8;i++)
{
if((senddata)&0x80)
{
SETBIT_RW; //D_OUT=1
}
else
{
CLRBIT_RW;//D_OUT=0;
}
SETBIT_E;//SCK=1;
NOP;
CLRBIT_E;//SCK=0;
senddata<<=1;
}
}
/*************************************
功能:串行发送命令
参数:要发送的命令数据
返回值:无
编写人:王志辉
时间:2007年6月13日
*************************************/
void SdCmd(unsigned char scmd) //send command
{
// SETBIT_RS;
Send(0xf8);//发送五个连续的1
Send(scmd&0xf0);//发送高四位
Send(scmd<<4); //发送低四位
// SETBIT_RS;
_delay_us(20);
}
void SdData(unsigned char DData)
{
// SETBIT_RS;
Send(0xfa);//
Send(DData&0xf0);//发送高四位
Send(DData<<4); //发送低四位
// SETBIT_RS;
_delay_us(20);
}
/*************************************
功能:设定显示一个汉字的行号和列号
参数:行号;列号
返回值:无
编写人:王志辉
时间:2007年6月13日
*************************************/
void DispSetCursor(unsigned char LineNum, unsigned char ColumnNum)
{
unsigned char i=0x00;
switch(LineNum&0x0f) //确定行号
{
case 0x00:
i=0x80;
break;
case 0x01:
i=0x90;
break;
case 0x02:
i=0x88;
break;
case 0x03:
i=0x98;
break;
default :
break;
}
i = (ColumnNum&0x0f)|i; //确定列号
SdCmd(i);
}
/*************************************
功能:写一串数据的显示程序
参数:字符串的首地址
返回值:无
编写人:王志辉
时间:2007年6月13日
*************************************/
void WriteTextRom(const prog_uchar *pstr)
{
uchar i;
uchar j;
SdCmd(0x34); // 8bit I/F, basic command
SdCmd(0x30); // 8bit I/F, basic command, graphic off
for(i=0;i<36;i++) //清空屏幕
{
if (i%16==0) //判断是否换行
{
DispSetCursor(i/16,0); //如换行, 则光标移动到行首
}
SdData(' '); //
}
j=0;
while (pgm_read_byte(pstr) && j<36)
{
if (j%16==0) //判断是否换行
{
DispSetCursor(j/16,0); //如换行, 则光标移动到行首
}
//避免最后一格写半个汉字, 把汉字写到下一行
if (((j+1)%16==0) && pgm_read_byte(pstr)>127 && pgm_read_byte(pstr-1)<128)
{
SdData(' '); //
j++;
}
else
{
SdData(pgm_read_byte(pstr++));
j++;
}
}
}
void write_char(unsigned char LineNum, unsigned char ColumnNum,char *data,uchar size)
{ uchar a;
DispSetCursor(LineNum,ColumnNum);
_delay_ms(1);
for(a=0;a<size;a++)
SdData(*(data+a));
}
void write_charRom(unsigned char LineNum, unsigned char ColumnNum,const prog_uchar *pstr,uchar size)
{ uchar a;
DispSetCursor(LineNum,ColumnNum);
_delay_ms(1);
for(a=0;a<size;a++)
SdData(pgm_read_byte(pstr+a));
}
void write_one_char(unsigned char LineNum, unsigned char ColumnNum,char data)
{ uchar a;
DispSetCursor(LineNum,ColumnNum);
_delay_ms(1);
SdData(data);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -