📄 lcd.c
字号:
//LCD.c
#include <reg51.h>
#include "time.h"
#include "LCD.h"
#include "serial.h"
/******************************************************************************
函数:LCD_SendData()
功能:主机通过串行总线向LCD发送一个字节的数据
参数:
uchValue:要发送的数据
返回:
******************************************************************************/
void LCD_SendData(unsigned char uchValue)
{
LCD_CS = 1;
Ser_SendByte(0xFA);//11111,01,0 RW=0,RS=1
Ser_SendByte(uchValue & 0xF0);//高四位
Ser_SendByte((uchValue & 0x0F)<<4);//低四位
LCD_CS = 0;
}
/******************************************************************************
函数:LCD_SendCommand()
功能:主机通过串行总线向LCD发送一个字节的控制命令
参数:
uchCmd:要发送的控制命令
返回:
******************************************************************************/
void LCD_SendComand(unsigned char uchCmd)
{
LCD_CS = 1;
Ser_SendByte(0xF8);//11111,00,0 RW=0,RS=0 同步标志
Ser_SendByte(uchCmd & 0xF0);//高四位
Ser_SendByte((uchCmd & 0x0F)<<4);//低四位
LCD_CS = 0;
}
/******************************************************************************
函数:LCD_Init()
功能:LCD初始化:上电、开背光、初始配置
参数:
返回:
******************************************************************************/
void LCD_Init()
{
LCD_CS = 0;
Delay_ms(1); //启动等待,等LCM讲入工作状态
LCD_CS = 1;
LCD_BACKLIGHT = 0;
LCD_SendComand(0x30);//功能设置,一次送8位数据,基本指令集
LCD_SendComand(0x0C);//0000,1100 整体显示,游标off,游标位置off
LCD_SendComand(0x01);//0000,0001 清DDRAM
LCD_SendComand(0x02);//0000,0010 DDRAM地址归位
LCD_SendComand(0x80);//1000,0000 设定DDRAM 7位地址000,0000到地址计数器AC
}
/******************************************************************************
函数:LCD_Display()
功能:控制LCD在指定位置显示指定内容
参数:
uchX_Add:指定位置
uchValue1、uchValue2:显示内容的码
返回:
******************************************************************************/
void LCD_Display(unsigned char uchX_Add,unsigned int uiValue)
{
unsigned char uchValue1,uchValue2;
uchValue1 = (uiValue >> 8) & 0x00ff;
uchValue2 = uiValue & 0x00ff;
LCD_SendComand(uchX_Add);
LCD_SendData(uchValue1);
LCD_SendData(uchValue2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -