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;// – –
今天的文章lcd开机流程图_LCD1602程序代码及显示流程图.doc分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/29112.html