📄 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++);
}
/********************************************************************************************
* 函数名称: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; Lcd_Set_Y( y ); }
else
{ cs1=1; cs2=0; 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_Character_16X16( bit bit_flag, uchar x, uchar y, uchar code *point )
* 功能:显示16*16字符(汉字)
* 入口参数:x y data
* 出口参数:无
*说明:bit_flag = 1 正常显示 bit_flag = 0 黑白反相显示
****************************************************************************/
void Lcd_Character_16X16( 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<16;j++ )
{
Lcd_Set_X_Y( x, y ); y++;
Lcd_Write_Byte( point[ i*16 + j] );
}
}
}
else
{
for( i = 0; i<2; i++ )
{
x += i;
y = temp;
for( j = 0; j < 16; j++ )
{
Lcd_Set_X_Y( x, y ); y++;
Lcd_Write_Byte( ~ point[ i * 16 + 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;
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_Time(uchar * clock_time )
* 功能:显示时间
* 入口参数:无
* 出口参数:无
* 说明 : 时间数组 BCD 码形式
****************************************************************************/
void Lcd_Time(uchar * clock_time )
{
uchar i=0;
//显示 "hour时min分sec秒"
i= * clock_time >> 4;
Lcd_Character_16X8( 1, 2, 80, letter_logo[i]); //显示 sec的高位
i= * clock_time & 0x0f;
Lcd_Character_16X8( 1, 2, 88, letter_logo[i]); //显示 sec的低位
Lcd_Character_16X16( 1, 2, 96 , time_logo[1]); //显示 秒
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -