📄 lcd12864.h
字号:
//12864串口C51程序
#ifndef _lcd12864.h_
#define _lcd12864.h_
#define uint unsigned int
#define uchar unsigned char
#define CMDOUT DDRA|=0XF0 //PA口低四位设置为输出
#define DADAIN DDRA&=0XDF //PA1设置为输入
#define DAtAPORt PORTA|=0X20 //PA1加上拉
#define MCUData PINA
#define LCD_CS_H PORTA|=BIT(4) //PA4高电平
#define LCD_CS_L PORTA&=~BIT(4) //PA4低电平
#define LCD_SID_H PORTA|=BIT(5) //PA5高电平
#define LCD_SID_L PORTA&=~BIT(5) //PA5低电平
#define LCD_CLK_H PORTA|=BIT(6) //PA6高电平
#define LCD_CLK_L PORTA&=~BIT(6) //PA6低电平
#define LCD_PSB_H PORTA|=BIT(7) //PA7高电平
#define LCD_PSB_L PORTA&=~BIT(7) //PA7低电平
/*******************************************
函数名称:delay
功 能:延时ms的时间
参 数:n-延时时间
返回值 :无
********************************************/
void delay(unsigned int n)
{
unsigned int i;
for(i=0; i<n; i++);
}
/*******************************************
函数名称:SendByte
功 能:串行发送一字节数据
参 数:dat-发送的数据
返回值 :无
********************************************/
void SendByte(unsigned char dat)
{
unsigned char i;
CMDOUT;
for(i=0;i<8;i++)
{
LCD_CLK_L;
if(dat&0x80)
LCD_SID_H;
else
LCD_SID_L;
LCD_CLK_H;
dat=dat<<1;
}
}
/*******************************************
函数名称:ReceieveByte
功 能:串行接收一字节数据
参 数:无
返回值 :接受的数据
********************************************/
unsigned char ReceieveByte(void)
{
unsigned char i,d1,d2;
CMDOUT;
DAtAPORt;
DADAIN;
for(i=0;i<8;i++)
{
LCD_CLK_L;
delay(100);
LCD_CLK_H;
if(MCUData)
d1++;
d1=d1<<1;
}
for(i=0;i<8;i++)
{
LCD_CLK_L;
delay(100);
LCD_CLK_H;
if(MCUData)
d2++;
d2=d2<<1;
}
return (d1&0xF0+d2&0x0F);
}
/*******************************************
函数名称:CheckBusy
功 能:判断忙函数
参 数:无
返回值 :无
********************************************/
void CheckBusy( void )
{
do SendByte(0xfc); //11111,RW(1),RS(0),0
while(0x80&ReceieveByte()); //BF(.7)=1 Busy
CMDOUT;
}
/*******************************************
函数名称:SendCMD
功 能:写控制命令
参 数:dat-写命令的数据
返回值 :无
********************************************/
void write_com(unsigned char dat)
{
LCD_CS_H;
CheckBusy();
SendByte(0xF8);//11111,RW=0,RS=0,0 同步标志
SendByte(dat&0xF0);//高四位
SendByte((dat&0x0F)<<4);//低四位
LCD_CS_L;
}
/*******************************************
函数名称:SendDat
功 能:写显示数据或单字节字符
参 数:dat-写数据
返回值 :无
********************************************/
void write_data(unsigned char dat)
{
LCD_CS_H;
CheckBusy();
SendByte(0xFA);//11111,RW=0,RS=1,0
SendByte(dat&0xF0);//高四位
SendByte((dat&0x0F)<<4);//低四位
LCD_CS_L;
}
/******************************************
函数名称:Write_string
功 能:向液晶写显示字符串
参 数:无
返回值 :无
******************************************/
void write_string(unsigned char add, unsigned char * str)
{
unsigned char i = 0;
write_com(0x30); //8BitMCU,基本指令集合
write_com(add); //起始位置
while(str[i] != '\0')
{
write_data(str[i++]);
}
}
/*******************************************
函数名称:putBMP
功 能:显示图片
参 数:*puts显示图片
返回值 :无
********************************************/
void putBMP(unsigned char *puts)
{
unsigned int x=0;
unsigned char i,j;
write_com(0x34); //8Bit扩充指令集,即使是36H也要写两次
write_com(0x36); //绘图ON,基本指令集里面36H不能开绘图
for(i=0;i<32;i++) //12864实际为256x32
{
write_com(0x80|i); //行位置
write_com(0x80); //列位置
for(j=0;j<32;j++) //256/8=32 byte
{ //列位置每行自动增加
write_data(puts[x]);
x++;
}
}
}
/*******************************************
函数名称:lcdInit
功 能:液晶初始化
参 数:无
返回值 :无
********************************************/
void lcd__Init( void )
{
LCD_PSB_L ;
LCD_CS_H ;
delay(100);
write_com(0x30); //功能设置,一次送8位数据,基本指令集
write_com(0x03); //AC归0,不改变DDRAM内容
write_com(0x0C); //0000,1100 整体显示,游标off,游标位置off
write_com(0x01); //0000,0001 清DDRAM
write_com(0x02); //0000,0010 DDRAM地址归位
write_com(0x80); //1000,0000 设定DDRAM 7位地址000,0000到地址计数器AC
write_com(0x06); //写入时,游标右移动
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -