📄 lcd1602.c
字号:
/***********************************************************
文件名称: lcd1602.c
作 者: 芦达
版 本: 1.0
说 明: LCM函数
修改记录:
***********************************************************/
#include <reg52.h>
#include <lcd1602.h>
#include <delay.h>
char int2charLCD[20];
/***********************************************************
函数名称: write_LCD_command
函数功能: 将命令写入LCM
入口参数:
出口参数:
备 注:
***********************************************************/
void write_LCD_command(unsigned command)
{
LCD_RS=COMMAND;
LCD_ENABLE=ENABLE;
P0=command;
DelayNS(20);
LCD_ENABLE=DISABLE;
P0=0;
}
/***********************************************************
函数名称: write_LCD_data
函数功能: 将数据写入LCM
入口参数:
出口参数:
备 注:
***********************************************************/
void write_LCD_data(unsigned LCDdata)
{
LCD_RS=DATA;
LCD_ENABLE=ENABLE;
P0=LCDdata;
DelayNS(20);
LCD_ENABLE=DISABLE;
P0=0;
}
/***********************************************************
函数名称: init_LCD
函数功能: 初始化LCM
入口参数:
出口参数:
备 注:
***********************************************************/
void init_LCD(void)
{
P0=0;
dula=0;
wela=0;
write_LCD_command(TwoLine_8bit);
write_LCD_command(CURSOR_OFF);
write_LCD_command(CURSOR_RIGHT);
}
/***********************************************************
函数名称: clear_LCD
函数功能: LCM 清屏
入口参数:
出口参数:
备 注:
***********************************************************/
void clear_LCD(void)
{
write_LCD_command(LCD_CLEAR);
write_LCD_command(CURSOR_HOME);
}
/***********************************************************
函数名称: display_LCD
函数功能: LCM显示字符串
入口参数:
出口参数:
备 注:
***********************************************************/
void display_LCD_string(char *p)
{
while (*p)
{
write_LCD_data(*p);
p++;
}
}
/***********************************************************
函数名称: gotoxy
函数功能: 设置位置
入口参数:
出口参数:
备 注:
***********************************************************/
void gotoxy(unsigned x,unsigned y)
{
if (x==1)
write_LCD_command(GOTO_LINE_1+y);
else
write_LCD_command(GOTO_LINE_2+y);
}
/***********************************************************
函数名称: display_LCD_number
函数功能: LCM显示数字
入口参数:
出口参数:
备 注:
***********************************************************/
void display_LCD_number(unsigned long number,unsigned char dotwei)
{ unsigned char x;
unsigned long y=number ;
unsigned char count=0;
if (y==0)
{
write_LCD_data('0');
}
else
{
while (y)
{ x=y%10;
y=y/10;
int2charLCD[count]=x+'0';
count++;
}
while(count<=dotwei)
{
int2charLCD[count]='0';
count++;
}
int2charLCD[count]=0;
for (x=count-1;x<20;x--)
{
if((x+1)==dotwei) write_LCD_data('.');
write_LCD_data(int2charLCD[x]);
}
for(;count<20;count++)
write_LCD_data(' ');
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -