📄 lcd1624.c
字号:
///////////////////////////////////////////////////////////////////////////////////////////////
// LCD1624
//说明:利用x、y来定义液晶显示的位置
///////////////////////////////////////////////////////////////////////////////////////////////
#include<reg52.h>
#include<absacc.h>
#include <intrins.h>
#include <string.h>
#define Uchar unsigned char
#define Uint unsigned int
xdata unsigned char CW _at_ 0xf9fc;
xdata unsigned char CR _at_ 0xf9fe;
xdata unsigned char DW _at_ 0xf9fd;
xdata unsigned char DR _at_ 0xf9ff;
bit flag;
//////////////////////////////////////////////////////////////////////////
void delay(unsigned int i) //延时
{
while(--i);
}
///////////////////////////////////////////////////////////
unsigned char lc_read(void) //读液晶命令
{unsigned char a;
delay(100);
a=CR;
return(a);
}
////////////////////////////////////////////////////////////
void readbf(void) //读液晶忙
{while(flag)
{flag=(bit)(lc_read()&0x80);
}
}
//////////////////////////////////////////////////////////
void lc_write(unsigned char a) //写液晶命令
{
delay(20);
CW=a;
delay(20);
}
//////////////////////////////////////////////////////////
void ld_write(unsigned char a) //写液晶数据
{
delay(20);
DW=a;
delay(20);
}
//////////////////////////////////////////////////////////////
void inttilcs(void) //液晶初始化
{ readbf();
lc_write(0x38);
delay(500);
readbf();
lc_write(0x01); //清除、复位
readbf();
delay(500);
lc_write(0x0c);
readbf();
delay(500);
lc_write(0x06);
delay(500);
}
//////////////////////////////////////////////////////////////////////////
extern void LocateXY( char posx,char posy) //定地址
{
unsigned char temp;
temp = posx & 0xf; //转化为16进制
posy &= 0x03;
switch ( posy)
{
case 0:;
break;
case 1:temp |= 0x40;
break;
default:;
}
temp |= 0x80;
lc_write(temp);
}
////////////////////////////////////////////////////////////////////////////
extern void DispOneChar(unsigned char x,unsigned char y,unsigned char Wdata) //显示一位
{ readbf();
LocateXY( x, y ); // 定位显示地址
ld_write( Wdata ); // 写字符
}
////////////////////////////////////////////////////////////////////////////
extern void Putstr(unsigned char x,unsigned char y,unsigned char code *ptr) //显示字符串
{
unsigned char i,l=0;
readbf();
while (ptr[l] >31){l++;};
for (i=0;i<l;i++)
{
DispOneChar(x++,y,ptr[i]);
if ( x == 16 )
{ x = 0; y ^= 1;
}
}
}
/////////////////////////////////////////////////////////////////////////////
/*void main()
{
inttilcs();
readbf();
Putstr(5,0,"123456");
while(1);
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -