大家好,又见面了,我是你们的朋友全栈君。
LCD1602程序代码及显示流程图
LCD1602程序代码及显示流程图
lcd1602显示程序代码
前些天弄了最小系统板后就想着学习1602的显示程序,可惜坛子里的或网上的,都没有简单的1602显示程序,无柰在网上下载了一段经过反复修改测试,终于有了下面一段代码:
// – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
// – – 初始化接口
# define LCD_DB P0 // – – P0 = DB0~DB7
sbit LCD_RS=P2 ; // – – p2.0 = RS
sbit LCD_RW=P2; // – – p2.1 = RW
sbit LCD_E=P2; // – – p2.2 = E
// – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
// – – 定义函数
# define uchar unsigned char
# define uint unsigned int
// – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
// – – 定义子程序函数
void LCD_init(void); // – – 初始化LCD1602函数
void LCD_write_command(uchar command); // – – 向LCD1602写指令函数
void LCD_write_data(uchar dat); // – – 向LCD1602写数据函数
void LCD_set_xy(uchar x,uchar y); // – – 设置LCD1602显示位置 X(0-16),y(1-2)
void LCD_disp_char(uchar x,uchar y,uchar dat); // – – 在LCD1602上显示一个字符
void LCD_disp_string(uchar X,uchar Y,uchar *s); // – – 在LCD1602上显示一个字符串
//void LCD_check_busy(void);//检查忙函数。我没用到此函数,因为通过率极低。
void LCD_delay_10us(uint n); // – – 10微秒的延时子程序
void LCD_delay_50us(uint n); // – – 50微秒的延时子程序
// – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
// – – 初始化LCD1602
void LCD_init(void)
{
LCD_delay_10us(20);
LCD_write_command(0x38); // – – 设置8位格式,2行,5×7
LCD_delay_10us(5);
LCD_write_command(0x0c); // – – 整体显示,关光标,不闪烁
LCD_delay_10us(5);
LCD_write_command(0x06); // – – 设定输入方式,增量不移位
LCD_delay_10us(5);
LCD_write_command(0x01); // – – 清除屏幕显示
LCD_delay_50us(40);
}
//********************************
// – – 向LCD1602写指令
void LCD_write_command(uchar dat)
{
LCD_delay_10us(5);
LCD_RS=0; // – – 指令
LCD_RW=0; // – – 写入
LCD_DB=dat;
LCD_delay_10us(5);
LCD_E=1; // – – 允许
LCD_delay_10us(5);
LCD_E=0;
}
// – – 向LCD1602写数据
void LCD_write_data(uchar dat)
{
LCD_delay_10us(5);
LCD_RS=1;// – –
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/160134.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...