[其他ST产品] STM32使用4线SPI模式驱动SSD1351

[复制链接]
971|4
 楼主| 原来是wjc 发表于 2022-12-27 16:32 | 显示全部楼层 |阅读模式
STM32与SSD1351的接线如下:PC9 – CS :片选低电平有效
PC8–DC :数据/命令控制
PC7–RST :控制器和驱动器的电源复位RES
PB15–SDA :SPI2_MOSI
PB13–SCL : SPI2_SCK
字模取模方式:阴码 逐行式 顺向
图片取模:16位真彩色 高位在前
  1. /*ssd1351.h*/
  2. #ifndef __ssd1351_H
  3. #define __ssd1351_H
  4. #include "stm32f10x.h"

  5. /* 宏定义 --------------------------------------------------------------------*/
  6. #define                Black                0x0000                //黑色(不亮)
  7. #define                Navy                0x000F                //深蓝色
  8. #define                Dgreen                0x03E0                //深绿色
  9. #define                Dcyan                0x03EF                //深青色
  10. #define                Maroon                0x7800                //深红色
  11. #define                Purple                0x780F                //紫色
  12. #define                Olive                0x7BE0                //橄榄绿
  13. #define                Lgray                0xC618                //灰白色
  14. #define                Dgray                0x7BEF                //深灰色
  15. #define                Blue                0x001F                //蓝色
  16. #define                Green                0x07E0                //绿色
  17. #define                Cyan                0x07FF                //青色
  18. #define                Red                        0xF800                //红色
  19. #define                Magenta                0xF81F                //品红
  20. #define                Yellow                0xFFE0                //黄色
  21. #define                White                0xFFFF                //白色

  22. #define Max_Column          0x7f                        // 128-1
  23. #define Max_Row                  0x7f                        // 128-1

  24. //PC7          LCD_RST        控制器和驱动器的电源复位
  25. #define OLED_RES_GPIO_PORT      (GPIOC)                                //RES#引脚
  26. #define OLED_RES_GPIO_PINS      (GPIO_Pin_7)
  27. //PC8          LCD_DC        数据/命令控制
  28. #define OLED_DC_GPIO_PORT       (GPIOC)                                //D/C#引脚
  29. #define OLED_DC_GPIO_PINS       (GPIO_Pin_8)
  30. //PC9          LCD_CS        片选 低电平有效
  31. #define OLED_CS_GPIO_PORT              (GPIOC)                                //CS#引脚
  32. #define OLED_CS_GPIO_PINS              (GPIO_Pin_9)

  33. #define OLED_RES_Set()          GPIO_SetBits(OLED_RES_GPIO_PORT, OLED_RES_GPIO_PINS)
  34. #define OLED_RES_Clr()          GPIO_ResetBits(OLED_RES_GPIO_PORT,OLED_RES_GPIO_PINS)

  35. #define OLED_DC_Set()           GPIO_SetBits(OLED_DC_GPIO_PORT, OLED_DC_GPIO_PINS)
  36. #define OLED_DC_Clr()           GPIO_ResetBits(OLED_DC_GPIO_PORT, OLED_DC_GPIO_PINS)

  37. #define        SPI_NSS_HIGH()                        GPIO_SetBits(OLED_CS_GPIO_PORT, OLED_CS_GPIO_PINS)
  38. #define        SPI_NSS_LOW()                        GPIO_ResetBits(OLED_CS_GPIO_PORT, OLED_CS_GPIO_PINS)

  39. /* 函数声明-------------------------------------------------------------------*/
  40. void OLED_GPIO_Init(void);//IO口初始化
  41. void SPI2_Init(void);//SPI初始化
  42. u8 SPI_RW_Byte(u8 data);//使用SPI0读写1Byte

  43. void Fill_RAM(int Colour_RGB);//填充全屏(刷屏)
  44. void Clear_Screen(unsigned char Var_Row);//指定某一行清屏(一共8行:0~7)
  45. //指定坐标画一个字符(逐行式),字符大小固定为8*16
  46. void Display_Char(unsigned char x, unsigned char y, unsigned char Var_Char, int Colour_RGB);
  47. //显示字符串
  48. void Display_String(unsigned char x, unsigned char y, unsigned char *chr, int Colour_RGB);
  49. //指定坐标画一个字符(逐行式),字符大小固定为16*16
  50. void Display_Chinese16x16(unsigned char x, unsigned char y, unsigned char Var_Char, int Colour_RGB);
  51. //指定坐标画一个字符(逐行式),字符大小固定为12*12
  52. void Display_Chinese12x12(unsigned char x, unsigned char y, unsigned char Var_Char, int Colour_RGB);
  53. //显示数字
  54. void Display_Num(unsigned char x,unsigned char y,int Var_Num, unsigned char Num_Len, int Colour_RGB);
  55. //显示图片
  56. void Display_Pattern(unsigned char *Pattern_Data, unsigned char Start_x, unsigned char End_x, unsigned char Start_y, unsigned char End_y);
  57. //画点
  58. void Draw_Point(const unsigned char x, const unsigned char y, int Colour_RGB);
  59. //画圆圈
  60. void Display_Circle(const u8 x,const u8 y,const u8 r, int Colour_RGB);
  61. //灰阶表设置
  62. void Set_Gray_Scale_Table(void);
  63. //OLED显示初始化
  64. void OLED_Init(void);
  65. #endif



评论

———————————————— 版权声明:本文为CSDN博主「霍格沃兹在逃Coder」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/sinat_24880087/article/details/105877144  发表于 2022-12-27 16:33
 楼主| 原来是wjc 发表于 2022-12-27 16:40 | 显示全部楼层
  1. /*ssd1351.c*/
  2. #include "font.h"
  3. /****************************************************
  4. 函数名:OLED_GPIO_Init
  5. 形参:
  6. 返回值:
  7. 函数功能:OLED的信号引脚初始化
  8. ****************************************************/
  9. void OLED_GPIO_Init(void)
  10. {
  11.     GPIO_InitTypeDef GPIO_InitStructure;        //定义结构体

  12.     RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE);        //使能GPIOC时钟
  13.     GPIO_InitStructure.GPIO_Pin = OLED_RES_GPIO_PINS | OLED_DC_GPIO_PINS | OLED_CS_GPIO_PINS;                //初始化用于控制OLED的相关引脚
  14.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;        //推挽输出
  15.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  16.     GPIO_Init(GPIOC, &GPIO_InitStructure);        //初始化

  17.     GPIO_SetBits(GPIOC, OLED_RES_GPIO_PINS | OLED_DC_GPIO_PINS | OLED_CS_GPIO_PINS);        //将RES、DC、CS引脚拉高
  18. }
  19. /****************************************************
  20. 函数名:SPI2_Init
  21. 形参:
  22. 返回值:
  23. 函数功能:初始化SPI2
  24. ****************************************************/
  25. void SPI2_Init(void)
  26. {
  27.     /* 定义spi与GPIO配置参数结构体 */
  28.     SPI_InitTypeDef  SPI_InitStruct;
  29.     GPIO_InitTypeDef GPIO_InitStructure;

  30.     /* 打开SPI2的端口时钟、AFIO与外设时钟 */
  31.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
  32.     RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);

  33.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_13;        //初始化PB13(CLK)与PB15(MOSI)
  34.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  35.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;        //复用推挽输出
  36.     GPIO_Init(GPIOB, &GPIO_InitStructure);

  37.     SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;        //全双工
  38.     SPI_InitStruct.SPI_Mode      = SPI_Mode_Master;        //SPI主模式
  39.     SPI_InitStruct.SPI_DataSize  = SPI_DataSize_8b;        //8位数据结构
  40.     SPI_InitStruct.SPI_CPOL      = SPI_CPOL_High;        //时钟极性高
  41.     SPI_InitStruct.SPI_CPHA      = SPI_CPHA_2Edge;        //第二个时钟沿有效
  42.     SPI_InitStruct.SPI_NSS       = SPI_NSS_Soft;        //NSS引脚软件控制
  43.     SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;//定义波特率预分频的值:波特率预分频值为256 SPI_BaudRatePrescaler_64
  44.     SPI_InitStruct.SPI_FirstBit  = SPI_FirstBit_MSB;        //高位先发送
  45.     SPI_InitStruct.SPI_CRCPolynomial = 7;        //CRC校验7
  46.     SPI_Init(SPI2, &SPI_InitStruct);        //初始化
  47.     SPI_Cmd(SPI2, ENABLE);        //使能SPI2
  48. }
  49. /****************************************************
  50. 函数名:SPI_RW_Byte
  51. 形参:  data:发送的数据
  52. 返回值:  temp:读取的数据
  53. 函数功能:使用SPI0读写1Byte
  54. ****************************************************/
  55. u8 SPI_RW_Byte(u8 data)
  56. {
  57.     u8 temp=0;        //定义变量读取数据
  58.     /* 等待发送缓存器空 */
  59.     while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);//检查指定的SPI标志位设置与否:发送缓存空标志位
  60.     /* 发送数据 */
  61.     SPI_I2S_SendData(SPI2, data);
  62. //        /* 等待接收缓存器非空 */
  63.     while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
  64.     /* 接收一字节数据 */
  65.     temp = SPI_I2S_ReceiveData(SPI2);
  66.     return temp;
  67. }
  68. /**
  69.   * @函数名       Delay
  70.   * @功  能       延迟
  71.   * @参  数       data:延迟data
  72.   * @返回值       无
  73.   */
  74. static void Delay(uint32_t data)
  75. {
  76.     while(data--);
  77. }
  78. /****************************************************
  79. 函数名:Write_Command
  80. 形参:  Cmd:发送的命令
  81. 返回值:
  82. 函数功能:往OLED发送命令
  83. ****************************************************/
  84. void Write_Command(unsigned char Cmd)
  85. {
  86.     SPI_NSS_LOW(); //片选拉低,选通器件
  87.     OLED_DC_Clr();  //DC拉低,发送命令
  88.     SPI_RW_Byte(Cmd); //发送数据
  89.     OLED_DC_Set(); //DC拉高,空闲时为高电平
  90.     SPI_NSS_HIGH(); //片选拉高,关闭器件
  91. }
  92. /****************************************************
  93. 函数名:Write_Data
  94. 形参:  Data:发送的数据
  95. 返回值:
  96. 函数功能:往OLED发送数据
  97. ****************************************************/
  98. void Write_Data(unsigned char Data)
  99. {
  100.     SPI_NSS_LOW(); //片选拉低,选通器件
  101.     OLED_DC_Set();  //DC拉高,发送数据
  102.     SPI_RW_Byte(Data); //发送数据
  103.     OLED_DC_Clr();
  104.     SPI_NSS_HIGH(); //片选拉高,关闭器件
  105. }
  106. /****************************************************
  107. 函数名:Set_Column_Address
  108. 形参:  Clo_Start:列起始地址;Clo_End:列结束地址 0-127
  109. 返回值:
  110. 函数功能:设置列地址
  111. ****************************************************/
  112. void Set_Column_Address(unsigned char Clo_Start, unsigned char Clo_End)
  113. {
  114.     Write_Command(0x15);  // 设置列地址
  115.     Write_Data(Clo_Start);  // 列起始地址
  116.     Write_Data(Clo_End);  // 列结束地址
  117. }

  118. /****************************************************
  119. 函数名:Set_Row_Address
  120. 形参:  Row_Start:行起始地址;Row_End:行结束地址
  121. 返回值:
  122. 函数功能:设置行地址
  123. ****************************************************/
  124. void Set_Row_Address(unsigned char Row_Start, unsigned char Row_End)
  125. {
  126.     Write_Command(0x75);  // 设置行地址
  127.     Write_Data(Row_Start);  // 行起始地址
  128.     Write_Data(Row_End);  // 行结束地址
  129. }

  130. /****************************************************
  131. 函数名:Set_Write_RAM
  132. 形参:
  133. 返回值:
  134. 函数功能:使能MCU写RAM
  135. ****************************************************/
  136. void Set_Write_RAM()
  137. {
  138.     Write_Command(0x5C);  //使能MCU写RAM
  139. }

  140. /****************************************************
  141. 函数名:Set_Read_RAM
  142. 形参:
  143. 返回值:
  144. 函数功能:使能MCU读RAM
  145. ****************************************************/
  146. void Set_Read_RAM()
  147. {
  148.     Write_Command(0x5D);  //使能MCU读RAM
  149. }
  150. /****************************************************
  151. 函数名:Fill_RAM
  152. 形参:  Colour_RGB:填充颜色:RRRRRGGGGGGBBBBB
  153. 返回值:
  154. 函数功能:填充全屏(刷屏)
  155. ****************************************************/
  156. void Fill_RAM(int Colour_RGB)
  157. {
  158.     unsigned char i,j;  //定义变量
  159.     Set_Column_Address(0x00,0x7F);  //设置列地址0~127
  160.     Set_Row_Address(0x00,0x7F);   //设置行地址0~127
  161.     Set_Write_RAM();  //使能MCU写RAM
  162.     for(i=0; i<128; i++) //填充128列*128行
  163.     {
  164.         for(j=0; j<128; j++)
  165.         {
  166.             Write_Data(Colour_RGB >> 8);  //写入填充颜色高字节
  167.             Write_Data(Colour_RGB); //写入填充颜色低字节
  168.         }
  169.     }
  170. }
  171. /****************************************************
  172. 函数名:Clear_Screen
  173. 形参:  Var_Row:第Var_Row行
  174. 返回值:
  175. 函数功能:指定某一行清屏(一共8行:0~7)
  176. ****************************************************/
  177. void Clear_Screen(unsigned char Var_Row)
  178. {
  179.     unsigned int i;
  180.     Set_Column_Address(0x00, 0x7F);        //设置列地址0~127
  181.     Set_Row_Address(Var_Row*16, (Var_Row*16 + 15));                //设置行地址
  182.     Set_Write_RAM();        //使能MCU写RAM

  183.     for(i = 0; i < 2048; i++)        //把这一行清屏,点数量 = 16*128 = 2048
  184.     {
  185.         Write_Data(0x00);
  186.         Write_Data(0x00);
  187.     }
  188. }
  189. /****************************************************
  190. 函数名:Draw_Point
  191. 形参:  x:列起始地址;y:行起始地址;Colour_RGB:填充颜色:RRRRRGGGGGGBBBBB
  192. 返回值:
  193. 函数功能:画点
  194. ****************************************************/
  195. void Draw_Point(const unsigned char x, const unsigned char y, int Colour_RGB)
  196. {
  197.     Write_Command(0x15);  // 设置列地址
  198.     Write_Data(x);

  199.     Write_Command(0x75);  // 设置行地址
  200.     Write_Data(y);

  201.     Set_Write_RAM();  //使能MCU写RAM

  202.     Write_Data(Colour_RGB >> 8); //写入填充颜色高字节
  203.     Write_Data(Colour_RGB);  //写入填充颜色低字节
  204. }
  205. /****************************************************
  206. 函数名:Display_Char
  207. 形参:  x:列起始地址;y:行起始地址;Var_Char:写入的字符;Colour_RGB:填充颜色:RRRRRGGGGGGBBBBB
  208. 返回值:
  209. 函数功能:指定坐标画一个字符(逐行式),字符大小固定为8*16
  210. ****************************************************/
  211. void Display_Char(unsigned char x, unsigned char y, unsigned char Var_Char, int Colour_RGB)
  212. {
  213.     unsigned char i, j; //定义变量
  214.     unsigned char Var_Temp, x_Temp; //定义变量

  215.     x_Temp = x; //获取x起始坐标
  216.     for (i = 0; i < 16; i++)
  217.     {
  218.         Var_Temp = ACSII_Font[Var_Char - 0x20][i];  //获取字符在数组的偏移量
  219.         for ( j = 0; j < 8; j++)
  220.         {
  221.             if (Var_Temp & 0x80)  //先画最高位的点,为1则画对应的颜色
  222.                 Draw_Point(x, y, Colour_RGB);
  223.             //else
  224.             //Draw_Point(x, y, 0x0000); //为0则黑色(都不亮),可作为背景色

  225.             Var_Temp <<= 1; //移位,准备画下一个点
  226.             x++;  //x坐标加1

  227.             if((x - x_Temp) == 8)
  228.             {
  229.                 x = x_Temp; //x坐标回到起始位置
  230.                 y++;  //y坐标加1
  231.                 break;  //退出当前循环
  232.             }
  233.         }
  234.     }
  235. }
  236. /****************************************************
  237. 函数名:Display_String
  238. 形参:  x:列起始地址;y:行起始地址;*chr:显示的字符串;Colour_RGB:填充颜色:RRRRRGGGGGGBBBBB
  239. 返回值:
  240. 函数功能:显示字符串
  241. ****************************************************/
  242. void Display_String(unsigned char x, unsigned char y, unsigned char *chr, int Colour_RGB)
  243. {
  244.     unsigned char i = 0;  //定义变量

  245.     while(chr[i] != '\0') //判断是否结束
  246.     {
  247.         Display_Char(x, y, chr[i], Colour_RGB); //显示字符
  248.         x += 8; //x坐标加8(一个字符x方向占8个点,Y方向占16个点)
  249.         i++;  //下一个字符
  250.     }
  251. }
  252. /****************************************************
  253. 函数名:Display_Circle
  254. 形参:  圆心:(x0, y0) 半径:r;Colour_RGB:填充颜色:RRRRRGGGGGGBBBBB
  255. 返回值:
  256. 函数功能:显示空心圆圈
  257. ****************************************************/
  258. void Display_Circle(const u8 x,const u8 y,const u8 r, int Colour_RGB)
  259. {
  260.     int a, b, num;
  261.     a = 0;
  262.     b = r;
  263.     while(2 * b * b >= r * r)          // 1/8圆即可
  264.     {
  265.         Draw_Point(x + a, y - b+2,Colour_RGB); // 0~1
  266.         Draw_Point(x + b-2, y + a,Colour_RGB); // 2~3 00000
  267.         Draw_Point(x - a, y + b-2,Colour_RGB); // 4~5
  268.         Draw_Point(x - b+2, y - a,Colour_RGB); // 6~7
  269.         Draw_Point(x + b-2, y - a,Colour_RGB); // 2~1
  270.         Draw_Point(x + a, y + b-2,Colour_RGB); // 4~3   
  271.         Draw_Point(x - b+2, y + a,Colour_RGB); // 6~5  
  272.         Draw_Point(x - a, y - b+2,Colour_RGB); // 0~7
  273.          
  274.         a++;
  275.         num = (a * a + b * b) - r*r;
  276.         if(num > 0)
  277.         {
  278.             a--;
  279.             b--;
  280.         }
  281.     }
  282. }
  283. /****************************************************
  284. 函数名:Display_Circle2
  285. 形参:  圆心:(x0, y0) 半径:r;Colour_RGB:填充颜色:RRRRRGGGGGGBBBBB
  286. 返回值:
  287. 函数功能:显示空心圆圈算法2
  288. ****************************************************/
  289. void Display_Circle2(u8 x,u8 y,u8 r,int Colour_RGB)
  290. {
  291.     int tx,ty;
  292.     double d =0.0;
  293.     tx = 0;
  294.     ty = r;
  295.     d = 1.25 - r;

  296.     while(tx<=ty)
  297.     {
  298.         Draw_Point(x + tx,y - ty, Colour_RGB);//0-1
  299.         Draw_Point(x + ty,y - tx, Colour_RGB);//1-2
  300.         Draw_Point(x + ty,y + tx, Colour_RGB);//2-3
  301.         Draw_Point(x + tx,y + ty, Colour_RGB);//3-4
  302.         Draw_Point(x - tx,y + ty, Colour_RGB);//4-5
  303.         Draw_Point(x - ty,y + tx, Colour_RGB);//5-6
  304.         Draw_Point(x - ty,y - tx, Colour_RGB);//6-7
  305.         Draw_Point(x - tx,y - ty, Colour_RGB);//7-0

  306.         if(d<0)
  307.         {
  308.             d += 2*tx+3;
  309.         }
  310.         else
  311.         {
  312.             d += 2*(tx-ty)+5;
  313.             ty--;
  314.         }
  315.         tx++;
  316.     }
  317. }
  318. /****************************************************
  319. 函数名:Display_Fill_Circle
  320. 形参:  圆心:(x0, y0) 半径:r;Colour_RGB:填充颜色:RRRRRGGGGGGBBBBB
  321. 返回值:
  322. 函数功能:显示实心圆圈
  323. ****************************************************/
  324. void Display_Fill_Circle(const u8 x0,const u8 y0,const u8 r,int Colour_RGB)//写画实心圆心(x0,y0),半径r
  325. {
  326.     u8 x = 0,y = 0,R = 0;
  327.     for(x = x0-r; x <= x0+r; x++)
  328.     {
  329.         for(y = y0-r; y <= y0+r ; y++ )
  330.         {

  331.             R = sqrt(pow(r,2)-pow(x-x0,2))+y0; //圆方程  x,y反置
  332.             if( (y >= y0 && y <= R) || (y < y0 && y >= 2*y0-R))
  333.             {
  334.                 //点限制在 圆方程内
  335.                 Draw_Point(y,x,Colour_RGB);
  336.             }
  337.         }
  338.     }
  339. }
  340. /****************************************************
  341. 函数名:Display_Chinese
  342. 形参:  x:列起始地址;y:行起始地址;Var_Char:汉字在数组的下标;Colour_RGB:填充颜色:RRRRRGGGGGGBBBBB
  343. 返回值:
  344. 函数功能:指定坐标画一个字符(逐行式),字符大小固定为16*16
  345. ****************************************************/
  346. void Display_Chinese16x16(unsigned char x, unsigned char y, unsigned char Var_Char, int Colour_RGB)
  347. {
  348.     unsigned char i, j; //定义变量
  349.     unsigned char Var_Temp, x_Temp; //定义变量

  350.     x_Temp = x; //获取x起始坐标
  351.     for(i = 0; i < 32; i++) //16*16 = 32*8;一次只能写入一字节,也就是8位,所以采用8*32的画法
  352.     {
  353.         Var_Temp = Chinese_Font[Var_Char][i]; //获取汉字在数组的偏移量
  354.         for(j = 0; j < 8; j++)
  355.         {
  356.             if(Var_Temp & 0x80)   //先画最高位的点,为1则画对应的颜色
  357.                 Draw_Point(x, y, Colour_RGB);
  358.             //else
  359.             //Draw_Point(x, y, 0x0000); //为0则黑色(都不亮),可作为背景色
  360.             Var_Temp <<= 1; //移位,准备画下一个点
  361.             x++;  //x坐标加1

  362.             if((x - x_Temp) == 16)  //画完一列
  363.             {
  364.                 x = x_Temp; //x坐标回到起始位置
  365.                 y++;  //y坐标加1
  366.                 break;  //退出当前循环
  367.             }
  368.         }
  369.     }
  370. }
  371. /****************************************************
  372. 函数名:Display_Chinese
  373. 形参:  x:列起始地址;y:行起始地址;Var_Char:汉字在数组的下标;Colour_RGB:填充颜色:RRRRRGGGGGGBBBBB
  374. 返回值:
  375. 函数功能:指定坐标画一个字符(逐行式),字符大小固定为12*12
  376. ****************************************************/
  377. void Display_Chinese12x12(unsigned char x, unsigned char y, unsigned char Var_Char, int Colour_RGB)
  378. {
  379.     unsigned char i, j; //定义变量
  380.     unsigned char Var_Temp, x_Temp; //定义变量

  381.     x_Temp = x; //获取x起始坐标
  382.     for(i = 0; i < 24; i++) //12*12 = 18*8;一次只能写入一字节,也就是8位,所以采用8*18的画法
  383.     {
  384.         Var_Temp = Chinese_Font_12[Var_Char][i]; //获取汉字在数组的偏移量
  385.         for(j = 0; j < 8; j++)
  386.         {
  387.             if(Var_Temp & 0x80)   //先画最高位的点,为1则画对应的颜色
  388.                 Draw_Point(x, y, Colour_RGB);
  389.             //else
  390.             //Draw_Point(x, y, 0x0000); //为0则黑色(都不亮),可作为背景色
  391.             Var_Temp <<= 1; //移位,准备画下一个点
  392.             x++;  //x坐标加1

  393.             if((x - x_Temp) == 12)  //画完一列
  394.             {
  395.                 x = x_Temp; //x坐标回到起始位置
  396.                 y++;  //y坐标加1
  397.                 break;  //退出当前循环
  398.             }
  399.         }
  400.     }
  401. }
  402. /****************************************************
  403. 函数名:Num_Pow
  404. 形参:  m:底数;n:指数
  405. 返回值:
  406. 函数功能:m^n幂运算
  407. ****************************************************/
  408. uint32_t Num_Pow(unsigned char m,unsigned char n)
  409. {
  410.     uint32_t result=1; //定义变量

  411.     while(n--)result*=m;  //m^n
  412.     return result;  //返回结果
  413. }

  414. /****************************************************
  415. 函数名:Display_Num
  416. 形参:  x:列起始地址;y:行起始地址;Var_Num:显示的数字;Num_Len:数字长度;Colour_RGB:填充颜色:RRRRRGGGGGGBBBBB
  417. 返回值:
  418. 函数功能:显示数字
  419. ****************************************************/
  420. void Display_Num(unsigned char x,unsigned char y,int Var_Num, unsigned char Num_Len, int Colour_RGB)
  421. {
  422.     unsigned char i;  //定义变量
  423.     unsigned char Var_Temp;   //定义变量
  424.     unsigned char Var_Show = 0; //定义变量

  425.     for(i = 0; i < Num_Len; i++)  //显示数字
  426.     {
  427.         Var_Temp  =  (Var_Num / Num_Pow(10, Num_Len-i-1)) % 10;  //获取最高位(数字显示是一位一位取出来再显示)
  428.         if(Var_Show == 0 && i<(Num_Len - 1))  //判断首位数字是否为0
  429.         {
  430.             if(Var_Temp == 0)
  431.             {
  432.                 Display_Char(x+8*i, y, ' ', Colour_RGB);  //首位数据为0则不显示
  433.                 continue; //继续循环
  434.             }
  435.             else
  436.                 Var_Show = 1; //后面的数字正常显示
  437.         }

  438.         Display_Char(x+8*i, y, Var_Temp + '0', Colour_RGB); //显示数字
  439.     }
  440. }
  441. /****************************************************
  442. 函数名:Display_Pattern
  443. 形参:  *Pattern_Data:图片数组;Start_x:x方向起点;End_x:x方向终点;Start_y:y方向起点;End_y:y方向终点
  444. 返回值:
  445. 函数功能:显示图片
  446. ****************************************************/
  447. void Display_Pattern(unsigned char *Pattern_Data, unsigned char Start_x, unsigned char End_x, unsigned char Start_y, unsigned char End_y)
  448. {
  449.     unsigned char *Data_Pointer;        //定义指针变量
  450.     unsigned char i, j;                //定义变量
  451.     Data_Pointer = Pattern_Data;        //获取数组首地址
  452.     Set_Column_Address(Start_x, End_x);        //设置列范围
  453.     Set_Row_Address(Start_y, End_y);        //设置行范围
  454.     Set_Write_RAM();        //设置MCU写RAM

  455.     for(i = 0; i < (End_y - Start_y + 1); i++)        //y方向(End_y - Start_y + 1)
  456.     {
  457.         for(j = 0; j < (End_x - Start_x + 1); j++)        //x方向(End_x - Start_x + 1)
  458.         {
  459.             Write_Data(*Data_Pointer);        //写入数据(一个点需要写入16位数据:RRRRRGGGGGGBBBBB)
  460.             Data_Pointer++;
  461.             Write_Data(*Data_Pointer);
  462.             Data_Pointer++;
  463.         }
  464.     }
  465. }
  466. /****************************************************
  467. 函数名:Set_Gray_Scale_Table
  468. 形参:
  469. 返回值:
  470. 函数功能:灰阶表设置
  471. ****************************************************/
  472. void Set_Gray_Scale_Table(void)
  473. {
  474.     Write_Command(0xB8);
  475.     Write_Data(0x02);     // Gray Scale Level 1
  476.     Write_Data(0x03);     // Gray Scale Level 2
  477.     Write_Data(0x04);     // Gray Scale Level 3
  478.     Write_Data(0x05);     // Gray Scale Level 4
  479.     Write_Data(0x06);     // Gray Scale Level 5
  480.     Write_Data(0x07);     // Gray Scale Level 6
  481.     Write_Data(0x08);     // Gray Scale Level 7
  482.     Write_Data(0x09);     // Gray Scale Level 8
  483.     Write_Data(0x0A);     // Gray Scale Level 9
  484.     Write_Data(0x0B);     // Gray Scale Level 10
  485.     Write_Data(0x0C);     // Gray Scale Level 11
  486.     Write_Data(0x0D);     // Gray Scale Level 12
  487.     Write_Data(0x0E);     // Gray Scale Level 13
  488.     Write_Data(0x0F);     // Gray Scale Level 14
  489.     Write_Data(0x10);     // Gray Scale Level 15
  490.     Write_Data(0x11);     // Gray Scale Level 16
  491.     Write_Data(0x12);     // Gray Scale Level 17
  492.     Write_Data(0x13);     // Gray Scale Level 18
  493.     Write_Data(0x15);     // Gray Scale Level 19
  494.     Write_Data(0x17);     // Gray Scale Level 20
  495.     Write_Data(0x19);     // Gray Scale Level 21
  496.     Write_Data(0x1B);     // Gray Scale Level 22
  497.     Write_Data(0x1D);     // Gray Scale Level 23
  498.     Write_Data(0x1F);     // Gray Scale Level 24
  499.     Write_Data(0x21);     // Gray Scale Level 25
  500.     Write_Data(0x23);     // Gray Scale Level 26
  501.     Write_Data(0x25);     // Gray Scale Level 27
  502.     Write_Data(0x27);     // Gray Scale Level 28
  503.     Write_Data(0x2A);     // Gray Scale Level 29
  504.     Write_Data(0x2D);     // Gray Scale Level 30
  505.     Write_Data(0x30);     // Gray Scale Level 31
  506.     Write_Data(0x33);     // Gray Scale Level 32
  507.     Write_Data(0x36);     // Gray Scale Level 33
  508.     Write_Data(0x39);     // Gray Scale Level 34
  509.     Write_Data(0x3C);     // Gray Scale Level 35
  510.     Write_Data(0x3F);     // Gray Scale Level 36
  511.     Write_Data(0x42);     // Gray Scale Level 37
  512.     Write_Data(0x45);     // Gray Scale Level 38
  513.     Write_Data(0x48);     // Gray Scale Level 39
  514.     Write_Data(0x4C);     // Gray Scale Level 40
  515.     Write_Data(0x50);     // Gray Scale Level 41
  516.     Write_Data(0x54);     // Gray Scale Level 42
  517.     Write_Data(0x58);     // Gray Scale Level 43
  518.     Write_Data(0x5C);     // Gray Scale Level 44
  519.     Write_Data(0x60);     // Gray Scale Level 45
  520.     Write_Data(0x64);     // Gray Scale Level 46
  521.     Write_Data(0x68);     // Gray Scale Level 47
  522.     Write_Data(0x6C);     // Gray Scale Level 48
  523.     Write_Data(0x70);     // Gray Scale Level 49
  524.     Write_Data(0x74);     // Gray Scale Level 50
  525.     Write_Data(0x78);     // Gray Scale Level 51
  526.     Write_Data(0x7D);     // Gray Scale Level 52
  527.     Write_Data(0x82);     // Gray Scale Level 53
  528.     Write_Data(0x87);     // Gray Scale Level 54
  529.     Write_Data(0x8C);     // Gray Scale Level 55
  530.     Write_Data(0x91);     // Gray Scale Level 56
  531.     Write_Data(0x96);     // Gray Scale Level 57
  532.     Write_Data(0x9B);     // Gray Scale Level 58
  533.     Write_Data(0xA0);     // Gray Scale Level 59
  534.     Write_Data(0xA5);     // Gray Scale Level 60
  535.     Write_Data(0xAA);     // Gray Scale Level 61
  536.     Write_Data(0xAF);     // Gray Scale Level 62
  537.     Write_Data(0xB4);     // Gray Scale Level 63
  538. }
  539. /****************************************************
  540. 函数名:OLED_Init
  541. 形参:
  542. 返回值:
  543. 函数功能:OLED显示初始化
  544. ****************************************************/
  545. void OLED_Init(void)
  546. {
  547.     OLED_GPIO_Init();     //初始化RES、DC与CS引脚

  548.     SPI_NSS_LOW();
  549.     Delay(100);
  550.     OLED_RES_Clr();
  551.     Delay(500);
  552.     OLED_RES_Set();
  553.     Delay(500); //延迟,由于单片机上电初始化比OLED快,所以必须加上延迟,等待OLED上电初始化完成

  554.     Write_Command(0xFD);  // 解锁OLED驱动IC(SSD1351)的命令输入
  555.     Write_Data(0x12);

  556.     Write_Command(0xFD);  //设置 命令:A2,B1,B3,BB,BE 为可访问状态
  557.     Write_Data(0xB1);

  558.     Write_Command(0xAE);  //关显示(进入睡眠模式)
  559.     Write_Command(0xA4);  //Normal Display mode

  560.     Write_Command(0x15);        //set column address
  561.     Write_Data(0x00);     //column address start 00
  562.     Write_Data(0x7f);     //column address end 95
  563.     Write_Command(0x75);        //set row address
  564.     Write_Data(0x00);     //row address start 00
  565.     Write_Data(0x7f);     //row address end 63

  566.     Write_Command(0xB3);  //设置显示时钟分频&内部振荡器频率
  567.     Write_Data(0xF1);   //时钟2分频,振荡器频率最高

  568.     Write_Command(0xCA);  //设置 MUX Ratio
  569.     Write_Data(0x7F);   //128


  570.     Write_Command(0xA0);  //设置重映射格式
  571.     Write_Data(0x74);   //水平地址增长模式、列地址0映射到SEG0、颜色数据传输顺序D[15:0] = [RRRRR:GGGGGG:BBBBB]、扫描方向:COM127~COM0、使能奇偶分离、颜色模式65K

  572.     Write_Command(0xA1);  //设置显示起始行
  573.     Write_Data(0x00);   //0x00

  574.     Write_Command(0xA2);  //设置显示偏移
  575.     Write_Data(0x00);   //无偏移

  576.     Write_Command(0xAB);  //功能选择设置
  577.     Write_Data(0x01);   //使能VDD内部稳压器、选择8位并行接口

  578.     Write_Command(0xB4);  //VSL设置
  579.     Write_Data(0xA0);   //使能外部VSL
  580.     Write_Data(0xB5);
  581.     Write_Data(0x55);

  582.     Write_Command(0xC1);  //设置色彩的对比电流
  583.     Write_Data(0xC8);   //A-->Red
  584.     Write_Data(0x80);   //B-->Green
  585.     Write_Data(0xC0);   //C-->Blue

  586.     Write_Command(0xC7);  //主对比度电流控制
  587.     Write_Data(0x0f);   //0x0f

  588.     Write_Command(0xB1);  //设置阶段1(复位阶段)&阶段2(预充电)的周期
  589.     Write_Data(0x32);   //阶段1为5个时钟周期、阶段2为3个时钟周期

  590.     Write_Command(0xB2);
  591.     Write_Data(0xA4);
  592.     Write_Data(0x00);
  593.     Write_Data(0x00);

  594.     Write_Command(0xBB);  //设置预充电电压
  595.     Write_Data(0x17);   //0.5*VCC Set_Gray_Scale_Table(); // 设置灰度表脉冲宽度

  596.     Write_Command(0xB6);  //设置Second预充周期
  597.     Write_Data(0x01);   //1个时钟周期(1DCLKS)

  598.     Write_Command(0xBE);  //设置VCOMH电压
  599.     Write_Data(0x05);   //0.82*VCC

  600.     Write_Command(0xA6);  //设置显示模式:正常模式

  601.     Fill_RAM(0x0000);  //清屏

  602.     Write_Command(0xAF);  //开显示
  603. }

 楼主| 原来是wjc 发表于 2022-12-27 16:41 | 显示全部楼层
  1. /*font.h*/
  2. #ifndef __FONT_H
  3. #define __FONT_H
  4. /************************************16*8的ACSII表************************************/
  5. const unsigned char ACSII_Font[][16] = {
  6.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",32*/
  7.     {0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x10,0x10,0x00,0x00},/*"!",33*/
  8.     {0x00,0x12,0x24,0x24,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*""",34*/
  9.     {0x00,0x00,0x00,0x12,0x12,0x12,0x7E,0x24,0x24,0x24,0x7E,0x24,0x24,0x24,0x00,0x00},/*"#",35*/
  10.     {0x00,0x00,0x08,0x3C,0x4A,0x4A,0x48,0x38,0x0C,0x0A,0x0A,0x4A,0x4A,0x3C,0x08,0x08},/*"$",36*/
  11.     {0x00,0x00,0x00,0x44,0xA4,0xA8,0xA8,0xB0,0x54,0x1A,0x2A,0x2A,0x4A,0x44,0x00,0x00},/*"%",37*/
  12.     {0x00,0x00,0x00,0x30,0x48,0x48,0x48,0x50,0x6E,0xA4,0x94,0x98,0x89,0x76,0x00,0x00},/*"&",38*/
  13.     {0x00,0x60,0x20,0x20,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",39*/
  14.     {0x00,0x02,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x08,0x04,0x02,0x00},/*"(",40*/
  15.     {0x00,0x40,0x20,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x10,0x20,0x40,0x00},/*")",41*/
  16.     {0x00,0x00,0x00,0x00,0x10,0x10,0xD6,0x38,0x38,0xD6,0x10,0x10,0x00,0x00,0x00,0x00},/*"*",42*/
  17.     {0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x7F,0x08,0x08,0x08,0x00,0x00,0x00,0x00},/*"+",43*/
  18.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x20,0x20,0x40},/*",",44*/
  19.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",45*/
  20.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00},/*".",46*/
  21.     {0x00,0x00,0x02,0x04,0x04,0x04,0x08,0x08,0x10,0x10,0x10,0x20,0x20,0x40,0x40,0x00},/*"/",47*/
  22.     {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",48*/
  23.     {0x00,0x00,0x00,0x08,0x38,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"1",49*/
  24.     {0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x02,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00},/*"2",50*/
  25.     {0x00,0x00,0x00,0x3C,0x42,0x42,0x02,0x04,0x18,0x04,0x02,0x42,0x42,0x3C,0x00,0x00},/*"3",51*/
  26.     {0x00,0x00,0x00,0x04,0x0C,0x0C,0x14,0x24,0x24,0x44,0x7F,0x04,0x04,0x1F,0x00,0x00},/*"4",52*/
  27.     {0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x78,0x44,0x02,0x02,0x42,0x44,0x38,0x00,0x00},/*"5",53*/
  28.     {0x00,0x00,0x00,0x18,0x24,0x40,0x40,0x5C,0x62,0x42,0x42,0x42,0x22,0x1C,0x00,0x00},/*"6",54*/
  29.     {0x00,0x00,0x00,0x7E,0x42,0x04,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x00,0x00},/*"7",55*/
  30.     {0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00},/*"8",56*/
  31.     {0x00,0x00,0x00,0x38,0x44,0x42,0x42,0x42,0x46,0x3A,0x02,0x02,0x24,0x18,0x00,0x00},/*"9",57*/
  32.     {0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00},/*":",58*/
  33.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10},/*";",59*/
  34.     {0x00,0x00,0x00,0x02,0x04,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x04,0x02,0x00,0x00},/*"<",60*/
  35.     {0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00},/*"=",61*/
  36.     {0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x20,0x40,0x00,0x00},/*">",62*/
  37.     {0x00,0x00,0x00,0x3C,0x42,0x42,0x62,0x04,0x08,0x08,0x08,0x00,0x18,0x18,0x00,0x00},/*"?",63*/
  38.     {0x00,0x00,0x00,0x38,0x44,0x5A,0xAA,0xAA,0xAA,0xAA,0xAA,0x5C,0x42,0x3C,0x00,0x00},/*"@",64*/
  39.     {0x00,0x00,0x00,0x10,0x10,0x18,0x28,0x28,0x24,0x3C,0x44,0x42,0x42,0xE7,0x00,0x00},/*"A",65*/
  40.     {0x00,0x00,0x00,0xF8,0x44,0x44,0x44,0x78,0x44,0x42,0x42,0x42,0x44,0xF8,0x00,0x00},/*"B",66*/
  41.     {0x00,0x00,0x00,0x3E,0x42,0x42,0x80,0x80,0x80,0x80,0x80,0x42,0x44,0x38,0x00,0x00},/*"C",67*/
  42.     {0x00,0x00,0x00,0xF8,0x44,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x44,0xF8,0x00,0x00},/*"D",68*/
  43.     {0x00,0x00,0x00,0xFC,0x42,0x48,0x48,0x78,0x48,0x48,0x40,0x42,0x42,0xFC,0x00,0x00},/*"E",69*/
  44.     {0x00,0x00,0x00,0xFC,0x42,0x48,0x48,0x78,0x48,0x48,0x40,0x40,0x40,0xE0,0x00,0x00},/*"F",70*/
  45.     {0x00,0x00,0x00,0x3C,0x44,0x44,0x80,0x80,0x80,0x8E,0x84,0x44,0x44,0x38,0x00,0x00},/*"G",71*/
  46.     {0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"H",72*/
  47.     {0x00,0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},/*"I",73*/
  48.     {0x00,0x00,0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x88,0xF0},/*"J",74*/
  49.     {0x00,0x00,0x00,0xEE,0x44,0x48,0x50,0x70,0x50,0x48,0x48,0x44,0x44,0xEE,0x00,0x00},/*"K",75*/
  50.     {0x00,0x00,0x00,0xE0,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x42,0xFE,0x00,0x00},/*"L",76*/
  51.     {0x00,0x00,0x00,0xEE,0x6C,0x6C,0x6C,0x6C,0x6C,0x54,0x54,0x54,0x54,0xD6,0x00,0x00},/*"M",77*/
  52.     {0x00,0x00,0x00,0xC7,0x62,0x62,0x52,0x52,0x4A,0x4A,0x4A,0x46,0x46,0xE2,0x00,0x00},/*"N",78*/
  53.     {0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x44,0x38,0x00,0x00},/*"O",79*/
  54.     {0x00,0x00,0x00,0xFC,0x42,0x42,0x42,0x42,0x7C,0x40,0x40,0x40,0x40,0xE0,0x00,0x00},/*"P",80*/
  55.     {0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x82,0x82,0x82,0xB2,0x4C,0x38,0x06,0x00},/*"Q",81*/
  56.     {0x00,0x00,0x00,0xFC,0x42,0x42,0x42,0x7C,0x48,0x48,0x44,0x44,0x42,0xE3,0x00,0x00},/*"R",82*/
  57.     {0x00,0x00,0x00,0x3E,0x42,0x42,0x40,0x20,0x18,0x04,0x02,0x42,0x42,0x7C,0x00,0x00},/*"S",83*/
  58.     {0x00,0x00,0x00,0xFE,0x92,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00},/*"T",84*/
  59.     {0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00},/*"U",85*/
  60.     {0x00,0x00,0x00,0xE7,0x42,0x42,0x44,0x24,0x24,0x28,0x28,0x18,0x10,0x10,0x00,0x00},/*"V",86*/
  61.     {0x00,0x00,0x00,0xD6,0x54,0x54,0x54,0x54,0x54,0x6C,0x28,0x28,0x28,0x28,0x00,0x00},/*"W",87*/
  62.     {0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x18,0x18,0x18,0x24,0x24,0x42,0xE7,0x00,0x00},/*"X",88*/
  63.     {0x00,0x00,0x00,0xEE,0x44,0x44,0x28,0x28,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00},/*"Y",89*/
  64.     {0x00,0x00,0x00,0x7E,0x84,0x04,0x08,0x08,0x10,0x20,0x20,0x42,0x42,0xFC,0x00,0x00},/*"Z",90*/
  65.     {0x00,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1E,0x00},/*"[",91*/
  66.     {0x00,0x00,0x40,0x20,0x20,0x20,0x10,0x10,0x10,0x08,0x08,0x04,0x04,0x04,0x02,0x02},/*"",92*/
  67.     {0x00,0x78,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x78,0x00},/*"]",93*/
  68.     {0x00,0x18,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",94*/
  69.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF},/*"_",95*/
  70.     {0x00,0x60,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"`",96*/
  71.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x0C,0x34,0x44,0x4C,0x36,0x00,0x00},/*"a",97*/
  72.     {0x00,0x00,0x00,0x00,0xC0,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x64,0x58,0x00,0x00},/*"b",98*/
  73.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x22,0x40,0x40,0x40,0x22,0x1C,0x00,0x00},/*"c",99*/
  74.     {0x00,0x00,0x00,0x00,0x06,0x02,0x02,0x3E,0x42,0x42,0x42,0x42,0x46,0x3B,0x00,0x00},/*"d",100*/
  75.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x7E,0x40,0x42,0x3C,0x00,0x00},/*"e",101*/
  76.     {0x00,0x00,0x00,0x00,0x0C,0x12,0x10,0x7C,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},/*"f",102*/
  77.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x44,0x44,0x38,0x40,0x3C,0x42,0x42,0x3C},/*"g",103*/
  78.     {0x00,0x00,0x00,0x00,0xC0,0x40,0x40,0x5C,0x62,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"h",104*/
  79.     {0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x70,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},/*"i",105*/
  80.     {0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x1C,0x04,0x04,0x04,0x04,0x04,0x04,0x44,0x78},/*"j",106*/
  81.     {0x00,0x00,0x00,0x00,0xC0,0x40,0x40,0x4E,0x48,0x50,0x70,0x48,0x44,0xEE,0x00,0x00},/*"k",107*/
  82.     {0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},/*"l",108*/
  83.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x49,0x49,0x49,0x49,0x49,0xED,0x00,0x00},/*"m",109*/
  84.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xDC,0x62,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"n",110*/
  85.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00},/*"o",111*/
  86.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD8,0x64,0x42,0x42,0x42,0x64,0x58,0x40,0xE0},/*"p",112*/
  87.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1A,0x26,0x42,0x42,0x42,0x26,0x1A,0x02,0x07},/*"q",113*/
  88.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEE,0x32,0x20,0x20,0x20,0x20,0xF8,0x00,0x00},/*"r",114*/
  89.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x42,0x40,0x3C,0x02,0x42,0x7C,0x00,0x00},/*"s",115*/
  90.     {0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x7C,0x10,0x10,0x10,0x10,0x12,0x0C,0x00,0x00},/*"t",116*/
  91.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC6,0x42,0x42,0x42,0x42,0x46,0x3B,0x00,0x00},/*"u",117*/
  92.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEE,0x44,0x44,0x28,0x28,0x10,0x10,0x00,0x00},/*"v",118*/
  93.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xDB,0x89,0x4A,0x5A,0x54,0x24,0x24,0x00,0x00},/*"w",119*/
  94.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x24,0x18,0x18,0x18,0x24,0x6E,0x00,0x00},/*"x",120*/
  95.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x18,0x18,0x10,0x10,0x60},/*"y",121*/
  96.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x44,0x08,0x10,0x10,0x22,0x7E,0x00,0x00},/*"z",122*/
  97.     {0x00,0x03,0x04,0x04,0x04,0x04,0x04,0x04,0x08,0x04,0x04,0x04,0x04,0x04,0x03,0x00},/*"{",123*/
  98.     {0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08},/*"|",124*/
  99.     {0x00,0xC0,0x20,0x20,0x20,0x20,0x20,0x20,0x10,0x20,0x20,0x20,0x20,0x20,0xC0,0x00},/*"}",125*/
  100.     {0x20,0x5A,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"~",126*/
  101.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"",127*/
  102. };
  103. /************************************16*16的汉字码表************************************/
  104. const unsigned char Chinese_Font[][32] = {
  105.     0x00,0x08,0x00,0x08,0x7C,0x08,0x44,0x08,0x45,0xFE,0x44,0x08,0x44,0x08,0x7C,0x08,
  106.     0x44,0x88,0x44,0x48,0x44,0x48,0x44,0x08,0x7C,0x08,0x44,0x08,0x00,0x28,0x00,0x10,/*"时",0*/

  107.     0x20,0x00,0x13,0xFC,0x10,0x04,0x40,0x04,0x47,0xC4,0x44,0x44,0x44,0x44,0x44,0x44,
  108.     0x47,0xC4,0x44,0x44,0x44,0x44,0x44,0x44,0x47,0xC4,0x40,0x04,0x40,0x14,0x40,0x08,/*"间",1*/
  109. };

  110. /************************************12*12的汉字码表************************************/
  111. const unsigned char Chinese_Font_12[][24] = {
  112.     0x00,0x40,0xF0,0x40,0x90,0x40,0x97,0xE0,0x90,0x40,0xF0,0x40,0x92,0x40,0x91,0x40,
  113.     0x91,0x40,0xF0,0x40,0x90,0x40,0x01,0xC0,/*"时",0*/

  114.     0x4F,0xE0,0x20,0x20,0x00,0x20,0x5F,0xA0,0x50,0xA0,0x50,0xA0,0x5F,0xA0,0x50,0xA0,
  115.     0x50,0xA0,0x5F,0xA0,0x40,0x20,0x40,0xE0,/*"间",1*/
  116. };


  117. #endif

 楼主| 原来是wjc 发表于 2022-12-27 16:42 | 显示全部楼层
图片数组自己取模使用函数调用就好
  1. /*main.c*/
  2. #include "ssd1351.h"
  3. #include "font.h"
  4. int main(void)
  5. {

  6.     SPI2_Init();//显示SPI初始化
  7.     OLED_Init();//初始化OLED屏幕
  8.     Fill_RAM(0x0000);        //清屏
  9.     Display_Pattern(gImage_bck0, 0, 127, 0, 127);//图片需要自己取模更换
  10.     Display_Chinese12x12(52,  114, 2, 0X0BFF);        //显示汉字/*"时",2*/
  11.     Display_Chinese12x12(64,  114, 3, 0X0BFF);        //显示汉字/*"间",3*/
  12.     Display_Circle(63,58,38,0x09FF);
  13. }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

87

主题

1250

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部