切换到宽版
  • 2920阅读
  • 13回复

[STM]成功点亮隔壁老王家1.5寸LCD屏 [复制链接]

上一主题 下一主题
离线小茅
 

发帖
2290
M币
1597
专家
6
粉丝
36
前几天看到@junyee   的帖子http://bbs.mydigit.cn/read.php?tid=2562208 ,感觉这款屏挺便宜,又是串口屏,就买了10块回来,今天到货,直接开干


首先给大家排坑。
1、引脚定义:从左至右分别是VOUT(电荷泵输出),VDD(电源),CSB(片选信号),VSS(地),A0(低电平写入指令,高电平写入数据),SCLK(SPI总线的时钟线),SDA(SPI总线的数据线),RESB(低电平复位)。
2、根据芯片手册,使用内置电荷泵进行升压需要在VOUT和VSS之间连接一个电容,芯片手册最后面给出的示例用的是1.0uF的电容,可以作为参考。不过我最开始没看这么仔细,焊了个0.47uF的上去,也没出什么问题。
3、淘宝给的资料是ST7558,但是实际上芯片可能只是个ST7545,我最开始的时候没注意,后来发现有几个初始化的指令根本没有作用,后来回来看帖子才发现是芯片搞错了。ST7545比较简单,指令少。
4、这个可能是手机屏,上方有一个状态栏,这个屏在设计的时候为了把状态栏的页放在点阵后面,导致这个屏的行是从下往上数的,所以第一行的地址是0x47,第二行是0x46依此类推。
5、焊盘间距是1.27mm,和SOIC封装的引脚间距是一样的。焊盘大小和转接板上的焊盘是一样的,所以我在焊接的时候是先把转接板的焊盘上锡,然后再把屏焊上去。

我采用了和坛友一样的方法,用转接板引出插针。
对于这样的屏,我会先查找一下有没有可以让屏全亮的指令,比如SSD1306的0xA5,用来检测单片机与屏的通信是否正常。根据芯片手册,只要把初始化代码中的0x0C改成0x09就可以了,全亮的效果如图



然后就是尝试点亮了,因为我有SSD1306的程序,所以移植起来还是比较容易的,在页寻址模式下,只要修改初始化指令,然后把选行的0xB0+n改成0x47-n,把选列的0x00+n改为0x80+n就行了。
成功点亮的效果如图



开源
单片机是STM32F030F4P6
A0接PA6,RESB接PB1,CSB直接接地,硬件SPI是PA5和PA7
里面有自己写的初始化函数,清屏函数,写字函数,可以按行打印字符串。如果想打印变量,可以加stdio.h然后用sprintf
用的LL库,用了硬件SPI,没用中断,还用了TIM3用于产生延时
工程文件
链接:https://pan.baidu.com/s/1Oeznm1mV2z13ij7FMIHsdg 密码:w0qg
因为是用STM32CubeMX创建的,加了一个比较大的库进去,所以直接传网盘了
下面是主要代码
  1. /**
  2.   ******************************************************************************
  3.   * @file           : main.c
  4.   * [url=u.php?uid=650075]@brief[/url]            : Main program body
  5.   ******************************************************************************
  6.   ** This notice applies to any and all portions of this file
  7.   * that are not between comment pairs USER CODE BEGIN and
  8.   * USER CODE END. Other portions of this file, whether
  9.   * inserted by the user or by software development tools
  10.   * are owned by their respective copyright owners.
  11.   *
  12.   * COPYRIGHT(c) 2018 STMicroelectronics
  13.   *
  14.   * Redistribution and use in source and binary forms, with or without modification,
  15.   * are permitted provided that the following conditions are met:
  16.   *   1. Redistributions of source code must retain the above copyright notice,
  17.   *      this list of conditions and the following disclaimer.
  18.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  19.   *      this list of conditions and the following disclaimer in the documentation
  20.   *      and/or other materials provided with the distribution.
  21.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  22.   *      may be used to endorse or promote products derived from this software
  23.   *      without specific prior written permission.
  24.   *
  25.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  29.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35.   *
  36.   ******************************************************************************
  37.   */
  38. /* Includes ------------------------------------------------------------------*/
  39. #include "main.h"
  40. /* USER CODE BEGIN Includes */
  41. /* USER CODE END Includes */
  42. /* Private variables ---------------------------------------------------------*/
  43. /* USER CODE BEGIN PV */
  44. /* Private variables ---------------------------------------------------------*/
  45. const uint8_t ASCII[] =
  46. {
  47. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// ,0
  48. 0x00,0x00,0x70,0xF8,0xF8,0x70,0x00,0x00,0x00,0x00,0x00,0x0D,0x0D,0x00,0x00,0x00,//!,1
  49. 0x00,0x38,0x38,0x00,0x00,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//",2
  50. 0x00,0x20,0xF8,0xF8,0x20,0xF8,0xF8,0x20,0x00,0x02,0x0F,0x0F,0x02,0x0F,0x0F,0x02,//#,3
  51. 0x00,0x30,0x78,0xCE,0x8E,0x18,0x10,0x00,0x00,0x04,0x0C,0x38,0x39,0x0F,0x06,0x00,//$,4
  52. 0x18,0x3C,0x24,0xBC,0xD8,0x60,0x30,0x00,0x00,0x06,0x03,0x0D,0x1E,0x12,0x1E,0x0C,//%,5
  53. 0x00,0xB0,0xF8,0x48,0x78,0x30,0x00,0x00,0x00,0x07,0x0F,0x08,0x09,0x07,0x0F,0x09,//&,6
  54. 0x00,0x00,0x00,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//',7
  55. 0x00,0x00,0xC0,0xF0,0x38,0x08,0x00,0x00,0x00,0x00,0x07,0x1F,0x38,0x20,0x00,0x00,//(,8
  56. 0x00,0x00,0x08,0x38,0xF0,0xC0,0x00,0x00,0x00,0x00,0x20,0x38,0x1F,0x07,0x00,0x00,//),9
  57. 0x00,0x80,0xA0,0xE0,0xC0,0xE0,0xA0,0x80,0x00,0x00,0x02,0x03,0x01,0x03,0x02,0x00,//*,10
  58. 0x00,0x80,0x80,0xE0,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00,//+,11
  59. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2C,0x3C,0x1C,0x00,0x00,//,,12
  60. 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//-,13
  61. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x0C,0x00,0x00,//.,14
  62. 0x00,0x00,0x00,0x80,0xE0,0x78,0x18,0x00,0x00,0x18,0x1E,0x07,0x01,0x00,0x00,0x00,///,15
  63. 0x00,0x00,0xF0,0xF8,0x08,0x68,0xF8,0xF0,0x00,0x00,0x07,0x0F,0x0B,0x08,0x0F,0x07,//0,16
  64. 0x00,0x20,0x20,0x30,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,//1,17
  65. 0x00,0x30,0x38,0x08,0x88,0xF8,0x70,0x00,0x00,0x0C,0x0E,0x0B,0x09,0x08,0x08,0x00,//2,18
  66. 0x00,0x30,0x38,0x88,0x88,0xF8,0x70,0x00,0x00,0x06,0x0E,0x08,0x08,0x0F,0x07,0x00,//3,19
  67. 0x00,0x00,0xF8,0xF8,0x00,0xE0,0xE0,0x00,0x00,0x03,0x03,0x02,0x02,0x0F,0x0F,0x02,//4,20
  68. 0x00,0xF8,0xF8,0x88,0x88,0x88,0x08,0x00,0x00,0x08,0x08,0x08,0x0C,0x07,0x03,0x00,//5,21
  69. 0x00,0xC0,0xE0,0x78,0x58,0xC8,0x80,0x00,0x00,0x07,0x0F,0x08,0x08,0x0F,0x07,0x00,//6,22
  70. 0x00,0x08,0x08,0x88,0xE8,0x78,0x18,0x00,0x00,0x00,0x0E,0x0F,0x01,0x00,0x00,0x00,//7,23
  71. 0x00,0x70,0xF8,0xC8,0x88,0xF8,0x70,0x00,0x00,0x07,0x0F,0x08,0x09,0x0F,0x07,0x00,//8,24
  72. 0x00,0xF0,0xF8,0x08,0x08,0xF8,0xF0,0x00,0x00,0x00,0x09,0x0D,0x0F,0x03,0x01,0x00,//9,25
  73. 0x00,0x00,0x00,0x60,0x60,0x60,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x0C,0x00,0x00,//:,26
  74. 0x00,0x00,0x00,0x60,0x60,0x60,0x00,0x00,0x00,0x00,0x00,0x2C,0x3C,0x1C,0x00,0x00,//;,27
  75. 0x00,0x80,0xC0,0x60,0x30,0x18,0x08,0x00,0x00,0x00,0x01,0x03,0x06,0x0C,0x08,0x00,//<,28
  76. 0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00,//=,29
  77. 0x00,0x08,0x18,0x30,0x60,0xC0,0x80,0x00,0x00,0x08,0x0C,0x06,0x03,0x01,0x00,0x00,//>,30
  78. 0x00,0x30,0x38,0x88,0xC8,0x78,0x30,0x00,0x00,0x00,0x00,0x0D,0x0D,0x00,0x00,0x00,//?,31
  79. 0xF0,0xF8,0x08,0x88,0xC8,0x48,0xF8,0xF0,0x07,0x0F,0x08,0x09,0x0B,0x0A,0x0B,0x0B,//@,32
  80. 0x00,0xE0,0xF0,0x18,0x18,0xF0,0xE0,0x00,0x00,0x0F,0x0F,0x01,0x01,0x0F,0x0F,0x00,//A,33
  81. 0x00,0xF8,0xF8,0x88,0x88,0xF8,0x70,0x00,0x00,0x0F,0x0F,0x08,0x08,0x0F,0x07,0x00,//B,34
  82. 0x00,0xF0,0xF8,0x08,0x08,0x38,0x30,0x00,0x00,0x07,0x0F,0x08,0x08,0x0E,0x06,0x00,//C,35
  83. 0x00,0xF8,0xF8,0x08,0x18,0xF0,0xE0,0x00,0x00,0x0F,0x0F,0x08,0x0C,0x07,0x03,0x00,//D,36
  84. 0x00,0xF8,0xF8,0x88,0x88,0x88,0x08,0x00,0x00,0x0F,0x0F,0x08,0x08,0x08,0x08,0x00,//E,37
  85. 0x00,0xF8,0xF8,0x88,0x88,0x88,0x08,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00,0x00,//F,38
  86. 0x00,0xF0,0xF8,0x08,0x08,0x38,0x30,0x00,0x00,0x07,0x0F,0x08,0x09,0x0F,0x0F,0x00,//G,39
  87. 0x00,0xF8,0xF8,0x80,0x80,0xF8,0xF8,0x00,0x00,0x0F,0x0F,0x00,0x00,0x0F,0x0F,0x00,//H,40
  88. 0x00,0x00,0x08,0xF8,0xF8,0x08,0x00,0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00,//I,41
  89. 0x00,0x00,0x00,0x00,0x00,0xF8,0xF8,0x00,0x00,0x06,0x0E,0x08,0x08,0x0F,0x07,0x00,//J,42
  90. 0x00,0xF8,0xF8,0x80,0xE0,0x78,0x18,0x00,0x00,0x0F,0x0F,0x00,0x03,0x0F,0x0C,0x00,//K,43
  91. 0x00,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x0F,0x08,0x08,0x08,0x08,0x00,//L,44
  92. 0x00,0xF8,0xF8,0x20,0xC0,0x20,0xF8,0xF8,0x00,0x0F,0x0F,0x00,0x01,0x00,0x0F,0x0F,//M,45
  93. 0x00,0xF8,0xF8,0x60,0xC0,0x80,0xF8,0xF8,0x00,0x0F,0x0F,0x00,0x00,0x01,0x0F,0x0F,//N,46
  94. 0x00,0xF0,0xF8,0x08,0x08,0xF8,0xF0,0x00,0x00,0x07,0x0F,0x08,0x08,0x0F,0x07,0x00,//O,47
  95. 0x00,0xF8,0xF8,0x88,0x88,0xF8,0x70,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00,0x00,//P,48
  96. 0x00,0xF0,0xF8,0x08,0x08,0xF8,0xF0,0x00,0x00,0x07,0x0F,0x08,0x18,0x3F,0x27,0x00,//Q,49
  97. 0x00,0xF8,0xF8,0x88,0x88,0xF8,0x70,0x00,0x00,0x0F,0x0F,0x00,0x01,0x0F,0x0E,0x00,//R,50
  98. 0x00,0x30,0x78,0xC8,0x88,0x18,0x10,0x00,0x00,0x04,0x0C,0x08,0x09,0x0F,0x06,0x00,//S,51
  99. 0x00,0x08,0x08,0xF8,0xF8,0x08,0x08,0x00,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,//T,52
  100. 0x00,0xF8,0xF8,0x00,0x00,0xF8,0xF8,0x00,0x00,0x07,0x0F,0x08,0x08,0x0F,0x07,0x00,//U,53
  101. 0x00,0xF8,0xF8,0x00,0x00,0xF8,0xF8,0x00,0x00,0x03,0x07,0x0C,0x0C,0x07,0x03,0x00,//V,54
  102. 0x00,0xF8,0xF8,0x00,0xC0,0x00,0xF8,0xF8,0x00,0x01,0x0F,0x0E,0x01,0x0E,0x0F,0x01,//W,55
  103. 0x00,0x18,0x38,0xE0,0xC0,0x38,0x18,0x00,0x00,0x0E,0x0F,0x00,0x01,0x0F,0x0E,0x00,//X,56
  104. 0x00,0x78,0xF8,0x80,0x80,0xF8,0x78,0x00,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,//Y,57
  105. 0x00,0x08,0x08,0x88,0xC8,0x78,0x38,0x00,0x00,0x0E,0x0F,0x09,0x08,0x08,0x08,0x00,//Z,58
  106. 0x00,0x00,0xF8,0xF8,0x08,0x08,0x00,0x00,0x00,0x00,0x7F,0x7F,0x40,0x40,0x00,0x00,//[,59
  107. 0x00,0x18,0x78,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x1E,0x18,0x00,//\,60
  108. 0x00,0x00,0x08,0x08,0xF8,0xF8,0x00,0x00,0x00,0x00,0x40,0x40,0x7F,0x7F,0x00,0x00,//],61
  109. 0x00,0x08,0x0C,0x06,0x06,0x0C,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^,62
  110. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,//_,63
  111. 0x00,0x00,0x02,0x06,0x0E,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//`,64
  112. 0x00,0x00,0x20,0x20,0x20,0xE0,0xC0,0x00,0x00,0x06,0x0F,0x09,0x09,0x0F,0x0F,0x00,//a,65
  113. 0x00,0xF8,0xF8,0x20,0x20,0xE0,0xC0,0x00,0x00,0x0F,0x0F,0x08,0x08,0x0F,0x07,0x00,//b,66
  114. 0x00,0xC0,0xE0,0x20,0x20,0x60,0x40,0x00,0x00,0x07,0x0F,0x08,0x08,0x0C,0x04,0x00,//c,67
  115. 0x00,0xC0,0xE0,0x20,0x20,0xF8,0xF8,0x00,0x00,0x07,0x0F,0x08,0x08,0x0F,0x0F,0x00,//d,68
  116. 0x00,0xC0,0xE0,0x20,0x20,0xE0,0xC0,0x00,0x00,0x07,0x0F,0x09,0x09,0x09,0x01,0x00,//e,69
  117. 0x00,0x80,0xF0,0xF8,0x88,0x88,0x88,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00,//f,70
  118. 0x00,0xC0,0xE0,0x20,0x20,0xE0,0xE0,0x00,0x00,0x47,0x4F,0x48,0x48,0x7F,0x3F,0x00,//g,71
  119. 0x00,0xF8,0xF8,0x20,0x20,0xE0,0xC0,0x00,0x00,0x0F,0x0F,0x00,0x00,0x0F,0x0F,0x00,//h,72
  120. 0x00,0x20,0x20,0xEC,0xEC,0x00,0x00,0x00,0x00,0x08,0x08,0x0F,0x0F,0x08,0x08,0x00,//i,73
  121. 0x00,0x00,0x20,0x20,0xEC,0xEC,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x3F,0x00,0x00,//j,74
  122. 0x00,0xF8,0xF8,0x00,0x80,0xE0,0x60,0x00,0x00,0x0F,0x0F,0x01,0x03,0x0E,0x0C,0x00,//k,75
  123. 0x00,0x08,0x08,0xF8,0xF8,0x00,0x00,0x00,0x00,0x08,0x08,0x0F,0x0F,0x08,0x08,0x00,//l,76
  124. 0x00,0xE0,0xE0,0x20,0xE0,0x20,0xE0,0xC0,0x00,0x0F,0x0F,0x00,0x07,0x00,0x0F,0x0F,//m,77
  125. 0x00,0xE0,0xE0,0x20,0x20,0xE0,0xC0,0x00,0x00,0x0F,0x0F,0x00,0x00,0x0F,0x0F,0x00,//n,78
  126. 0x00,0xC0,0xE0,0x20,0x20,0xE0,0xC0,0x00,0x00,0x07,0x0F,0x08,0x08,0x0F,0x07,0x00,//o,79
  127. 0x00,0xE0,0xE0,0x20,0x20,0xE0,0xC0,0x00,0x00,0x7F,0x7F,0x08,0x08,0x0F,0x07,0x00,//p,80
  128. 0x00,0xC0,0xE0,0x20,0x20,0xE0,0xE0,0x00,0x00,0x07,0x0F,0x08,0x08,0x7F,0x7F,0x00,//q,81
  129. 0x00,0xE0,0xE0,0x80,0x40,0x60,0x60,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00,0x00,//r,82
  130. 0x00,0xC0,0xE0,0x20,0x20,0x20,0x20,0x00,0x00,0x08,0x09,0x09,0x09,0x0F,0x06,0x00,//s,83
  131. 0x00,0x20,0xF8,0xF8,0x20,0x20,0x20,0x00,0x00,0x00,0x07,0x0F,0x08,0x08,0x08,0x00,//t,84
  132. 0x00,0xE0,0xE0,0x00,0x00,0xE0,0xE0,0x00,0x00,0x07,0x0F,0x08,0x08,0x0F,0x0F,0x00,//u,85
  133. 0x00,0xE0,0xE0,0x00,0x00,0xE0,0xE0,0x00,0x00,0x03,0x07,0x0C,0x0C,0x07,0x03,0x00,//v,86
  134. 0x00,0xE0,0xE0,0x00,0xC0,0x00,0xE0,0xE0,0x00,0x03,0x0F,0x0C,0x03,0x0C,0x0F,0x03,//w,87
  135. 0x00,0x60,0xE0,0x80,0x80,0xE0,0x60,0x00,0x00,0x0C,0x0E,0x03,0x03,0x0E,0x0C,0x00,//x,88
  136. 0x00,0xE0,0xE0,0x00,0x00,0xE0,0xE0,0x00,0x40,0x47,0x4F,0x68,0x38,0x1F,0x07,0x00,//y,89
  137. 0x00,0x20,0x20,0x20,0xA0,0xE0,0x60,0x00,0x00,0x0C,0x0E,0x0B,0x09,0x08,0x08,0x00,//z,90
  138. 0x00,0x00,0x80,0xF0,0x78,0x08,0x00,0x00,0x00,0x01,0x03,0x1E,0x3C,0x20,0x00,0x00,//{,91
  139. 0x00,0x00,0x00,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x7F,0x00,0x00,0x00,//|,92
  140. 0x00,0x00,0x08,0x78,0xF0,0x80,0x00,0x00,0x00,0x00,0x20,0x3C,0x1E,0x03,0x01,0x00,//},93
  141. 0x30,0x18,0x08,0x18,0x30,0x20,0x30,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~,94
  142. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,//,95
  143. };
  144. uint8_t LCDBuffer[192] = {0};
  145. uint8_t *pLCD0, *pLCD1;
  146. const uint8_t *pASCII;
  147. /* USER CODE END PV */
  148. /* Private function prototypes -----------------------------------------------*/
  149. static void LL_Init(void);
  150. void SystemClock_Config(void);
  151. static void MX_GPIO_Init(void);
  152. static void MX_SPI1_Init(void);
  153. static void MX_TIM3_Init(void);
  154. /* USER CODE BEGIN PFP */
  155. /* Private function prototypes -----------------------------------------------*/
  156. void ST7545_Init(void);
  157. void ST7545_Print(char *str, uint8_t line);
  158. void ST7545_Clear(void);
  159. void TIM3Delay(uint16_t t);
  160. /* USER CODE END PFP */
  161. /* USER CODE BEGIN 0 */
  162. /* USER CODE END 0 */
  163. /**
  164.   * [url=u.php?uid=650075]@brief[/url]    The application entry point.
  165.   *
  166.   * @retval None
  167.   */
  168. int main(void)
  169. {
  170.   /* USER CODE BEGIN 1 */
  171.   /* USER CODE END 1 */
  172.   /* MCU Configuration----------------------------------------------------------*/
  173.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  174.   LL_Init();
  175.   /* USER CODE BEGIN Init */
  176.   /* USER CODE END Init */
  177.   /* Configure the system clock */
  178.   SystemClock_Config();
  179.   /* USER CODE BEGIN SysInit */
  180.   /* USER CODE END SysInit */
  181.   /* Initialize all configured peripherals */
  182.   MX_GPIO_Init();
  183.   MX_SPI1_Init();
  184.   MX_TIM3_Init();
  185.   /* USER CODE BEGIN 2 */
  186.     ST7545_Init();
  187.     ST7545_Print("ST7545 LCD", 0);
  188.     ST7545_Print("Demo Program", 2);
  189.     ST7545_Print("By XiaoMao", 4);
  190.     ST7545_Print("MyDigit.cn", 6);
  191.   /* USER CODE END 2 */
  192.   /* Infinite loop */
  193.   /* USER CODE BEGIN WHILE */
  194.   while (1)
  195.   {
  196.   /* USER CODE END WHILE */
  197.   /* USER CODE BEGIN 3 */
  198.   }
  199.   /* USER CODE END 3 */
  200. }
  201. static void LL_Init(void)
  202. {
  203.   
  204.   LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_SYSCFG);
  205.   LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
  206.   /* System interrupt init*/
  207.   /* SVC_IRQn interrupt configuration */
  208.   NVIC_SetPriority(SVC_IRQn, 0);
  209.   /* PendSV_IRQn interrupt configuration */
  210.   NVIC_SetPriority(PendSV_IRQn, 0);
  211.   /* SysTick_IRQn interrupt configuration */
  212.   NVIC_SetPriority(SysTick_IRQn, 0);
  213. }
  214. /**
  215.   * [url=u.php?uid=650075]@brief[/url]   System Clock Configuration
  216.   * @retval None
  217.   */
  218. void SystemClock_Config(void)
  219. {
  220.   LL_FLASH_SetLatency(LL_FLASH_LATENCY_0);
  221.   if(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_0)
  222.   {
  223.   Error_Handler();  
  224.   }
  225.   LL_RCC_HSI_Enable();
  226.    /* Wait till HSI is ready */
  227.   while(LL_RCC_HSI_IsReady() != 1)
  228.   {
  229.     
  230.   }
  231.   LL_RCC_HSI_SetCalibTrimming(16);
  232.   LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
  233.   LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
  234.   LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI);
  235.    /* Wait till System clock is ready */
  236.   while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI)
  237.   {
  238.   
  239.   }
  240.   LL_Init1msTick(8000000);
  241.   LL_SYSTICK_SetClkSource(LL_SYSTICK_CLKSOURCE_HCLK);
  242.   LL_SetSystemCoreClock(8000000);
  243.   /* SysTick_IRQn interrupt configuration */
  244.   NVIC_SetPriority(SysTick_IRQn, 0);
  245. }
  246. /* SPI1 init function */
  247. static void MX_SPI1_Init(void)
  248. {
  249.   LL_SPI_InitTypeDef SPI_InitStruct;
  250.   LL_GPIO_InitTypeDef GPIO_InitStruct;
  251.   /* Peripheral clock enable */
  252.   LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_SPI1);
  253.   
  254.   /**SPI1 GPIO Configuration  
  255.   PA5   ------> SPI1_SCK
  256.   PA7   ------> SPI1_MOSI
  257.   */
  258.   GPIO_InitStruct.Pin = LL_GPIO_PIN_5;
  259.   GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  260.   GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  261.   GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  262.   GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  263.   GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  264.   LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  265.   GPIO_InitStruct.Pin = LL_GPIO_PIN_7;
  266.   GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  267.   GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  268.   GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  269.   GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  270.   GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  271.   LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  272.   /* SPI1 parameter configuration*/
  273.   SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
  274.   SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
  275.   SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
  276.   SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_HIGH;
  277.   SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE;
  278.   SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
  279.   SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2;
  280.   SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
  281.   SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
  282.   SPI_InitStruct.CRCPoly = 7;
  283.   LL_SPI_Init(SPI1, &SPI_InitStruct);
  284.   LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA);
  285.   LL_SPI_DisableNSSPulseMgt(SPI1);
  286. }
  287. /* TIM3 init function */
  288. static void MX_TIM3_Init(void)
  289. {
  290.   LL_TIM_InitTypeDef TIM_InitStruct;
  291.   /* Peripheral clock enable */
  292.   LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
  293.   TIM_InitStruct.Prescaler = 7999;
  294.   TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_DOWN;
  295.   TIM_InitStruct.Autoreload = 499;
  296.   TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  297.   LL_TIM_Init(TIM3, &TIM_InitStruct);
  298.   LL_TIM_DisableARRPreload(TIM3);
  299.   LL_TIM_SetClockSource(TIM3, LL_TIM_CLOCKSOURCE_INTERNAL);
  300.   LL_TIM_SetTriggerOutput(TIM3, LL_TIM_TRGO_RESET);
  301.   LL_TIM_DisableMasterSlaveMode(TIM3);
  302. }
  303. /** Configure pins as
  304.         * Analog
  305.         * Input
  306.         * Output
  307.         * EVENT_OUT
  308.         * EXTI
  309. */
  310. static void MX_GPIO_Init(void)
  311. {
  312.   LL_GPIO_InitTypeDef GPIO_InitStruct;
  313.   /* GPIO Ports Clock Enable */
  314.   LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);
  315.   LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);
  316.   /**/
  317.   LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_6);
  318.   /**/
  319.   LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_1);
  320.   /**/
  321.   GPIO_InitStruct.Pin = LL_GPIO_PIN_6;
  322.   GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  323.   GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
  324.   GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  325.   GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  326.   LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  327.   /**/
  328.   GPIO_InitStruct.Pin = LL_GPIO_PIN_1;
  329.   GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  330.   GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
  331.   GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  332.   GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  333.   LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  334. }
  335. /* USER CODE BEGIN 4 */
  336. void ST7545_Init(void)
  337. {
  338.     LL_SPI_Enable(SPI1);
  339.     LL_GPIO_ResetOutputPin(GPIOB, LL_GPIO_PIN_1);    //RST Low
  340.     TIM3Delay(50);
  341.     LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_1);    //Rst Hi
  342.     TIM3Delay(50);
  343.     while(LL_SPI_IsActiveFlag_TXE(SPI1) == RESET){}
  344.     LL_SPI_TransmitData8(SPI1, 0x21);    //H = 1
  345.     while(LL_SPI_IsActiveFlag_TXE(SPI1) == RESET){}
  346.     LL_SPI_TransmitData8(SPI1, 0x10);    //Set bias system (BSx)
  347.     while(LL_SPI_IsActiveFlag_TXE(SPI1) == RESET){}
  348.     LL_SPI_TransmitData8(SPI1, 0xC0);    //Set V0 (VOP) output voltage
  349.     while(LL_SPI_IsActiveFlag_TXE(SPI1) == RESET){}
  350.     LL_SPI_TransmitData8(SPI1, 0x20);    //H = 0, Horizontal addressing mode
  351.     while(LL_SPI_IsActiveFlag_TXE(SPI1) == RESET){}
  352.     LL_SPI_TransmitData8(SPI1, 0x0C);    //Sets display configuration
  353.     ST7545_Clear();
  354. }
  355. void ST7545_Clear(void)
  356. {
  357.     for(uint8_t i = 0; i < 9; i++)
  358.     {
  359.         LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_6);
  360.         while(LL_SPI_IsActiveFlag_TXE(SPI1) == RESET){}
  361.         LL_SPI_TransmitData8(SPI1, 0x40 | i);
  362.         while(LL_SPI_IsActiveFlag_TXE(SPI1) == RESET){}
  363.         LL_SPI_TransmitData8(SPI1, 0x80);
  364.         while(LL_SPI_IsActiveFlag_BSY(SPI1)){}
  365.         LL_GPIO_SetOutputPin(GPIOA, LL_GPIO_PIN_6);
  366.         for(uint8_t j = 0; j < 96; j++)
  367.         {
  368.             while(LL_SPI_IsActiveFlag_TXE(SPI1) == RESET){}
  369.             LL_SPI_TransmitData8(SPI1, 0x00);
  370.         }
  371.     }
  372. }
  373. void ST7545_Print(char *str, uint8_t line)
  374. {
  375.     pLCD0 = LCDBuffer;
  376.     pLCD1 = LCDBuffer + 96;
  377.     for(uint8_t i = 0; i < 12; i++)
  378.     {
  379.         if(*str)
  380.         {
  381.             pASCII = ASCII + ((*str - 0x20) << 4);
  382.             str++;
  383.         }
  384.         else
  385.         {
  386.             pASCII = ASCII;
  387.         }
  388.         for(uint8_t j = 0; j < 8; j++)
  389.         {
  390.             *pLCD0++ = *pASCII++;
  391.         }
  392.         for(uint8_t j = 0; j < 8; j++)
  393.         {
  394.             *pLCD1++ = *pASCII++;
  395.         }
  396.     }    
  397.     pLCD0 = LCDBuffer;
  398.     while(LL_SPI_IsActiveFlag_BSY(SPI1)){}
  399.     LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_6);
  400.     while(LL_SPI_IsActiveFlag_TXE(SPI1) == RESET){}
  401.     LL_SPI_TransmitData8(SPI1, 0x47 - (line++ & 0x7));
  402.     while(LL_SPI_IsActiveFlag_TXE(SPI1) == RESET){}
  403.     LL_SPI_TransmitData8(SPI1, 0x80);
  404.     while(LL_SPI_IsActiveFlag_BSY(SPI1)){}
  405.     LL_GPIO_SetOutputPin(GPIOA, LL_GPIO_PIN_6);
  406.     for(uint8_t i = 0; i < 96; i++)
  407.     {
  408.         while(LL_SPI_IsActiveFlag_TXE(SPI1) == RESET){}
  409.         LL_SPI_TransmitData8(SPI1, *pLCD0++);
  410.     }
  411.     while(LL_SPI_IsActiveFlag_BSY(SPI1)){}
  412.     LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_6);
  413.     while(LL_SPI_IsActiveFlag_TXE(SPI1) == RESET){}
  414.     LL_SPI_TransmitData8(SPI1, 0x47 - (line & 0x7));
  415.     while(LL_SPI_IsActiveFlag_TXE(SPI1) == RESET){}
  416.     LL_SPI_TransmitData8(SPI1, 0x80);
  417.     while(LL_SPI_IsActiveFlag_BSY(SPI1)){}
  418.     LL_GPIO_SetOutputPin(GPIOA, LL_GPIO_PIN_6);
  419.     for(uint8_t i = 0; i < 96; i++)
  420.     {
  421.         while(LL_SPI_IsActiveFlag_TXE(SPI1) == RESET){}
  422.         LL_SPI_TransmitData8(SPI1, *pLCD0++);
  423.     }
  424. }
  425. void TIM3Delay(uint16_t t)
  426. {
  427.         LL_TIM_SetCounter(TIM3, t);
  428.         LL_TIM_EnableCounter(TIM3);
  429.         while(!LL_TIM_IsActiveFlag_UPDATE(TIM3))
  430.         {
  431.         }
  432.         LL_TIM_ClearFlag_UPDATE(TIM3);
  433.         LL_TIM_DisableCounter(TIM3);
  434. }
  435. /* USER CODE END 4 */
  436. /**
  437.   * [url=u.php?uid=650075]@brief[/url]    This function is executed in case of error occurrence.
  438.   * @param  file: The file name as string.
  439.   * @param  line: The line in file as a number.
  440.   * @retval None
  441.   */
  442. void _Error_Handler(char *file, int line)
  443. {
  444.   /* USER CODE BEGIN Error_Handler_Debug */
  445.   /* User can add his own implementation to report the HAL error return state */
  446.   while(1)
  447.   {
  448.   }
  449.   /* USER CODE END Error_Handler_Debug */
  450. }
  451. #ifdef  USE_FULL_ASSERT
  452. /**
  453.   * [url=u.php?uid=650075]@brief[/url]    Reports the name of the source file and the source line number
  454.   *         where the assert_param error has occurred.
  455.   * @param  file: pointer to the source file name
  456.   * @param  line: assert_param error line source number
  457.   * @retval None
  458.   */
  459. void assert_failed(uint8_t* file, uint32_t line)
  460. {
  461.   /* USER CODE BEGIN 6 */
  462.   /* User can add his own implementation to report the file name and line number,
  463.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  464.   /* USER CODE END 6 */
  465. }
  466. #endif /* USE_FULL_ASSERT */
  467. /**
  468.   * @}
  469.   */
  470. /**
  471.   * @}
  472.   */
  473. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/




[ 此帖被小茅在2018-11-12 19:26重新编辑 ]
本文内容包含图片或附件,获取更多资讯,请 登录 后查看;或者 注册 成为会员获得更多权限
数码之家终于回归正常的论坛模式了
离线shiyb

发帖
979
M币
2660
专家
0
粉丝
13
只看该作者 1楼 发表于: 10-26
恭喜恭喜!楼主点石成金。
在线yyglxc

发帖
4656
M币
1440
专家
1
粉丝
34
只看该作者 2楼 发表于: 10-26
谢谢分享经验!
离线glf999

发帖
316
M币
-626
专家
2
粉丝
10
只看该作者 3楼 发表于: 10-26
前几天也 看贴后买了 几块  还没到手呢

也不会用正好多学习一下 谢谢分享了
离线550573685

发帖
1020
M币
492
专家
2
粉丝
25
只看该作者 4楼 发表于: 10-26
一个古董库存点亮即可,不用太在意是什么芯片,很多都兼容的,就像国产芯片,还有些是人家想保留点东西,不会全告诉卖家的 呵呵
离线550573685

发帖
1020
M币
492
专家
2
粉丝
25
只看该作者 5楼 发表于: 10-26

本文内容包含图片或附件,获取更多资讯,请 登录 后查看;或者 注册 成为会员获得更多权限
离线小茅

发帖
2290
M币
1597
专家
6
粉丝
36
只看该作者 6楼 发表于: 10-26
回 glf999 的帖子
glf999:前几天也 看贴后买了 几块  还没到手呢
也不会用正好多学习一下 谢谢分享了 (2018-10-26 15:53) 回 glf999 的帖子

希望帖子的内容对你有帮助
数码之家终于回归正常的论坛模式了
在线acbear

发帖
103
M币
187
专家
0
粉丝
15
只看该作者 7楼 发表于: 10-26
谢谢分享,买了几片1.5寸的屏,回去试试。
离线1325133

发帖
1864
M币
1496
专家
1
粉丝
29
只看该作者 8楼 发表于: 10-26
虽不明,但觉厉。
离线flkflk

发帖
213
M币
55
专家
0
粉丝
9
只看该作者 9楼 发表于: 11-06
谢谢您的分享, 我的三十片也到手了,慢慢折腾。