当前位置:   article > 正文

(HAL)STM32F103C6T8——软件模拟I2C驱动0.96寸OLED屏幕

(HAL)STM32F103C6T8——软件模拟I2C驱动0.96寸OLED屏幕

一、电路接法

电路接法参照江科大视频。

二、相关代码及文件

说明:代码采用hal库,通过修改江科大代码实现。仅OLED.c文件关于引脚定义作了hal库修改,并将宏定义OLED_W_SCL(x)、OLED_W_SDA(x)作了相关修改。

1、OLED.c

  1. void OLED_I2C_Init(void) /* 作修改部分 */
  2. {
  3. /* 1、时钟使能 */
  4. __HAL_RCC_GPIOB_CLK_ENABLE();
  5. /* 2、引脚初始化 */
  6. GPIO_InitTypeDef g_init_struct;
  7. g_init_struct.Pin = GPIO_PIN_8;
  8. g_init_struct.Mode = GPIO_MODE_OUTPUT_PP;
  9. g_init_struct.Speed = GPIO_SPEED_FREQ_HIGH;
  10. g_init_struct.Pull = GPIO_PULLUP;
  11. HAL_GPIO_Init(GPIOB, &g_init_struct);
  12. g_init_struct.Pin = GPIO_PIN_9;
  13. HAL_GPIO_Init(GPIOB, &g_init_struct);
  14. OLED_W_SCL(1);
  15. OLED_W_SDA(1);
  16. }
  1. #include "./BSP/OLED/OLED.h"
  2. #include "./BSP/OLED/OLED_Font.h"
  3. void OLED_I2C_Init(void)
  4. {
  5. /* 1、时钟使能 */
  6. __HAL_RCC_GPIOB_CLK_ENABLE();
  7. /* 2、引脚初始化 */
  8. GPIO_InitTypeDef g_init_struct;
  9. g_init_struct.Pin = GPIO_PIN_8;
  10. g_init_struct.Mode = GPIO_MODE_OUTPUT_PP;
  11. g_init_struct.Speed = GPIO_SPEED_FREQ_HIGH;
  12. g_init_struct.Pull = GPIO_PULLUP;
  13. HAL_GPIO_Init(GPIOB, &g_init_struct);
  14. g_init_struct.Pin = GPIO_PIN_9;
  15. HAL_GPIO_Init(GPIOB, &g_init_struct);
  16. OLED_W_SCL(1);
  17. OLED_W_SDA(1);
  18. }
  19. /**
  20. * @brief I2C开始
  21. * @param 无
  22. * @retval 无
  23. */
  24. void OLED_I2C_Start(void)
  25. {
  26. OLED_W_SDA(1);
  27. OLED_W_SCL(1);
  28. OLED_W_SDA(0);
  29. OLED_W_SCL(0);
  30. }
  31. /**
  32. * @brief I2C停止
  33. * @param 无
  34. * @retval 无
  35. */
  36. void OLED_I2C_Stop(void)
  37. {
  38. OLED_W_SDA(0);
  39. OLED_W_SCL(1);
  40. OLED_W_SDA(1);
  41. }
  42. /**
  43. * @brief I2C发送一个字节
  44. * @param Byte 要发送的一个字节
  45. * @retval 无
  46. */
  47. void OLED_I2C_SendByte(uint8_t Byte)
  48. {
  49. uint8_t i;
  50. for (i = 0; i < 8; i++)
  51. {
  52. OLED_W_SDA(Byte & (0x80 >> i));
  53. OLED_W_SCL(1);
  54. OLED_W_SCL(0);
  55. }
  56. OLED_W_SCL(1); //额外的一个时钟,不处理应答信号
  57. OLED_W_SCL(0);
  58. }
  59. /**
  60. * @brief OLED写命令
  61. * @param Command 要写入的命令
  62. * @retval 无
  63. */
  64. void OLED_WriteCommand(uint8_t Command)
  65. {
  66. OLED_I2C_Start();
  67. OLED_I2C_SendByte(0x78); //从机地址
  68. OLED_I2C_SendByte(0x00); //写命令
  69. OLED_I2C_SendByte(Command);
  70. OLED_I2C_Stop();
  71. }
  72. /**
  73. * @brief OLED写数据
  74. * @param Data 要写入的数据
  75. * @retval 无
  76. */
  77. void OLED_WriteData(uint8_t Data)
  78. {
  79. OLED_I2C_Start();
  80. OLED_I2C_SendByte(0x78); //从机地址
  81. OLED_I2C_SendByte(0x40); //写数据
  82. OLED_I2C_SendByte(Data);
  83. OLED_I2C_Stop();
  84. }
  85. /**
  86. * @brief OLED设置光标位置
  87. * @param Y 以左上角为原点,向下方向的坐标,范围:0~7
  88. * @param X 以左上角为原点,向右方向的坐标,范围:0~127
  89. * @retval 无
  90. */
  91. void OLED_SetCursor(uint8_t Y, uint8_t X)
  92. {
  93. OLED_WriteCommand(0xB0 | Y); //设置Y位置
  94. OLED_WriteCommand(0x10 | ((X & 0xF0) >> 4)); //设置X位置高4位
  95. OLED_WriteCommand(0x00 | (X & 0x0F)); //设置X位置低4
  96. }
  97. /**
  98. * @brief OLED清屏
  99. * @param 无
  100. * @retval 无
  101. */
  102. void OLED_Clear(void)
  103. {
  104. uint8_t i, j;
  105. for (j = 0; j < 8; j++)
  106. {
  107. OLED_SetCursor(j, 0);
  108. for(i = 0; i < 128; i++)
  109. {
  110. OLED_WriteData(0x00);
  111. }
  112. }
  113. }
  114. /**
  115. * @brief OLED显示一个字符
  116. * @param Line 行位置,范围:1~4
  117. * @param Column 列位置,范围:1~16
  118. * @param Char 要显示的一个字符,范围:ASCII可见字符
  119. * @retval 无
  120. */
  121. void OLED_ShowChar(uint8_t Line, uint8_t Column, char Char)
  122. {
  123. uint8_t i;
  124. OLED_SetCursor((Line - 1) * 2, (Column - 1) * 8); //设置光标位置在上半部分
  125. for (i = 0; i < 8; i++)
  126. {
  127. OLED_WriteData(OLED_F8x16[Char - ' '][i]); //显示上半部分内容
  128. }
  129. OLED_SetCursor((Line - 1) * 2 + 1, (Column - 1) * 8); //设置光标位置在下半部分
  130. for (i = 0; i < 8; i++)
  131. {
  132. OLED_WriteData(OLED_F8x16[Char - ' '][i + 8]); //显示下半部分内容
  133. }
  134. }
  135. /**
  136. * @brief OLED显示字符串
  137. * @param Line 起始行位置,范围:1~4
  138. * @param Column 起始列位置,范围:1~16
  139. * @param String 要显示的字符串,范围:ASCII可见字符
  140. * @retval 无
  141. */
  142. void OLED_ShowString(uint8_t Line, uint8_t Column, char *String)
  143. {
  144. uint8_t i;
  145. for (i = 0; String[i] != '\0'; i++)
  146. {
  147. OLED_ShowChar(Line, Column + i, String[i]);
  148. }
  149. }
  150. /**
  151. * @brief OLED次方函数
  152. * @retval 返回值等于X的Y次方
  153. */
  154. uint32_t OLED_Pow(uint32_t X, uint32_t Y)
  155. {
  156. uint32_t Result = 1;
  157. while (Y--)
  158. {
  159. Result *= X;
  160. }
  161. return Result;
  162. }
  163. /**
  164. * @brief OLED显示数字(十进制,正数)
  165. * @param Line 起始行位置,范围:1~4
  166. * @param Column 起始列位置,范围:1~16
  167. * @param Number 要显示的数字,范围:0~4294967295
  168. * @param Length 要显示数字的长度,范围:1~10
  169. * @retval 无
  170. */
  171. void OLED_ShowNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length)
  172. {
  173. uint8_t i;
  174. for (i = 0; i < Length; i++)
  175. {
  176. OLED_ShowChar(Line, Column + i, Number / OLED_Pow(10, Length - i - 1) % 10 + '0');
  177. }
  178. }
  179. /**
  180. * @brief OLED显示数字(十进制,带符号数)
  181. * @param Line 起始行位置,范围:1~4
  182. * @param Column 起始列位置,范围:1~16
  183. * @param Number 要显示的数字,范围:-2147483648~2147483647
  184. * @param Length 要显示数字的长度,范围:1~10
  185. * @retval 无
  186. */
  187. void OLED_ShowSignedNum(uint8_t Line, uint8_t Column, int32_t Number, uint8_t Length)
  188. {
  189. uint8_t i;
  190. uint32_t Number1;
  191. if (Number >= 0)
  192. {
  193. OLED_ShowChar(Line, Column, '+');
  194. Number1 = Number;
  195. }
  196. else
  197. {
  198. OLED_ShowChar(Line, Column, '-');
  199. Number1 = -Number;
  200. }
  201. for (i = 0; i < Length; i++)
  202. {
  203. OLED_ShowChar(Line, Column + i + 1, Number1 / OLED_Pow(10, Length - i - 1) % 10 + '0');
  204. }
  205. }
  206. /**
  207. * @brief OLED显示数字(十六进制,正数)
  208. * @param Line 起始行位置,范围:1~4
  209. * @param Column 起始列位置,范围:1~16
  210. * @param Number 要显示的数字,范围:0~0xFFFFFFFF
  211. * @param Length 要显示数字的长度,范围:1~8
  212. * @retval 无
  213. */
  214. void OLED_ShowHexNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length)
  215. {
  216. uint8_t i, SingleNumber;
  217. for (i = 0; i < Length; i++)
  218. {
  219. SingleNumber = Number / OLED_Pow(16, Length - i - 1) % 16;
  220. if (SingleNumber < 10)
  221. {
  222. OLED_ShowChar(Line, Column + i, SingleNumber + '0');
  223. }
  224. else
  225. {
  226. OLED_ShowChar(Line, Column + i, SingleNumber - 10 + 'A');
  227. }
  228. }
  229. }
  230. /**
  231. * @brief OLED显示数字(二进制,正数)
  232. * @param Line 起始行位置,范围:1~4
  233. * @param Column 起始列位置,范围:1~16
  234. * @param Number 要显示的数字,范围:0~1111 1111 1111 1111
  235. * @param Length 要显示数字的长度,范围:1~16
  236. * @retval 无
  237. */
  238. void OLED_ShowBinNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length)
  239. {
  240. uint8_t i;
  241. for (i = 0; i < Length; i++)
  242. {
  243. OLED_ShowChar(Line, Column + i, Number / OLED_Pow(2, Length - i - 1) % 2 + '0');
  244. }
  245. }
  246. /**
  247. * @brief OLED初始化
  248. * @param 无
  249. * @retval 无
  250. */
  251. void OLED_Init(void)
  252. {
  253. uint32_t i, j;
  254. for (i = 0; i < 1000; i++) //上电延时
  255. {
  256. for (j = 0; j < 1000; j++);
  257. }
  258. OLED_I2C_Init(); //端口初始化
  259. OLED_WriteCommand(0xAE); //关闭显示
  260. OLED_WriteCommand(0xD5); //设置显示时钟分频比/振荡器频率
  261. OLED_WriteCommand(0x80);
  262. OLED_WriteCommand(0xA8); //设置多路复用率
  263. OLED_WriteCommand(0x3F);
  264. OLED_WriteCommand(0xD3); //设置显示偏移
  265. OLED_WriteCommand(0x00);
  266. OLED_WriteCommand(0x40); //设置显示开始行
  267. OLED_WriteCommand(0xA1); //设置左右方向,0xA1正常 0xA0左右反置
  268. OLED_WriteCommand(0xC8); //设置上下方向,0xC8正常 0xC0上下反置
  269. OLED_WriteCommand(0xDA); //设置COM引脚硬件配置
  270. OLED_WriteCommand(0x12);
  271. OLED_WriteCommand(0x81); //设置对比度控制
  272. OLED_WriteCommand(0xCF);
  273. OLED_WriteCommand(0xD9); //设置预充电周期
  274. OLED_WriteCommand(0xF1);
  275. OLED_WriteCommand(0xDB); //设置VCOMH取消选择级别
  276. OLED_WriteCommand(0x30);
  277. OLED_WriteCommand(0xA4); //设置整个显示打开/关闭
  278. OLED_WriteCommand(0xA6); //设置正常/倒转显示
  279. OLED_WriteCommand(0x8D); //设置充电泵
  280. OLED_WriteCommand(0x14);
  281. OLED_WriteCommand(0xAF); //开启显示
  282. OLED_Clear(); //OLED清屏
  283. }

2、OLED.h

  1. #ifndef __OLED_H
  2. #define __OLED_H
  3. #include "./SYSTEM/sys/sys.h"
  4. /*引脚配置(作修改部分)*/
  5. #define OLED_W_SCL(x) do{ x ? \
  6. HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET) : \
  7. HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET); \
  8. }while(0)
  9. #define OLED_W_SDA(x) do{ x ? \
  10. HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_SET) : \
  11. HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET); \
  12. }while(0)
  13. void OLED_Init(void);
  14. void OLED_Clear(void);
  15. void OLED_ShowChar(uint8_t Line, uint8_t Column, char Char);
  16. void OLED_ShowString(uint8_t Line, uint8_t Column, char *String);
  17. void OLED_ShowNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length);
  18. void OLED_ShowSignedNum(uint8_t Line, uint8_t Column, int32_t Number, uint8_t Length);
  19. void OLED_ShowHexNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length);
  20. void OLED_ShowBinNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length);
  21. #endif

3、OLED_Font.h

  1. #ifndef __OLED_FONT_H
  2. #define __OLED_FONT_H
  3. /*OLED字模库,宽8像素,高16像素*/
  4. const uint8_t OLED_F8x16[][16]=
  5. {
  6. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
  8. 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,
  9. 0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
  10. 0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,
  11. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
  12. 0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,
  13. 0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
  14. 0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,
  15. 0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
  16. 0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,
  17. 0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
  18. 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,
  19. 0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
  20. 0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,
  21. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
  22. 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,
  23. 0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
  24. 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,
  25. 0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
  26. 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,
  27. 0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
  28. 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,
  29. 0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
  30. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31. 0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
  32. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33. 0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
  34. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  35. 0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
  36. 0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,
  37. 0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
  38. 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
  39. 0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
  40. 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,
  41. 0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
  42. 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,
  43. 0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
  44. 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,
  45. 0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
  46. 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,
  47. 0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
  48. 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,
  49. 0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
  50. 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,
  51. 0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
  52. 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,
  53. 0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
  54. 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,
  55. 0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
  56. 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
  57. 0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
  58. 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,
  59. 0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
  60. 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,
  61. 0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
  62. 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,
  63. 0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
  64. 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,
  65. 0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
  66. 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,
  67. 0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
  68. 0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,
  69. 0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
  70. 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,
  71. 0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
  72. 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,
  73. 0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
  74. 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,
  75. 0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
  76. 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,
  77. 0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
  78. 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,
  79. 0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
  80. 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,
  81. 0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
  82. 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,
  83. 0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
  84. 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,
  85. 0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
  86. 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,
  87. 0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
  88. 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,
  89. 0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
  90. 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,
  91. 0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
  92. 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,
  93. 0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
  94. 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,
  95. 0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
  96. 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,
  97. 0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
  98. 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,
  99. 0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
  100. 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,
  101. 0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
  102. 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,
  103. 0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
  104. 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,
  105. 0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
  106. 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,
  107. 0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
  108. 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,
  109. 0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
  110. 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,
  111. 0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
  112. 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,
  113. 0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
  114. 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,
  115. 0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
  116. 0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,
  117. 0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
  118. 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,
  119. 0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
  120. 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,
  121. 0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
  122. 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,
  123. 0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
  124. 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,
  125. 0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
  126. 0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,
  127. 0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60
  128. 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,
  129. 0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
  130. 0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,
  131. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
  132. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  133. 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
  134. 0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,
  135. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
  136. 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
  137. 0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
  138. 0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,
  139. 0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
  140. 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,
  141. 0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
  142. 0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,
  143. 0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
  144. 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
  145. 0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
  146. 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,
  147. 0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
  148. 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,
  149. 0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
  150. 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,
  151. 0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
  152. 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,
  153. 0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
  154. 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,
  155. 0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
  156. 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,
  157. 0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
  158. 0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,
  159. 0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
  160. 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
  161. 0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
  162. 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,
  163. 0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
  164. 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
  165. 0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
  166. 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,
  167. 0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
  168. 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,
  169. 0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
  170. 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,
  171. 0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
  172. 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,
  173. 0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
  174. 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,
  175. 0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
  176. 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,
  177. 0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
  178. 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,
  179. 0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
  180. 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,
  181. 0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
  182. 0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,
  183. 0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
  184. 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,
  185. 0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
  186. 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
  187. 0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
  188. 0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,
  189. 0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
  190. 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,
  191. 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
  192. 0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,
  193. 0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
  194. 0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,
  195. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
  196. };
  197. #endif

4、main.c

  1. #include "./SYSTEM/sys/sys.h"
  2. #include "./SYSTEM/usart/usart.h"
  3. #include "./SYSTEM/delay/delay.h"
  4. #include "./BSP/LED/led.h"
  5. #include "./BSP/KEY/key.h"
  6. #include "./BSP/OLED/OLED.h"
  7. int main(void)
  8. {
  9. HAL_Init(); /* 初始化HAL库 */
  10. sys_stm32_clock_init(RCC_PLL_MUL9); /* 设置时钟, 72Mhz */
  11. delay_init(72); /* 延时初始化 */
  12. usart_init(115200); /* 初始化串口 */
  13. led_init();
  14. key_init();
  15. OLED_Init();
  16. /*OLED显示*/
  17. OLED_ShowChar(1, 1, 'A'); //11列显示字符A
  18. OLED_ShowString(1, 3, "HelloWorld!"); //13列显示字符串HelloWorld!
  19. OLED_ShowNum(2, 1, 12345, 5); //21列显示十进制数字12345,长度为5
  20. OLED_ShowSignedNum(2, 7, -66, 2); //27列显示有符号十进制数字-66,长度为2
  21. OLED_ShowHexNum(3, 1, 0xAA55, 4); //31列显示十六进制数字0xA5A5,长度为4
  22. OLED_ShowBinNum(4, 1, 0xAA55, 16); //41列显示二进制数字0xA5A5,长度为16
  23. //C语言无法直接写出二进制数字,故需要用十六进制表示
  24. while(1)
  25. {
  26. }
  27. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/164348
推荐阅读
相关标签
  

闽ICP备14008679号