📄 lcd1602func.c
字号:
/*******************************************************************
**函数功能:LCD的驱动函数 **
**创建人:xingyuegu **
**创建日期:2006-7-12 **
**版本:1.0 **
**修改日期:2006-10-30 **
**版本:2.0 **
*******************************************************************/
#include "lcd1602.h"
/*************************************************************
**功能:延时1.64ms **
**参数:无 **
*************************************************************/
void delay1_64ms(void)
{
uchar i;
for(i = 0;i < 250;i++)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
/*************************************************************
**功能:延时40us **
**参数:无 **
*************************************************************/
void delay40us(void)
{
uchar i;
for(i = 0;i < 20;i++)
{
;
}
}
/*************************************************************
**功能:判断LCD忙 **
**参数:无 **
*************************************************************/
unsigned char Lcd_Wait(void)
{
while(1)
{
DBPort=0xff;
LcdEn=0;
_nop_();
LcdRs=0;
_nop_();
_nop_();
LcdRw=1;
_nop_();
_nop_();
LcdEn=1;
_nop_();
_nop_();
_nop_();
_nop_();
if((DBPort&0x80)==0)
{
break;
}
LcdEn=0;
}
//delay40us();
return DBPort;
}
/**************************************************************
**功能:写LCD函数 **
**参数:style为写命令/数据,0-命令,1-数据;input为写入的8位 **
** 命令/数据 **
**************************************************************/
void Lcd_Write(bit style,unsigned char input)
{
LcdEn=0;
_nop_();
_nop_();
LcdRs=style;
_nop_();
_nop_();
LcdRw=0;
DBPort=input;
_nop_();
_nop_();
LcdEn=1;
_nop_();
_nop_();
LcdEn=0;
_nop_();
Lcd_Wait();
}
/****************************************************************
**功能:LCD清屏函数 **
**参数:无 **
****************************************************************/
void ClrScreen(void)
{
Lcd_Write(Lcd_Command,Lcd_Clear_Screen);
delay1_64ms();
}
/****************************************************************
**功能:LCD归位函数 **
**参数:无 **
****************************************************************/
void Screen_home(void)
{
Lcd_Write(Lcd_Command,Lcd_Home);
delay1_64ms();
}
/***************************************************************
**功能:设置显示模式 **
**参数: **
***************************************************************/
void Lcd_SetDisplay(unsigned char DisplayMode)
{
Lcd_Write(Lcd_Command,0x08|DisplayMode);
}
/***************************************************************
**功能:LCD移动设置 **
**参数:取值如下 **
***************************************************************/
void Lcd_Move(unsigned char MoveMode)
{
Lcd_Write(Lcd_Command,0x10|MoveMode);
}
/****************************************************************
**功能:LCD输入设置 **
**参数:取值如下 **
****************************************************************/
//
void Lcd_SetInput(unsigned char InputMode)
{
Lcd_Write(Lcd_Command,0x04|InputMode);
}
/****************************************************************
**功能:LCD初始化 **
**参数:取值如下 **
****************************************************************/
void Lcd_Init(void)
{
delay1_64ms();
Lcd_Write(Lcd_Command,0x38); //8位数据端口,2行显示,5*7点阵
Lcd_Write(Lcd_Command,0x38);
Lcd_Write(Lcd_Command,0x38);
Lcd_SetDisplay(Lcd_Display_On|Lcd_Cursor|Lcd_Flash); //开启显示, 无光标
//Lcd_Move(Lcd_CursorMove|Lcd_Left);
Lcd_SetInput(Lcd_Ac_Up|Lcd_No_Move); //AC递增, 画面不动_To
}
/****************************************************************
**功能:显示位置设置 **
**参数:x-行;y-列 **
****************************************************************/
void GotoXY(unsigned char x,unsigned char y)
{
if(y==0)
{Lcd_Write(Lcd_Command,0x80|x);
}
if(y==1)
{Lcd_Write(Lcd_Command,0x80|(x+0x40));
}
}
/****************************************************************
**功能:LCD显示函数 **
**参数:str-要显示的字符串指针 **
****************************************************************/
void Print(unsigned char *str)
{
while(*str!='\0')
{
Lcd_Write(Lcd_Data,*str);
str++;
}
}
void print_char(uchar a)
{
Lcd_Write(Lcd_Data,a);
//Lcd_Wait();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -