?? 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);
/*************************************
功能:初始化液晶(串口模式)
參數(shù):無
返回值:無
編寫人:王志輝
時間: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控制界面,基本指令集動作,繪圖顯示關(guān)
SdCmd(0x0C); // display on
SdCmd(0x06); // 進入點設(shè)定,游標(biāo)右移
SdCmd(0x01); // 清除顯示
}
/*************************************
功能:串行發(fā)送八位數(shù)據(jù)
參數(shù):要發(fā)送的數(shù)據(jù)
返回值:無
編寫人:王志輝
時間: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;
}
}
/*************************************
功能:串行發(fā)送命令
參數(shù):要發(fā)送的命令數(shù)據(jù)
返回值:無
編寫人:王志輝
時間:2007年6月13日
*************************************/
void SdCmd(unsigned char scmd) //send command
{
// SETBIT_RS;
Send(0xf8);//發(fā)送五個連續(xù)的1
Send(scmd&0xf0);//發(fā)送高四位
Send(scmd<<4); //發(fā)送低四位
// SETBIT_RS;
_delay_us(20);
}
void SdData(unsigned char DData)
{
// SETBIT_RS;
Send(0xfa);//
Send(DData&0xf0);//發(fā)送高四位
Send(DData<<4); //發(fā)送低四位
// SETBIT_RS;
_delay_us(20);
}
/*************************************
功能:設(shè)定顯示一個漢字的行號和列號
參數(shù):行號;列號
返回值:無
編寫人:王志輝
時間: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);
}
/*************************************
功能:寫一串?dāng)?shù)據(jù)的顯示程序
參數(shù):字符串的首地址
返回值:無
編寫人:王志輝
時間: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); //如換行, 則光標(biāo)移動到行首
}
SdData(' '); //
}
j=0;
while (pgm_read_byte(pstr) && j<36)
{
if (j%16==0) //判斷是否換行
{
DispSetCursor(j/16,0); //如換行, 則光標(biāo)移動到行首
}
//避免最后一格寫半個漢字, 把漢字寫到下一行
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);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -