📄 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显示开
* 入口参数:无
* 出口参数:无
*********************************************************************************************/
void Lcd_Display_On()
{
rs=0;
rw=0;
port=0x3f;
e=1;delay1(2);
e=0;
}
/********************************************************************************************
* 函数名称:Lcd_Display_Off()
* 功 能:LCD显示关
* 入口参数:无
* 出口参数:无
*********************************************************************************************/
void Lcd_Display_Off()
{
rs=0;
rw=0;
port=0x3e;
e=1;delay1(2);
e=0;
}
/********************************************************************************************
* 函数名称: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;
}
/****************************************************************************
*名称:Lcd_Character_16X8( bit bit_flag, uchar x, uchar y, uchar code *point )
*功能:显示16X8字符(字母)
*入口参数:
*出口参数:
*说明:bit_flag = 1 正常显示 bit_flag = 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] );
}
}
}
else
{
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)
* 功能:清屏
* 入口参数:无
* 出口参数:无
****************************************************************************/
/*******************************************************************************************
* 函数名称: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);
}
/*******************************************************************************
* 名称: Lcd_Temperature( uchar * temperture )
* 功能: 显示温度
* 入口参数: 温度
* 出口参数: 无
*********************************************************************************/
void Lcd_Temperture( uint temperature )
{
uchar a,b,c;
a=temperature/100;
b=temperature/10-a*10;
c=temperature-a*100-b*10;
Lcd_Character_16X8( 1, 6, 120, temperture_logo[2] ); // C
Lcd_Character_16X8( 1, 6, 108, temperture_logo[1] ); // °
Lcd_Character_16X8( 1, 6, 96, letter_logo[c] ); // 小数位
Lcd_Character_16X8( 1, 6, 88, temperture_logo[0] ); // .
Lcd_Character_16X8( 1, 6, 80, letter_logo[ b ] ); //个位
Lcd_Character_16X8( 1, 6, 72, letter_logo[ a ] ); //十位
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -