找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2968|回复: 11
打印 上一主题 下一主题
收起左侧

刚刚接触stm32,有没有大佬帮我看一下程序 LCD1602不显示

[复制链接]
回帖奖励 9 黑币 回复本帖可获得 3 黑币奖励! 每人限 1 次(中奖概率 60%)
跳转到指定楼层
楼主
这个程序的LCD1602引脚D0-D7是接到PB8-PB15吗?   RS  PB5,     RW  PB4 ,      E  PB3这样接对吗
我这样接的为什么不显示

  1. #include "public.h"
  2. #define DATA (GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15)
  3. #define rs (GPIO_Pin_5)
  4. #define rw (GPIO_Pin_4)
  5. #define e (GPIO_Pin_3)
  6. u8 num[]="0123456789";
  7. u8 a[]=" welcome to PZ  ";
  8. u8 b[]=" Beautiful Girl ";
  9. void GPIOINIT()   //¶Ë¿Ú³õʼ»¯
  10. {
  11. GPIO_InitTypeDef GPIO_InitStructure;
  12. GPIO_InitStructure.GPIO_Pin=DATA|rs|rw|e;
  13. GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  14. GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  15. GPIO_Init(GPIOB,&GPIO_InitStructure);
  16. // GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable,ENABLE);//°Ñµ÷ÊÔÉèÖÃÆÕͨIO¿Ú
  17. }
  18. void RCCINIT() //ϵͳ³õʼ»¯
  19. {
  20. SystemInit();
  21. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
  22.     //RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
  23. //Èç¹û²»¼ÓÕâÌõÓï¾ä³ÌÐòÏÔʾ¾Í»á³ö´í£¬¼´Ã»Óдò¿ª¶Ë¿Ú¸´Óù¦ÄܵÄʱÖÓÅäÖÃ
  24. }
  25. u8 readbusy() //æÐźżì²â
  26. {  
  27. u8 f;
  28. GPIO_ResetBits(GPIOB,rs);  
  29. GPIO_SetBits(GPIOB,rw);
  30. GPIO_SetBits(GPIOB,e);
  31. f=((GPIO_ReadInputData(GPIOB)&0X8000));
  32. delayms(10);
  33. GPIO_ResetBits(GPIOB,e);
  34. return f;  
  35. }
  36. void lcdwrc(u8 c)   //д°ËλÊý¾Ý
  37. {
  38. while(readbusy());
  39. GPIO_ResetBits(GPIOB,rs);  
  40. GPIO_ResetBits(GPIOB,rw);
  41. GPIO_ResetBits(GPIOB,e);
  42. delayms(1);
  43. GPIOB->BSRR = c<<8 & 0xf000;  //½«Êý¾ÝË͵½P0¿Ú
  44.     GPIOB->BRR = ((~c)<<8) & 0xf000;
  45. delayms(1);
  46. GPIO_SetBits(GPIOB,e);
  47. delayms(1);
  48. GPIO_ResetBits(GPIOB,e);
  49. delayms(1);
  50. }
  51. void lcdwrc4bit(long c)    //д8λÊý¾Ý,ͨ¹ý4¸öÒý½Å
  52. {
  53. while(readbusy());
  54. GPIO_ResetBits(GPIOB,rs);  
  55. GPIO_ResetBits(GPIOB,rw);
  56. GPIO_ResetBits(GPIOB,e);
  57. delayms(1);
  58. GPIOB->BSRR = c<<8 & 0xf000;  //½«Êý¾ÝË͵½P0¿Ú
  59.     GPIOB->BRR = ((~c)<<8) & 0xf000;
  60. delayms(1);
  61. GPIO_SetBits(GPIOB,e);
  62. delayms(1);
  63. GPIO_ResetBits(GPIOB,e);
  64. delayms(1);
  65. GPIOB->BSRR = c<<12 & 0xf000;  //½«Êý¾ÝË͵½P0¿Ú
  66.     GPIOB->BRR = ((~c)<<12) & 0xf000;
  67. delayms(1);
  68. GPIO_SetBits(GPIOB,e);
  69. delayms(1);
  70. GPIO_ResetBits(GPIOB,e);
  71. delayms(1);
  72. }
  73. void lcdwrd(long dat)   //¶Á°ËλÊý¾Ýͨ¹ý4¸öÒý½Å
  74. {
  75. while(readbusy());  
  76. GPIO_SetBits(GPIOB,rs);  
  77. GPIO_ResetBits(GPIOB,rw);
  78. GPIO_ResetBits(GPIOB,e);
  79. delayms(1);
  80. GPIOB->BSRR = dat<<8 & 0xf000;  //½«Êý¾ÝË͵½P0¿Ú
  81.     GPIOB->BRR = ((~dat)<<8) & 0xf000;
  82. delayms(1);
  83. GPIO_SetBits(GPIOB,e);
  84. delayms(1);
  85. GPIO_ResetBits(GPIOB,e);
  86. delayms(1);
  87. GPIOB->BSRR = dat<<12 & 0xf000;  //½«Êý¾ÝË͵½P0¿Ú
  88.     GPIOB->BRR = ((~dat)<<12) & 0xf000;
  89. delayms(1);
  90. GPIO_SetBits(GPIOB,e);
  91. delayms(1);
  92. GPIO_ResetBits(GPIOB,e);
  93. delayms(1);
  94. GPIO_ResetBits(GPIOB,rs);
  95. }
  96. void lcdinit()      //LCD³õʼ»¯
  97. {
  98. delayms(15);
  99. lcdwrc4bit(0x32);
  100. delayms(5);
  101. lcdwrc4bit(0x28);
  102. delayms(5);
  103. lcdwrc4bit(0x08);
  104. delayms(5);
  105. lcdwrc4bit(0x01);
  106. delayms(5);
  107. lcdwrc4bit(0x06);
  108. delayms(5);
  109. lcdwrc4bit(0x0c);
  110. delayms(5);
  111. }
  112. void display()    //ÏÔʾ
  113. {
  114. u8 i;
  115. lcdwrc4bit(0x00+0x80);
  116. for(i=0;i<16;i++)
  117. {
  118.   lcdwrd(a[i]);
  119. }
  120. lcdwrc4bit(0x40+0x80);
  121. for(i=0;i<16;i++)
  122. {
  123.   lcdwrd(b[i]);
  124. }
  125. }
  126. int main()
  127. {

  128. RCCINIT();   //  ÏµÍ³Ê±ÖÓ³õʼ»¯
  129. GPIOINIT();   //  ¶Ë¿Ú³õʼ»¯
  130. lcdinit(); //   Òº¾§ÏÔʾ³õʼ»¯
  131. while(1)
  132. {
  133.   display();   
  134. }
  135. }
复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:295783 发表于 2018-4-21 15:01 | 只看该作者
有人看见吗
回复

使用道具 举报

板凳
ID:295783 发表于 2018-4-21 15:03 | 只看该作者
顶一下
回复

使用道具 举报

地板
ID:150276 发表于 2018-4-22 17:27 | 只看该作者
LCD1602要5v供电,stm32是3.3v.你确定电平转换正确吗?
回复

使用道具 举报

5#
ID:295783 发表于 2018-4-23 08:25 | 只看该作者
51在路上 发表于 2018-4-22 17:27
LCD1602要5v供电,stm32是3.3v.你确定电平转换正确吗?

32我用的是上面带的USB电源,1602用的是5v
回复

使用道具 举报

6#
ID:295783 发表于 2018-4-23 08:25 | 只看该作者
51在路上 发表于 2018-4-22 17:27
LCD1602要5v供电,stm32是3.3v.你确定电平转换正确吗?

我上面那样接线对吗
回复

使用道具 举报

7#
ID:314258 发表于 2018-4-23 10:22 | 只看该作者
GPIOB->BSRR = c<<8 & 0xf000;
===>GPIOB->BSRR = c<<8 & 0xff00;
高8位
回复

使用道具 举报

8#
ID:314301 发表于 2018-4-23 10:59 | 只看该作者
查一下1602的显示方式,找好每一个点的显示再进行传输
回复

使用道具 举报

9#
ID:295783 发表于 2018-4-23 12:55 | 只看该作者
PC7275 发表于 2018-4-23 10:59
查一下1602的显示方式,找好每一个点的显示再进行传输

你觉得我连这个都不会吗??? 老铁!!!
回复

使用道具 举报

10#
ID:699194 发表于 2020-3-29 21:23 | 只看该作者
程序新手 发表于 2018-4-23 08:25
32我用的是上面带的USB电源,1602用的是5v

你这样接电源,都没有共GND给它,肯定不行的啊
回复

使用道具 举报

11#
ID:592807 发表于 2020-3-30 08:40 | 只看该作者
初始化包括io口初始化和指令初始化,你有没有使用指令对LCD初始化

(C.png (135.94 KB, 下载次数: 27)

uc1617s指令

uc1617s指令
回复

使用道具 举报

12#
ID:707815 发表于 2020-3-31 10:42 | 只看该作者
泥都知道打点了,那就应该知道取模呀,我没有看到你取得模,打点函数,根据字模打点,而且,打点的字模大小跟取模大小要一致,完成后,在进行打单个字符,再根据打单个字符,打印字符串,得一步一步的来,你也可以把你那一句话直接取模,直接打点函数打印该字模
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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