LCD12864 驅(qū)動(dòng) ,采用串行方式
/********************************************
file&: lcd.h
Description: LCD12864 驅(qū)動(dòng) ,采用串行方式,
Author:kassey@126.comJuly,22th,2005
********************************************/
#i nclude
#i nclude
sbit SCLK =P1^3 //E
sbit SID =P1^4; //RW
sbit RST =P1^2; // low active 可以不用,也就是說,只用兩條線和LCD通信
#define ROW1 0x80
#define ROW2 0x90
#define ROW3 0x88
#define ROW4 0x98
unsigned char code AC_TABLE[]={
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, //第一行漢字位置
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, //第二行漢字位置
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, //第三行漢字位置
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, //第四行漢字位置
};
/*****************************************
Fucntion: delay10US(char x)
Description: delay for 10 us
Parameter: x
Author:kassey@126.com
Date: July,7th,2005
*****************************************/
void delay10US(uchar x)
{
uchar k;
for(k=0;k
}
/*****************************************
Fucntion: delay1MS(char x)
Description: delay for 10 us
Parameter: x delay for 1MS
Author:kassey@126.com
Date: July,7th,2005
*****************************************/
void delay1MS(uchar x)
{
uchar k,j;
x=x<<1;
for(k=0;k
}
void SendByteLCD(uchar WLCDData)
{
uchar i;
for(i=0;i<8;i++)
{
if((WLCDData<else SID=0;
SCLK=0;
SCLK=1
}
}
SPIWR(uchar Wdata,uchar RS)
{
SendByteLCD(0xf8+(RS<<1));
SendByteLCD(Wdata&0xf0);
SendByteLCD((Wdata<<4)&0xf0);
}
void SendCMD(uchar CMD)
{
SPIWR(CMD,0);
delay10US(90);//8155來模擬串行通信,所以,加上8155的延時(shí),
}
void SendData(uchar Data)
{
SPIWR(Data,1);
}
void LCDInit()
{
RST=0;
delay1MS(50);
RST=1;
SendCMD(0x30);//功能設(shè)置,一次送8位數(shù)據(jù),基本指令集
SendCMD(0x0C);//0000,1100 整體顯示,游標(biāo)off,游標(biāo)位置off
SendCMD(0x01);//0000,0001 清DDRAM
SendCMD(0x02);//0000,0010 DDRAM地址歸位
SendCMD(0x80);//1000,0000 設(shè)定DDRAM 7位地址000,0000到地址計(jì)數(shù)器AC//
SendCMD(0x04);//點(diǎn)設(shè)定,顯示字符/光標(biāo)從左到右移位,DDRAM地址加 一//
SendCMD(0x0C);//顯示設(shè)定,開顯示,顯示光標(biāo),當(dāng)前顯示位反白閃動(dòng)
}
/*****************************
清文本區(qū)
*****************************/
void LcmClearTXT( void )
{
unsigned char i;
SendCMD(0x30); //8BitMCU,基本指令集合
SendCMD(0x80); //AC歸起始位
for(i=0;i<64;i++)
SendData(0x20);
}
/*****************************
發(fā)送字符串
*****************************/
void PutStr(unsigned char row,unsigned char col,unsigned char *puts)
{
SendCMD(0x30); //8BitMCU,基本指令集合
SendCMD(AC_TABLE[8*row+col]); //起始位置
while(*puts != '