📄 lcd.h
字号:
#ifndef _LCD_12864
#define _LCD_12864
/*****************************预定义**************************************/
#define uchar unsigned char
#define uint unsigned int/***************************12864管脚配置****************************/
#define port P1
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_Display_On()
* 功 能:LCD显示开
* 入口参数:无
* 出口参数:无
*********************************************************************************************/
void Lcd_Display_On()
{
port=0x3f;
rs=0;
rw=0;
e=1;
e=0;
}
/********************************************************************************************
* 函数名称:Lcd_Display_Off()
* 功 能:LCD显示关
* 入口参数:无
* 出口参数:无
*********************************************************************************************/
void Lcd_Display_Off()
{
port=0x3e;
rs=0;
rw=0;
e=1;
e=0;
}
/********************************************************************************************
* 函数名称:Lcd_Set_X(uchar x)
* 功 能:LCD设置X坐标
* 入口参数:x
* 出口参数:无
*********************************************************************************************/
void Lcd_Set_X(uchar x)
{
port=0xb8|x;
rs=0;
rw=0;
e=1;
e=0;
}
/********************************************************************************************
* 函数名称:Lcd_Set_Y(uchar y)
* 功 能:LCD设置Y坐标
* 入口参数:y
* 出口参数:无
*********************************************************************************************/
void Lcd_Set_Y(uchar y)
{
port=0x40|y;
rs=0;
rw=0;
e=1;
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=1; cs2=0; Lcd_Set_Y( y ); }
else
{ cs1=0; cs2=1; Lcd_Set_Y( y-64 ); }
Lcd_Set_X( x);
}
/********************************************************************************************
* 函数名称:Lcd_Write_Command()
* 功 能:写指令代码
* 入口参数:无
* 出口参数:无
*********************************************************************************************/
void Lcd_Write_Command(uchar temp)
{
port=temp;
rs=0;
rw=0;
e=1;
e=0;
}
/********************************************************************************************
* 函数名称:Lcd_Write_Byte()
* 功 能:写数据
* 入口参数:无
* 出口参数:无
*********************************************************************************************/
void Lcd_Write_Byte(uchar temp)
{
port=temp;
rs=1;
rw=0;
e=1;
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 i,j;
cs1=1;cs2=1;
for(i=0;i<8;i++)
{
Lcd_Set_X( i );
Lcd_Set_Y( 0 );
for(j=0;j<64;j++)
Lcd_Write_Byte(0x00);
}
}
/*******************************************************************************************
* 函数名称:Lcd_Initial()
* 功 能:初始化LCD
* 入口参数:无
* 出口参数:无
*********************************************************************************************/
void Lcd_Initial()
{
Lcd_Display_Off();
Lcd_Write_Command(0xb8); //Page_Add
Lcd_Write_Command(0x40); //Col_Add
Lcd_Write_Command(0xc0); //Start_Line
Lcd_Display_On();
Lcd_Clear();
}
/****************************************************************************
* 名称: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[2]); //显示 秒
clock_time ++;
i= * clock_time >> 4;
Lcd_Character_16X8( 1, 2, 48, letter_logo[i]); //显示 min的高位
i= * clock_time & 0x0f;
Lcd_Character_16X8( 1, 2, 56, letter_logo[i]); //显示 min的低位
Lcd_Character_16X16( 1, 2, 64 , time_logo[1]); //显示 分
clock_time ++;
i= * clock_time >> 4;
Lcd_Character_16X8( 1, 2, 16 , letter_logo[i]); //显示 hour的高位
i= * clock_time & 0x0f;
Lcd_Character_16X8( 1, 2, 24 , letter_logo[i]); //显示 hour的低位
Lcd_Character_16X16( 1, 2, 32 , time_logo[0]); //显示 分
}
/****************************************************************************
* 名称:Lcd_Data(uchar * clock_time )
* 功能:显示日期
* 入口参数:无
* 出口参数:无
* 说明 : 时间数组 BCD 码形式
****************************************************************************/
void Lcd_Data(uchar * clock_time )
{
uchar i=0;
clock_time += 3;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -