📄 lcd12864.h
字号:
/*********************************************************************/
/********* LCD12864ptg.H C51 driver *************/
/********** Written by WangBiao---20060602-20070207 ****************/
/*********************************************************************/
//--------------------------------------
#define DATAPORT P0 // 数据端口!!!!!!!!!!
sbit RS = P1^2;
sbit RW = P1^3;
sbit Elcd = P1^4;
//-----------------------外部函数----------------------------------------
void Init_Lcd12864(void); //LCD RESET
void ClearAS(void);
//---------------------------------------------------------
void DispChar(unsigned char x,unsigned char y,unsigned char dataW);
void DispString(unsigned char x,unsigned char y,unsigned char *ptr);
void DispChinese(unsigned char x,unsigned char y,unsigned char *ptr);
void DispNumb(unsigned char x,unsigned char y,unsigned int n,unsigned char number_bit);
//-----------------------------------------------------------------------
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//-----------------------------------------------------------------------
//-----------------------内部函数----------------------------------------
void WaitForEnable(void); //忙信号检测
void LcdWrite_C(unsigned char CMD,unsigned char AttribC);//write Control Charactor
void LcdWrite_D(char dataW); //写一个数据
unsigned char LcdRead(void);//read a data from LCD
//-------------------------------------------------------------------------
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//-------------------------------------------------------------------------
#define LCD_BUSY_FLAG 0x80 //用于检查写忙信号
unsigned char code number_code_table[]="0123456789";//for dis table
//-----------------------------------------------------------------------
//----------------------具体子函数---------------------------------------
//-----------------初始化-------------------------------
void Init_Lcd12864(void)
{
LcdWrite_C(0x30,0); //显示模式设置(不测试忙信号)共三次
LcdWrite_C(0x30,1);
LcdWrite_C(0x0c,1);//0x0f->all on,show arrow;0x0c->no arrow
ClearAS();
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
void ClearAS(void)
{
unsigned char i,j;
for(j=0;j<4;j++)
{
for(i=0;i<16;i++) DispChar(i,j,' ');
}
}
//-------------------------------------------------------------------
//----------------------------------------------------------------------------
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//----------------------------------------------------------------------------
//=======================================================//
// 按指定位置显示一个字符 //
//=======================================================//
void DispChar(unsigned char x,unsigned char y,unsigned char dataW)
{
unsigned char temp,t;
LcdWrite_C(0x30,1);//command back
temp=x&0x0f;
t=y>>1;
y&=0x01;
if(temp&0x01)
{ temp=temp>>1;
if(y)temp|=0x10;
temp|=0x80;
if(t)temp|=0x08;
LcdWrite_C(temp,1);
LcdRead();
LcdWrite_D(dataW);
}
else
{ temp=temp>>1;
if(y)temp|=0x10;
temp|=0x80;
if(t)temp|=0x08;
LcdWrite_C(temp,1);
LcdWrite_D(dataW);
}
}
//=======================================================//
// 按指定位置显示一串字符 //
//=======================================================//
void DispString(unsigned char x,unsigned char y,unsigned char *ptr)
{ unsigned char i,len=0;//len=0!!!!!!!!
while (ptr[len]>31){len++;};//取得要显示的个数
for(i=0;i<len;i++)
{
if((i!=0)&&((x+i)%16==0)) y++;
DispChar((x+i)%16,y,*ptr++);
}
}
//=======================================================//
// 按指定位置显示中文字符串(x必须偶对齐取值为0~7) //
//=======================================================//
void DispChinese(unsigned char x,unsigned char y,unsigned char *ptr)
{ unsigned char i,len=0;//len=0!!!!!!!!
while (ptr[len]>31){len++;};//取得要显示的个数
for(i=0;i<len;i++) //DispChar(x*2+i,y,*ptr++);
{
if((i!=0)&&((x+i)%16==0)) y++;
DispChar((x*2+i)%16,y,*ptr++);
}
}
//=======================================================//
// 按指定位置显示一个数字表(可变位BCD码) //
//=======================================================//
//---------------------------------------------------------
void DispNumb(unsigned char x,unsigned char y,unsigned int n,unsigned char number_bit)
{
unsigned char digi[5];
unsigned char i;
digi[0]=n/10000;
digi[1]=n/1000%10;
digi[2]=n/100%10;
digi[3]=n/10%10;
digi[4]=n%10;
for(i=0;i<number_bit;i++) DispChar(x+i,y,number_code_table[(digi[5-number_bit+i])]);
}
//--------------------------------------------------------------------------
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//--------------------------------------------------------------------------
//------------------------------------------------------//
//写控制字符子程序: E=1 RS=0 RW=0
//------------------------------------------------------//
void LcdWrite_C( unsigned char CMD,unsigned char AttribC )
{
if (AttribC) WaitForEnable(); // 检测忙信号?
RS = 0; RW = 0;
DATAPORT =CMD; // 送控制字子程序
Elcd = 1;Elcd = 0; // 操作允许脉冲信号
}
//------------------------------------------------------//
//当前位置写字符子程序: E =1 RS=1 RW=0
//------------------------------------------------------//
void LcdWrite_D( char dataW )
{
WaitForEnable(); // 检测忙信号
RS = 1; RW = 0;
DATAPORT = dataW;
Elcd = 1;Elcd = 0; // 操作允许脉冲信号
}
//------------------------------------------------------//
//读模块子程序:E=1 RS=1 RW=1
//------------------------------------------------------//
unsigned char LcdRead(void)
{
unsigned char dataW;
WaitForEnable(); // 检测忙信号
RS = 1; RW = 1;
Elcd = 1;
dataW=DATAPORT;
Elcd = 0;// 操作允许脉冲信号
return dataW;
}
//------------------------------------------------------//
//正常读写操作之前必须检测LCD控制器状态: CS=1 RS=0 RW=1
//DB7: 0 LCD控制器空闲; 1 LCD控制器忙
//------------------------------------------------------//
void WaitForEnable( void )
{
DATAPORT = 0xff;
RS =0; RW = 1; Elcd = 1;
while( DATAPORT & LCD_BUSY_FLAG );
Elcd = 0;
}
//-------------------------------------------------------------------
//###################################################################
//-------------------------------------------------------------------
//--------------------------------------------------------------------------
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//--------------------------------------------------------------------------
//-------------------End LCD12864.H-----------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -