找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1920|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

stm32單片機+HD44780 LCD1602可移植程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:679189 發(fā)表于 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. //本程序只供學(xué)習(xí)使用,未經(jīng)作者許可,不得用于其它任何用途
  8. //LCD1602液晶顯示測試
  9. //液晶控制芯片HD44780及兼容芯片
  10. //驅(qū)動方式:并口驅(qū)動
  11. //作者;jia
  12. //創(chuàng)建日期: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哪個地址上寫內(nèi)容
  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. }
復(fù)制代碼

  1. #include "lcd1602.h"
  2. #include "delay.h"
  3. /////////////////////////////////////////////////////////
  4. //本程序只供學(xué)習(xí)使用,未經(jīng)作者許可,不得用于其它任何用途
  5. //LCD1602液晶顯示測試
  6. //液晶控制芯片HD44780及兼容芯片
  7. //驅(qū)動方式:并口驅(qū)動
  8. //作者;jia
  9. //創(chuàng)建日期:2016年3月19日
  10. //部分程序引用@正點原子
  11. //對此程序如有疑問或建議
  12. /////////////////////////////////////////////////////////

  13. //mode:0 寫命令 1 寫數(shù)據(jù)
  14. //dat 寫入液晶數(shù)據(jù)口的數(shù)據(jù)
  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初始化函數(shù)
  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位數(shù)據(jù)接口
  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. }
復(fù)制代碼

Keil代碼下載: 庫函數(shù)-LCD1602.7z (176.83 KB, 下載次數(shù): 18)

評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:573477 發(fā)表于 2022-5-10 17:48 | 只看該作者
給了一堆不能用的代碼
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表