查看: 661|回复: 1

【瑞萨RA4系列开发板体验】OLED电压表

[复制链接]

116

主题

133

帖子

3768

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3768
发表于 2023-2-2 13:22:03 | 显示全部楼层 |阅读模式
【瑞萨RA4系列开发板体验】OLED电压表
作者:lugl

前面有大佬驱动OLED,但是有点小问题,我这里解决了。
【学习资料】
1、[color=rgb(12, 147, 228) !important]【瑞萨RA4系列开发板体验】硬件iic点亮oled屏幕 - 瑞萨单片机论坛 - 电子技术论坛 - 广受欢迎的专业电子论坛! (elecfans.com)
2、[color=rgb(12, 147, 228) !important](76条消息) 瑞萨e2studio(17)----IIC,12864OLED移植_记帖的博客-CSDN博客
【实现步骤】
在前面ADC的基础上增加OLED模块
1、打开配置工具,添加i2c_master
2、按下图设置:

3、按下面配置管脚:

4、同步生成工程,回到keil。
5、新建oled.c,oled.h,oledfont.h并加入到工程中:

具体函数内容如下:
oled.c:
  1. #include "oled.h"
  2. #include "stdlib.h"
  3. #include "oledfont.h"

  4. #include "hal_data.h"
  5. fsp_err_t err;
  6. int  timeout_ms = 1000;
  7. i2c_master_event_t i2c_event ;
  8. //OLED的显存
  9. //存放格式如下.
  10. //[0]0 1 2 3 ... 127
  11. //[1]0 1 2 3 ... 127
  12. //[2]0 1 2 3 ... 127
  13. //[3]0 1 2 3 ... 127
  14. //[4]0 1 2 3 ... 127
  15. //[5]0 1 2 3 ... 127
  16. //[6]0 1 2 3 ... 127
  17. //[7]0 1 2 3 ... 127
  18. void IIC_Master_callback(i2c_master_callback_args_t *p_args)
  19. {
  20.     i2c_event = I2C_MASTER_EVENT_ABORTED;
  21.     if (NULL != p_args)
  22.     {
  23.         /* capture callback event for validating the i2c transfer event*/
  24.         i2c_event = p_args->event;
  25.     }
  26. }

  27. /**********************************************
  28. // IIC Write Command
  29. **********************************************/
  30. void Write_IIC_Command(unsigned char IIC_Command)
  31. {
  32.     uint8_t ii[2]={0x00,0x00};            
  33.     ii[1]=IIC_Command;            
  34.     err = R_IIC_MASTER_Write(&g_i2c_master0_ctrl, ii, 0x02, true);
  35.     assert(FSP_SUCCESS == err);            
  36.     /* Since there is nothing else to do, block until Callback triggers*/
  37.     while ((I2C_MASTER_EVENT_TX_COMPLETE != i2c_event) && timeout_ms>0)
  38.     {                    
  39.         R_BSP_SoftwareDelay(1U, BSP_DELAY_UNITS_MICROSECONDS);
  40.         timeout_ms--;            
  41.     }            
  42.     if (I2C_MASTER_EVENT_ABORTED == i2c_event)            
  43.     {                    
  44.         __BKPT(0);            
  45.     }            
  46.     /* Read data back from the I2C slave */            
  47.     i2c_event = I2C_MASTER_EVENT_ABORTED;            
  48.     timeout_ms           = 1000;   
  49. }

  50. /**********************************************
  51. // IIC Write Data
  52. **********************************************/
  53. void Write_IIC_Data(unsigned char IIC_Data)
  54. {
  55.     uint8_t ii[2]={0x40,0x00};
  56.     ii[0] = 0x40;
  57.     ii[1]=IIC_Data;
  58.     err = R_IIC_MASTER_Write(&g_i2c_master0_ctrl, ii, 0x02, true);

  59.     assert(FSP_SUCCESS == err);            
  60.     /* Since there is nothing else to do, block until Callback triggers*/            
  61.     while ((I2C_MASTER_EVENT_TX_COMPLETE != i2c_event) && timeout_ms>0)            
  62.     {                    
  63.         R_BSP_SoftwareDelay(1U, BSP_DELAY_UNITS_MICROSECONDS);                    
  64.         timeout_ms--;
  65.     }
  66.    if (I2C_MASTER_EVENT_ABORTED == i2c_event)
  67.    {
  68.        __BKPT(0);
  69.    }
  70.    /* Read data back from the I2C slave */
  71.    i2c_event = I2C_MASTER_EVENT_ABORTED;
  72.    timeout_ms           = 1000;
  73. }

  74. static void OLED_WR_Byte(unsigned char dat,unsigned char cmd)
  75. {
  76.     if(cmd)
  77.     {
  78.         Write_IIC_Data(dat);
  79.     }
  80.     else
  81.     {
  82.         Write_IIC_Command(dat);
  83.     }
  84. }





  85. //坐标设置

  86. void OLED_Set_Pos(unsigned char x, unsigned char y)
  87. {   OLED_WR_Byte(0xb0+y,OLED_CMD);
  88.     OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
  89.     OLED_WR_Byte((x&0x0f),OLED_CMD);
  90. }
  91. //开启OLED显示
  92. void OLED_Display_On(void)
  93. {
  94.     OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
  95.     OLED_WR_Byte(0X14,OLED_CMD);  //DCDC ON
  96.     OLED_WR_Byte(0XAF,OLED_CMD);  //DISPLAY ON
  97. }
  98. //关闭OLED显示
  99. void OLED_Display_Off(void)
  100. {
  101.     OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
  102.     OLED_WR_Byte(0X10,OLED_CMD);  //DCDC OFF
  103.     OLED_WR_Byte(0XAE,OLED_CMD);  //DISPLAY OFF
  104. }
  105. //清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!!
  106. void OLED_Clear(void)
  107. {
  108.     u8 i,n;
  109.     for(i=0;i<8;i++)
  110.     {
  111.         OLED_WR_Byte (0xb0+i,OLED_CMD);    //设置页地址(0~7)
  112.         OLED_WR_Byte (0x00,OLED_CMD);      //设置显示位置—列低地址
  113.         OLED_WR_Byte (0x10,OLED_CMD);      //设置显示位置—列高地址
  114.         for(n=0;n<128;n++)OLED_WR_Byte(0,OLED_DATA);
  115.     } //更新显示
  116. }
  117. void OLED_On(void)
  118. {
  119.     u8 i,n;
  120.     for(i=0;i<8;i++)
  121.     {
  122.         OLED_WR_Byte (0xb0+i,OLED_CMD);    //设置页地址(0~7)
  123.         OLED_WR_Byte (0x00,OLED_CMD);      //设置显示位置—列低地址
  124.         OLED_WR_Byte (0x10,OLED_CMD);      //设置显示位置—列高地址
  125.         for(n=0;n<128;n++)OLED_WR_Byte(1,OLED_DATA);
  126.     } //更新显示
  127. }
  128. //在指定位置显示一个字符,包括部分字符
  129. //x:0~127
  130. //y:0~63
  131. //mode:0,反白显示;1,正常显示
  132. //size:选择字体 16/12
  133. void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 Char_Size)
  134. {
  135.     unsigned char c=0,i=0;
  136.         c=chr-' ';//得到偏移后的值
  137.         if(x>Max_Column-1){x=0;y=y+2;}
  138.         if(Char_Size ==16)
  139.             {
  140.             OLED_Set_Pos(x,y);
  141.             for(i=0;i<8;i++)
  142.             OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);
  143.             OLED_Set_Pos(x,y+1);
  144.             for(i=0;i<8;i++)
  145.             OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);
  146.             }
  147.             else {
  148.                 OLED_Set_Pos(x,y);
  149.                 for(i=0;i<6;i++)
  150.                 OLED_WR_Byte(F6x8[c][i],OLED_DATA);

  151.             }
  152. }
  153. //m^n函数
  154. u32 oled_pow(u8 m,u8 n)
  155. {
  156.     u32 result=1;
  157.     while(n--)result*=m;
  158.     return result;
  159. }
  160. //显示2个数字
  161. //x,y :起点坐标
  162. //len :数字的位数
  163. //size:字体大小
  164. //mode:模式   0,填充模式;1,叠加模式
  165. //num:数值(0~4294967295);
  166. void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 size2)
  167. {
  168.     u8 t,temp;
  169.     u8 enshow=0;
  170.     for(t=0;t<len;t++)
  171.     {
  172.         temp=(num/oled_pow(10,len-t-1))%10;
  173.         if(enshow==0&&t<(len-1))
  174.         {
  175.             if(temp==0)
  176.             {
  177.                 OLED_ShowChar(x+(size2/2)*t,y,' ',size2);
  178.                 continue;
  179.             }else enshow=1;

  180.         }
  181.         OLED_ShowChar(x+(size2/2)*t,y,temp+'0',size2);
  182.     }
  183. }
  184. //显示一个字符号串
  185. void OLED_ShowString(u8 x,u8 y,u8 *chr,u8 Char_Size)
  186. {
  187.     unsigned char j=0;
  188.     while (chr[j]!='\0')
  189.     {       OLED_ShowChar(x,y,chr[j],Char_Size);
  190.             x+=8;
  191.         if(x>120){x=0;y+=2;}
  192.             j++;
  193.     }
  194. }
  195. //显示汉字
  196. void OLED_ShowCHinese(u8 x,u8 y,u8 no)
  197. {
  198.     u8 t,adder=0;
  199.     OLED_Set_Pos(x,y);
  200.     for(t=0;t<16;t++)
  201.     {
  202.         OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
  203.         adder+=1;
  204.     }
  205.         OLED_Set_Pos(x,y+1);
  206.     for(t=0;t<16;t++)
  207.     {
  208.         OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);
  209.         adder+=1;
  210.     }
  211. }
  212. /***********功能描述:显示显示BMP图片128×64起始点坐标(x,y),x的范围0~127,y为页的范围0~7*****************/
  213. void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[])
  214. {
  215. unsigned int j=0;
  216. unsigned char x,y;

  217.   if(y1%8==0) y=y1/8;
  218.   else y=y1/8+1;
  219.     for(y=y0;y<y1;y++)
  220.     {
  221.         OLED_Set_Pos(x0,y);
  222.     for(x=x0;x<x1;x++)
  223.         {
  224.             OLED_WR_Byte(BMP[j++],OLED_DATA);
  225.         }
  226.     }
  227. }

  228. //初始化SSD1306
  229. void OLED_Init(void)
  230. {
  231.     /* Wait for minimum time required between transfers. */
  232.     //R_BSP_SoftwareDelay(800, BSP_DELAY_UNITS_MICROSECONDS);
  233.     err = R_IIC_MASTER_Open(&g_i2c_master0_ctrl, &g_i2c_master0_cfg);
  234.     assert(FSP_SUCCESS == err);
  235.     R_BSP_SoftwareDelay(500, BSP_DELAY_UNITS_MILLISECONDS); // NOLINT

  236.     OLED_WR_Byte(0xAE,OLED_CMD);//--display off
  237.     OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
  238.     OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
  239.     OLED_WR_Byte(0x40,OLED_CMD);//--set start line address
  240.     OLED_WR_Byte(0xB0,OLED_CMD);//--set page address
  241.     OLED_WR_Byte(0x81,OLED_CMD); // contract control
  242.     OLED_WR_Byte(0xFF,OLED_CMD);//--128
  243.     OLED_WR_Byte(0xA1,OLED_CMD);//set segment remap
  244.     OLED_WR_Byte(0xA6,OLED_CMD);//--normal / reverse
  245.     OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
  246.     OLED_WR_Byte(0x3F,OLED_CMD);//--1/32 duty
  247.     OLED_WR_Byte(0xC8,OLED_CMD);//Com scan direction
  248.     OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset
  249.     OLED_WR_Byte(0x00,OLED_CMD);//

  250.     OLED_WR_Byte(0xD5,OLED_CMD);//set osc division
  251.     OLED_WR_Byte(0x80,OLED_CMD);//

  252.     OLED_WR_Byte(0xD8,OLED_CMD);//set area color mode off
  253.     OLED_WR_Byte(0x05,OLED_CMD);//

  254.     OLED_WR_Byte(0xD9,OLED_CMD);//Set Pre-Charge Period
  255.     OLED_WR_Byte(0xF1,OLED_CMD);//

  256.     OLED_WR_Byte(0xDA,OLED_CMD);//set com pin configuartion
  257.     OLED_WR_Byte(0x12,OLED_CMD);//

  258.     OLED_WR_Byte(0xDB,OLED_CMD);//set Vcomh
  259.     OLED_WR_Byte(0x30,OLED_CMD);//

  260.     OLED_WR_Byte(0x8D,OLED_CMD);//set charge pump enable
  261.     OLED_WR_Byte(0x14,OLED_CMD);//

  262.     OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
  263. }
复制代码
oled.h
  1. #ifndef OLED_H_
  2. #define OLED_H_
  3. #include "stdint.h"

  4. typedef unsigned char u8;
  5. typedef unsigned short int u16;
  6. typedef unsigned int u32;


  7. #define OLED_MODE 0
  8. #define SIZE 8
  9. #define XLevelL                0x00
  10. #define XLevelH                0x10
  11. #define Max_Column        128
  12. #define Max_Row                64
  13. #define        Brightness        0xFF
  14. #define X_WIDTH         128
  15. #define Y_WIDTH         64
  16. #define OLED_CMD  0        //写命令
  17. #define OLED_DATA 1        //写数据


  18. void WriteCmd(void);
  19. void OLED_WR_CMD(uint8_t cmd);
  20. void OLED_WR_DATA(uint8_t data);
  21. void OLED_Init(void);
  22. void OLED_Clear(void);
  23. void OLED_Display_On(void);
  24. void OLED_Display_Off(void);
  25. void OLED_Set_Pos(uint8_t x, uint8_t y);
  26. void OLED_On(void);
  27. void OLED_ShowNum(uint8_t x,uint8_t y,unsigned int num,uint8_t len,uint8_t size2);
  28. void OLED_ShowChar(uint8_t x,uint8_t y,uint8_t chr,uint8_t Char_Size);
  29. void OLED_ShowString(uint8_t x,uint8_t y,uint8_t *chr,uint8_t Char_Size);
  30. void OLED_ShowCHinese(uint8_t x,uint8_t y,uint8_t no);
  31. void OLED_DrawBMP(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char BMP[]);
  32. #endif
复制代码
oledfont.h:
  1. #ifndef OLEDFONT_H_
  2. #define OLEDFONT_H_
  3. #include "stdint.h"

  4. //8*6 ASCII字符集点阵
  5. const unsigned char F6x8[][6] =
  6. {
  7.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp
  8.     0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// !
  9.     0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// "
  10.     0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// #
  11.     0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $
  12.     0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// %
  13.     0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// &
  14.     0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// '
  15.     0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// (
  16.     0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// )
  17.     0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// *
  18.     0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// +
  19.     0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// ,
  20.     0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// -
  21.     0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// .
  22.     0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// /
  23.     0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
  24.     0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1
  25.     0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2
  26.     0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3
  27.     0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4
  28.     0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5
  29.     0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
  30.     0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7
  31.     0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8
  32.     0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9
  33.     0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// :
  34.     0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ;
  35.     0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// <
  36.     0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// =
  37.     0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// >
  38.     0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ?
  39.     0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @
  40.     0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A
  41.     0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B
  42.     0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C
  43.     0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D
  44.     0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E
  45.     0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F
  46.     0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G
  47.     0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H
  48.     0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I
  49.     0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J
  50.     0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K
  51.     0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L
  52.     0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M
  53.     0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N
  54.     0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O
  55.     0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P
  56.     0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
  57.     0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R
  58.     0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S
  59.     0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T
  60.     0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U
  61.     0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V
  62.     0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W
  63.     0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X
  64.     0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y
  65.     0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z
  66.     0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [
  67.     0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55
  68.     0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ]
  69.     0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^
  70.     0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _
  71.     0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// '
  72.     0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a
  73.     0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b
  74.     0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c
  75.     0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d
  76.     0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e
  77.     0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f
  78.     0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g
  79.     0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h
  80.     0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i
  81.     0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j
  82.     0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k
  83.     0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l
  84.     0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m
  85.     0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n
  86.     0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o
  87.     0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p
  88.     0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q
  89.     0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r
  90.     0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s
  91.     0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t
  92.     0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u
  93.     0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v
  94.     0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w
  95.     0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x
  96.     0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y
  97.     0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z
  98.     0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines
  99. };

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

  197. //部分汉字
  198. const unsigned char Hzk[][32]=
  199. {
  200. //      //年(0) 月(1) 日(2) 生(3) 态(4) 工(5) 作(6) 室(7)

  201. //{0x00,0x20,0x18,0xC7,0x44,0x44,0x44,0x44,0xFC,0x44,0x44,0x44,0x44,0x04,0x00,0x00},
  202. //{0x04,0x04,0x04,0x07,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x00},/*"年",0*/

  203. //{0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00},
  204. //{0x80,0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00},/*"月",1*/

  205. //{0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x00,0x00,0x00},
  206. //{0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x00,0x00,0x00,0x00},/*"日",2*/

  207. //{0x80,0x40,0x30,0x1E,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00},
  208. //{0x40,0x40,0x42,0x42,0x42,0x42,0x42,0x7F,0x42,0x42,0x42,0x42,0x42,0x40,0x40,0x00},/*"生",3*/

  209. //{0x00,0x04,0x84,0x84,0x44,0x24,0x54,0x8F,0x14,0x24,0x44,0x84,0x84,0x04,0x00,0x00},
  210. //{0x41,0x39,0x00,0x00,0x3C,0x40,0x40,0x42,0x4C,0x40,0x40,0x70,0x04,0x09,0x31,0x00},/*"态",4*/

  211. //{0x00,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x04,0x04,0x00,0x00},
  212. //{0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00},/*"工",5*/

  213. //{0x00,0x80,0x60,0xF8,0x07,0x40,0x30,0x0F,0xF8,0x88,0x88,0x88,0x88,0x08,0x08,0x00},
  214. //{0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0xFF,0x08,0x08,0x08,0x08,0x08,0x00,0x00},/*"作",6*/

  215. //{0x10,0x0C,0x24,0x24,0xA4,0x64,0x25,0x26,0x24,0x24,0xA4,0x24,0x24,0x14,0x0C,0x00},
  216. //{0x40,0x40,0x48,0x49,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x4B,0x48,0x40,0x40,0x00},/*"室",7*/
  217. // 瑞(0) 萨(1) 电(2) 子(3) 发(4) 烧(5) 友(6)

  218. {0x84,0x84,0xFC,0x84,0x84,0x40,0x5E,0x50,0x50,0x50,0xDF,0x50,0x50,0x50,0x5E,0x00},
  219. {0x10,0x30,0x1F,0x08,0x08,0x00,0xFE,0x02,0x02,0x7F,0x02,0x7E,0x02,0x82,0xFE,0x00},/*"瑞",0*/
  220. {0x04,0xE4,0x24,0x24,0xA4,0x6F,0x04,0x24,0x64,0xAF,0x34,0xA4,0x64,0x24,0x04,0x00},
  221. {0x00,0xFF,0x00,0x11,0x22,0x9C,0x40,0x3F,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00},/*"萨",1*/
  222. {0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00},
  223. {0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x00},/*"电",2*/
  224. {0x80,0x82,0x82,0x82,0x82,0x82,0x82,0xE2,0xA2,0x92,0x8A,0x86,0x82,0x80,0x80,0x00},
  225. {0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"子",3*/
  226. {0x00,0x00,0x18,0x16,0x10,0xD0,0xB8,0x97,0x90,0x90,0x90,0x92,0x94,0x10,0x00,0x00},
  227. {0x00,0x20,0x10,0x8C,0x83,0x80,0x41,0x46,0x28,0x10,0x28,0x44,0x43,0x80,0x80,0x00},/*"发",4*/
  228. {0xF0,0x00,0xFF,0x20,0x10,0x00,0x88,0x88,0x4F,0x58,0x24,0x54,0x84,0xE4,0x00,0x00},
  229. {0x80,0x70,0x0F,0x10,0x20,0x82,0x42,0x32,0x0E,0x02,0x02,0x3E,0x42,0x42,0x72,0x00},/*"烧",5*/
  230. {0x08,0x08,0x08,0x08,0xC8,0x78,0xCF,0x48,0x48,0x48,0x48,0xC8,0x08,0x08,0x08,0x00},
  231. {0x10,0x88,0x84,0x43,0x40,0x20,0x21,0x16,0x08,0x14,0x22,0x41,0x40,0x80,0x80,0x00},/*"友",6*/
  232. };

  233. #endif /* OLEDFONT_H_ */
复制代码
6、hal_enty.cn修改如下:
  1. #include "hal_data.h"
  2. #include <stdio.h>
  3. #include "bsp_debug_uart.h"
  4. #include "bsp_can.h"
  5. #include "bsp_adc.h"
  6. #include "oled.h"

  7. FSP_CPP_HEADER
  8. void R_BSP_WarmStart(bsp_warm_start_event_t event);
  9. FSP_CPP_FOOTER


  10. /*******************************************************************************************************************//**
  11. * main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used.  This function
  12. * is called by main() when no RTOS is used.
  13. **********************************************************************************************************************/
  14. void hal_entry(void)
  15. {

  16.   bsp_uart_init();
  17.   bsp_can0_init();
  18.   bsp_adc_init();
  19.   OLED_Init();//OLED初始化
  20.   OLED_Clear();//清屏

  21.   //OLED_ShowString(16,1,"RA",16);
  22.   OLED_ShowCHinese(32,1,0);//瑞
  23.   OLED_ShowCHinese(48,1,1);//萨
  24.   OLED_ShowCHinese(0,4,2);//电
  25.   OLED_ShowCHinese(16,4,3);//子
  26.   OLED_ShowCHinese(32,4,4);//发
  27.   OLED_ShowCHinese(48,4,5);//烧
  28.   OLED_ShowCHinese(60,4,6);//友
  29.   while(1)
  30.   {
  31.     //can_send();
  32.     read_adc();
  33.     R_BSP_SoftwareDelay(1000, BSP_DELAY_UNITS_MILLISECONDS);
  34.       // NOLINT100->160
  35.   }
  36. #if BSP_TZ_SECURE_BUILD
  37.     /* Enter non-secure code */
  38.     R_BSP_NonSecureEnter();
  39. #endif
  40. }

  41. /*******************************************************************************************************************//**
  42. * This function is called at various points during the startup process.  This implementation uses the event that is
  43. * called right before main() to set up the pins.
  44. *
  45. * @param[in]  event    Where at in the start up process the code is currently at
  46. **********************************************************************************************************************/
  47. void R_BSP_WarmStart (bsp_warm_start_event_t event)
  48. {
  49.     if (BSP_WARM_START_RESET == event)
  50.     {
  51. #if BSP_FEATURE_FLASH_LP_VERSION != 0

  52.         /* Enable reading from data flash. */
  53.         R_FACI_LP->DFLCTL = 1U;

  54.         /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and
  55.          * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */
  56. #endif
  57.     }

  58.     if (BSP_WARM_START_POST_C == event)
  59.     {
  60.         /* C runtime environment and system clocks are setup. */

  61.         /* Configure pins. */
  62.         R_IOPORT_Open(&g_ioport_ctrl, g_ioport.p_cfg);
  63.     }
  64. }

  65. #if BSP_TZ_SECURE_BUILD

  66. BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ();

  67. /* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */
  68. BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ()
  69. {

  70. }
  71. #endif
复制代码
7、下载到开发板,OLED可以点亮了:

8、接下来实动态显示电压:
改动bsp_adc.c如下:
  1. void read_adc(void)
  2. {
  3.   fsp_err_t err = FSP_SUCCESS;
  4.   double a0;
  5.   uint16_t adc_data0=0;
  6.   char vbuf[10];
  7.   (void) R_ADC_ScanStart(&g_adc0_ctrl);
  8.    scan_complete_flag = false;
  9.   while (!scan_complete_flag)
  10.   {
  11.       /* Wait for callback to set flag. */
  12.   }
  13.   
  14.   err = R_ADC_Read(&g_adc0_ctrl, ADC_CHANNEL_2, &adc_data0);
  15.   assert(FSP_SUCCESS == err);
  16.   a0=(double)(adc_data0/4095.0)*3.3;
  17.   printf("v: %.03f \r\n",a0);
  18.   sprintf(vbuf,"%.03fV",a0);
  19.   OLED_ShowString(24,24,vbuf,24);
  20. }
复制代码
实现效果如下:

这样就实现了电压表,与实际电压对比一下,准确度还是很高的。详情见视频。
https://bbs.elecfans.com/jishu_2319892_1_1.html

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

3

主题

195

帖子

1191

积分

金牌会员

Rank: 6Rank: 6

积分
1191
发表于 2023-3-14 11:14:24 | 显示全部楼层

不错,学习一下
回复

使用道具 举报

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

本版积分规则

用户排行榜

RA助手

主题: 116帖子:133精华:0

RA_Lance

主题: 92帖子:132精华:9

lugl

主题: 38帖子:126精华:0

xujiwei263

主题: 16帖子:73精华:0

books咦

主题: 11帖子:11精华:2

Juggernaut

主题: 9帖子:95精华:0
快速回复 返回顶部 返回列表