📄 lcd.h
字号:
#ifndef _LCD_12864
#define _LCD_12864
/*****************************预定义**************************************/
#define uchar unsigned char
#define uint unsigned int /***************************12864管脚配置****************************/
#define port P1
#define COL 0x40 //列地址
#define PAGE 0xb8 //行地址
#define START_LINE 0xc0
#define DISP_ON 0x3f
#define DISP_OFF 0x3e
sbit rs=P3^0;
sbit rw=P3^1;
sbit e=P3^2;
sbit cs1=P3^6;
sbit cs2=P3^7;
/********************************************************************************************
* 函数名称:Delay()
* 功 能:延迟时间=a*1ms
* 入口参数:
* 出口参数:无
*********************************************************************************************/
void Delay(uint a)
{
uchar i;
while(a--)
for(i=0;i<125;i++);
}
void delay1(uint t)
{
uint i,j;
for(i=0;i<t;i++)
for(j=0;j<10;j++)
;
}
/********************************************************************************************
* 函数名称:Lcd_Display_On()
* 功 能:LCD显示开
* 入口参数:无
* 出口参数:无
/********************************************************************************************
* 函数名称:Lcd_Set_X(uchar x)
* 功 能:LCD设置X坐标
* 入口参数:x
* 出口参数:无
*********************************************************************************************/
void Lcd_Set_X(uchar x)
{
rs=0;
rw=0;
port=0xb8|x;
e=1;delay1(2);
e=0;
}
/********************************************************************************************
* 函数名称:Lcd_Set_Y(uchar y)
* 功 能:LCD设置Y坐标
* 入口参数:y
* 出口参数:无
*********************************************************************************************/
void Lcd_Set_Y(uchar y)
{
rs=0;
rw=0;
port=0x40|y;
e=1;delay1(2);
e=0;
}
/********************************************************************************************
* 函数名称:Lcd_Set_X_Y(uchar x, uchar y )
* 功 能:LCD设置x y坐标
* 入口参数:x y
* 出口参数:无
*********************************************************************************************/
void Lcd_Set_X_Y(uchar x, uchar y)
{
if( y<64 )
{ cs1=0; cs2=1;Delay(1); Lcd_Set_Y( y ); }
else
{ cs1=1; cs2=0;Delay(1); Lcd_Set_Y( y-64 ); }
Lcd_Set_X( x);
}
/********************************************************************************************
* 函数名称:Lcd_Write_Command()
* 功 能:写指令代码
* 入口参数:无
* 出口参数:无
*********************************************************************************************/
void Lcd_Write_Command(uchar temp)
{
rs=0;
rw=0;
port=temp;
e=1;delay1(2);
e=0;
}
/********************************************************************************************
* 函数名称:Lcd_Write_Byte()
* 功 能:写数据
* 入口参数:无
* 出口参数:无
*********************************************************************************************/
void Lcd_Write_Byte(uchar temp)
{
rs=1;
rw=0;
port=temp;
e=1;delay1(2);
e=0;
}
void Lcd_Character_16X8( bit bit_flag, uchar x, uchar y, uchar code *point )
{
uchar i , j,temp;
temp=y;
if( bit_flag )
{
for( i=0; i<2; i++ )
{
x+=i;
y=temp;
for( j=0;j<8;j++ )
{
Lcd_Set_X_Y( x, y ); y++;
Lcd_Write_Byte( point[ i*8 + j] );
}
}
}
}
/****************************************************************************
* 名称:Lcd_Clear(void)
* 功能:清屏
* 入口参数:无
* 出口参数:无
****************************************************************************/
void Lcd_Clear()
{
uchar j,k;
cs2=1;cs1=0;
for(k=0;k<8;k++)
{
Lcd_Write_Command(PAGE+k);
Lcd_Write_Command(COL); //列地址0
for(j=0;j<64;j++) //列地址自动加一
Lcd_Write_Byte(0x00);
}
cs2=0;cs1=1;
for(k=0;k<8;k++)
{
Lcd_Write_Command(PAGE+k);
Lcd_Write_Command(COL); //列地址0
for(j=0;j<64;j++) //列地址自动加一
Lcd_Write_Byte(0x00);
}
}
/*******************************************************************************************
* 函数名称:Lcd_Initial()
* 功 能:初始化LCD
* 入口参数:无
* 出口参数:无
*********************************************************************************************/
void Lcd_Initial()
{
delay1(100);
cs2=1; cs1=0;
delay1(100);
Lcd_Write_Command(DISP_OFF);
Lcd_Write_Command(PAGE);
Lcd_Write_Command(START_LINE);
Lcd_Write_Command(COL);
Lcd_Write_Command(DISP_ON);
cs2=0; cs1=1;
delay1(100);
Lcd_Write_Command(DISP_OFF);
Lcd_Write_Command(PAGE);
Lcd_Write_Command(START_LINE);
Lcd_Write_Command(COL);
Lcd_Write_Command(DISP_ON);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -