[综合信息] 【华大测评】+ 驱动板载显示器

[复制链接]
1308|3
 楼主| 海洋无限 发表于 2020-10-2 12:37 | 显示全部楼层 |阅读模式
这款开发板上有个OLED显示器,对调试板卡来说非常好用,这里首先把这个显示器驱动起来,显示器为I2C接口,论坛里有人已经成功驱动过了,相信应该不是很难。I2C驱动、OLED驱动,再加字库就OK了。show显示效果,祝大家国庆、中秋双节快乐!

oled

oled

只要之前接触过OLED,相信驱动起来都不是很难,这里不啰嗦了,直接上代码:首先搭建I2C接口配置,可参考例程
  1.     stc_i2c_init_t stcI2cInit;
  2.     stc_clk_freq_t stcClkFreq;

  3.         /* Initialize I2C port*/
  4.     PORT_SetFunc(I2C2_SCL_PORT, I2C2_SCL_PIN, Func_I2c2_Scl, Disable);
  5.     PORT_SetFunc(I2C2_SDA_PORT, I2C2_SDA_PIN, Func_I2c2_Sda, Disable);

  6.     /* Enable I2C Peripheral*/
  7.     PWC_Fcg1PeriphClockCmd(PWC_FCG1_PERIPH_I2C2, Enable);
  8.         
  9.     I2C_DeInit(I2C_CH);

  10.     /* Get system clock frequency */
  11.     CLK_GetClockFreq(&stcClkFreq);

  12.     MEM_ZERO_STRUCT(stcI2cInit);
  13.     stcI2cInit.enI2cMode = I2cMaster;
  14.     stcI2cInit.u32Pclk3 = stcClkFreq.pclk3Freq;
  15.     stcI2cInit.u32Baudrate = 400000ul;
  16.     stcI2cInit.u32SclTime = 0ul;
  17.     I2C_Init(I2C_CH, &stcI2cInit);

  18.     I2C_Cmd(I2C_CH, Enable);
写数据
  1.    uint32_t u32TimeOut = TIMEOUT;

  2.     while(u32Size--)
  3.     {
  4.         /* Wait tx buffer empty */
  5.         u32TimeOut = TIMEOUT;
  6.         while(Reset == I2C_GetStatus(I2C_CH, I2C_SR_TEMPTYF))
  7.         {
  8.             if(0ul == (u32TimeOut--))
  9.             {
  10.                 break;
  11.             }
  12.         }

  13.         /* Send one byte data */
  14.         I2C_SendData(I2C_CH, Data);

  15.         /* Wait transfer end*/
  16.         u32TimeOut = TIMEOUT;
  17.         while(Reset == I2C_GetStatus(I2C_CH, I2C_SR_TENDF))
  18.         {
  19.             if(0ul == (u32TimeOut--))
  20.             {
  21.                 break;
  22.             }
  23.         }

  24.         /* Check ACK */
  25.         u32TimeOut = TIMEOUT;
  26.         while(Set == I2C_GetStatus(I2C_CH, I2C_SR_NACKDETECTF))
  27.         {
  28.             if(0ul == (u32TimeOut--))
  29.             {
  30.                 break;
  31.             }
  32.         }
  33.     }
  1.     uint32_t u32TimeOut = TIMEOUT;

  2.     /* Wait tx buffer empty */
  3.     while(Reset == I2C_GetStatus(I2C_CH, I2C_SR_TEMPTYF))
  4.     {
  5.         if(0ul == (u32TimeOut--))
  6.         {
  7.                         break;
  8.         }
  9.     }

  10.     /* Send I2C address */
  11.     I2C_SendData(I2C_CH, u8Adr);

  12.     if(!(u8Adr & 0x01u))     
  13.     {
  14.         /* If in master transfer process, Need wait transfer end*/
  15.         uint32_t u32TimeOut = TIMEOUT;
  16.         while(Reset == I2C_GetStatus(I2C_CH, I2C_SR_TENDF))
  17.         {
  18.             if(0ul == (u32TimeOut--))
  19.             {
  20.                 break;
  21.             }
  22.         }
  23.     }

  24.     /* Check ACK */
  25.     u32TimeOut = TIMEOUT;
  26.     while(Set == I2C_GetStatus(I2C_CH, I2C_SR_NACKDETECTF))
  27.     {
  28.         if(0ul == (u32TimeOut--))
  29.         {
  30.             break;
  31.         }
  32.     }
  1.     uint32_t u32TimeOut = TIMEOUT;
  2.     en_flag_status_t enFlagBusy = Reset;
  3.     en_flag_status_t enFlagStartf = Reset;

  4.     /* generate start or restart signal */
  5.     if(!u8Start)
  6.     {
  7.         /* Wait I2C bus idle */
  8.         while(Set == I2C_GetStatus(I2C_CH, I2C_SR_BUSY))
  9.         {
  10.             if(0ul == (u32TimeOut--))
  11.             {
  12.                                 break;
  13.             }
  14.         }

  15.         I2C_GenerateStart(I2C_CH, Enable);
  16.     }
  17.     else
  18.     {
  19.         /* Clear start status flag */
  20.         I2C_ClearStatus(I2C_CH, I2C_CLR_STARTFCLR);
  21.         /* Send restart condition */
  22.         I2C_GenerateReStart(I2C_CH , Enable);
  23.     }

  24.     /* Judge if start success*/
  25.     u32TimeOut = TIMEOUT;
  26.     while(1)
  27.     {
  28.         enFlagBusy = I2C_GetStatus(I2C_CH, I2C_SR_BUSY);
  29.         enFlagStartf = I2C_GetStatus(I2C_CH, I2C_SR_STARTF);
  30.         if(enFlagBusy && enFlagStartf)
  31.         {
  32.             break;
  33.         }
  34.         if(0ul == (u32TimeOut--))
  35.         {
  36.                         break;
  37.         }
  38.     }
代码还不少,直接上传文件,最后调用OLED_Process show 效果!



Src.zip

7.16 KB, 下载次数: 9

OLED相关文件

zeshoufx 发表于 2020-10-2 13:14 | 显示全部楼层
谢谢分享【驱动板载显示器 】
weifeng90 发表于 2020-10-5 21:17 | 显示全部楼层
感谢分享
自己的灌饼 发表于 2020-10-10 09:18 | 显示全部楼层
OLED驱动,再加字库就OK了。show显示效果,祝大家国庆、中秋双节快乐!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:永远忠于年轻时的梦想!

39

主题

539

帖子

1

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