jinglixixi 发表于 2021-10-9 23:02

[ESP32-Audio-Kit音频开发板测评] 彩色OLED屏的显示驱动

<div class='showpostmsg'><p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">ESP32-Audio-Kit<span style="font-family:宋体">开发板是一款主打</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;"><span style="color:#444444"><span style="letter-spacing:.75pt">音频处理的开发板,若再为它配上图片显示功能将会锦上添花。鉴于其提供的接口资源实在有限,见图1所示。</span></span></span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;"><span style="color:#444444"><span style="letter-spacing:.75pt">图1扩展接口</span></span></span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;"><span style="color:#444444"><span style="letter-spacing:.75pt">这里是以一个SPI接口的彩色OLED屏为显示器件,其各引脚的连接关系如下:</span></span></span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">SCL&nbsp; --- &nbsp;23 </span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">SDA &nbsp;---&nbsp; 18</span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">RST&nbsp; ---&nbsp; 22</span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">DC&nbsp; &nbsp;---&nbsp; 19</span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">CS&nbsp; &nbsp;---&nbsp; 21</span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">显示屏的引脚功能配置函数为:</span></span></span></p>

<pre>
<code class="language-cpp">void App_OledInit(void)
{
  pinMode(SCL,OUTPUT);
  pinMode(SDA,OUTPUT);
  pinMode(DC, OUTPUT);
  pinMode(RST,OUTPUT);
  pinMode(CS,OUTPUT);
}</code></pre>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">相应的清屏函数为:</span></span></span></p>

<pre>
<code class="language-cpp">void LCD_Clear(u16 Color)
{
      u16 i,j;
      LCD_Address_Set(0,0,LCD_W-1,LCD_H-1);
      for(i=0;i&lt;LCD_W;i++)
      {
            for (j=0;j&lt;LCD_H;j++)
            {
                    LCD_WR_DATA(Color);
            }
      }
}</code></pre>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">在配置显示字库的情况下,其字符显示函数为:</span></span></span></p>

<pre>
<code class="language-cpp">void LCD_ShowChar(u16 x,u16 y,u8 num,u16 color)
{
    u8 temp;
    u8 pos,t;
    u16 x0=x;
    num=num-' ';
    LCD_Address_Set(x,y,x+8-1,y+16-1);
    for(pos=0;pos&lt;16;pos++)
    {
        temp=asc2_1608[(u16)num*16+pos];
        for(t=0;t&lt;8;t++)
        {
            if(temp&amp;0x01) LCD_WR_DATA(color);
            temp&gt;&gt;=1;
            x++;
        }
        x=x0;
        y++;
    }
}</code></pre>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">在使用该函数的情况下,其显示效果如图</span>2<span style="font-family:宋体">所示。</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;"><span style="color:#444444"><span style="letter-spacing:.75pt">图2字符显示效果</span></span></span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">在借助于文件系统及</span>TF<span style="font-family:宋体">卡读写功能的情况下,可实现图片显示及数码相框功能,显示效果如图</span>3<span style="font-family:宋体">所示。</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">显示指定目录下图片的功能函数为:</span></span></span></p>

<pre>
<code class="language-cpp">void listDir(fs::FS &amp;fs, const char * dirname, uint8_t levels)
{
    Serial.printf("Listing directory: %s\n", dirname);
    File root = fs.open(dirname);
    if(!root){
        Serial.println("Failed to open directory");
        return;
    }
    if(!root.isDirectory()){
        Serial.println("Not a directory");
        return;
    }
    File file = root.openNextFile();
    while(file)
    {
            testpic(SD_MMC, file.name());
            // 按键控制
            while (digitalRead(key)==0)
            file = root.openNextFile();
   }
}</code></pre>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;"><span style="color:#444444"><span style="letter-spacing:.75pt">图3图片显示效果</span></span></span></span></span></p>
</div><script>                                        var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;"   style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
                                       
                                        if(parseInt(discuz_uid)==0){
                                                                                                (function($){
                                                        var postHeight = getTextHeight(400);
                                                        $(".showpostmsg").html($(".showpostmsg").html());
                                                        $(".showpostmsg").after(loginstr);
                                                        $(".showpostmsg").css({height:postHeight,overflow:"hidden"});
                                                })(jQuery);
                                        }                </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script>

火辣西米秀 发表于 2021-10-10 10:47

<p>数码相框功能已实现,还行</p>
页: [1]
查看完整版本: [ESP32-Audio-Kit音频开发板测评] 彩色OLED屏的显示驱动