標題: stm32單片機+HD44780 LCD1602可移植程序 [打印本頁]

作者: JN0717    時間: 2022-5-3 00:34
標題: stm32單片機+HD44780 LCD1602可移植程序
單片機源程序如下:
  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. //創(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哪個地址上寫內容
  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. //創(chuàng)建日期:2016年3月19日
  10. //部分程序引用@正點原子
  11. //對此程序如有疑問或建議
  12. /////////////////////////////////////////////////////////

  13. //mode:0 寫命令 1 寫數(shù)據
  14. //dat 寫入液晶數(shù)據口的數(shù)據
  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ù)據接口
  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代碼下載: 庫函數(shù)-LCD1602.7z (176.83 KB, 下載次數(shù): 18)

作者: mj2019    時間: 2022-5-10 17:48
給了一堆不能用的代碼




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1