找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1123|回复: 1
收起左侧

stm32单片机+HD44780 LCD1602可移植程序

[复制链接]
ID:679189 发表于 2022-5-3 00:34 | 显示全部楼层 |阅读模式
单片机源程序如下:
  1. #include "sys.h"
  2. #include "delay.h"
  3. #include "lcd1602.h"
  4. const u8 table1[] = "Hello Everyone!";
  5. const u8 table2[] = "Welcome to hear!";
  6. /////////////////////////////////////////////////////////
  7. //本程序只供学习使用,未经作者许可,不得用于其它任何用途
  8. //LCD1602液晶显示测试
  9. //液晶控制芯片HD44780及兼容芯片
  10. //驱动方式:并口驱动
  11. //作者;jia
  12. //创建日期:2016年3月19日
  13. //部分程序引用@正点原子
  14. //对此程序如有疑问或建议
  15. /////////////////////////////////////////////////////////

  16. u8 i;

  17. int main(void)
  18. {        
  19.         delay_init();
  20.         lcd1602_init();
  21.         while(1)
  22.         {
  23. //                lcd1602_write_byte(0x01,write_cmd);
  24.                 lcd1602_write_byte(0x80+0x10,write_cmd);
  25.                 for(i=0;i<15;i++)
  26.                 {
  27.                         lcd1602_write_byte(table1[i],write_dat);
  28.                         delay_ms(20);
  29.                 }

  30.                 lcd1602_write_byte(0x80+0x50,write_cmd);//必须用写命令来指定在GRAM哪个地址上写内容
  31.                 for(i=0;i<16;i++)
  32.                 {
  33.                         lcd1602_write_byte(table2[i],write_dat);
  34.                         delay_ms(20);
  35.                 }
  36.                
  37.                 for(i=0;i<16;i++)
  38.                 {
  39.                                 lcd1602_write_byte(0x18,write_cmd);
  40.                                 delay_ms(500);
  41.                 }               
  42.                 while(1);
  43.         }
  44. }
复制代码

  1. #include "lcd1602.h"
  2. #include "delay.h"
  3. /////////////////////////////////////////////////////////
  4. //本程序只供学习使用,未经作者许可,不得用于其它任何用途
  5. //LCD1602液晶显示测试
  6. //液晶控制芯片HD44780及兼容芯片
  7. //驱动方式:并口驱动
  8. //作者;jia
  9. //创建日期:2016年3月19日
  10. //部分程序引用@正点原子
  11. //对此程序如有疑问或建议
  12. /////////////////////////////////////////////////////////

  13. //mode:0 写命令 1 写数据
  14. //dat 写入液晶数据口的数据
  15. void lcd1602_write_byte(u8 dat,u8 mode)
  16. {
  17. //        GPIO_Write(GPIOB,dat<<8); //ok
  18.         lcd1602_port_dat(dat)       //ok
  19.         lcd1602_rs = mode;
  20. //        lcd1602_en = 0;
  21. //        delay_ms(10);
  22.         lcd1602_en = 1;
  23.         delay_ms(10);
  24.         lcd1602_en = 0;
  25. }

  26. //LCD1602初始化函数
  27. void lcd1602_init(void)
  28. {
  29.         GPIO_InitTypeDef GPIO_InitStruct;
  30.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
  31.         
  32.         GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
  33.         GPIO_InitStruct.GPIO_Pin=GPIO_Pin_All;
  34.         GPIO_InitStruct.GPIO_Speed=GPIO_Speed_10MHz;
  35.         GPIO_Init(GPIOB, &GPIO_InitStruct);
  36.         GPIO_Write(GPIOB, 0XFF);
  37.                
  38.         lcd1602_write_byte(0x38,write_cmd);//16*2显示,5*7点阵,8位数据接口
  39. //        delay_ms(100);
  40.         lcd1602_write_byte(0x0f,write_cmd);//开显示,开光标,光标闪烁
  41. //delay_ms(100);
  42.         lcd1602_write_byte(0x06,write_cmd);//字符指针加1,光标加1;写一个字符整屏不移动
  43. //delay_ms(100);
  44.         lcd1602_write_byte(0x01,write_cmd);//清屏

  45. }
复制代码

Keil代码下载: 库函数-LCD1602.7z (176.83 KB, 下载次数: 16)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:573477 发表于 2022-5-10 17:48 | 显示全部楼层
给了一堆不能用的代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表