jinglixixi 发表于 2020-11-17 00:08

【MM32 eMiniBoard测评】+彩色OLED屏的显示驱动

<p>前面介绍了双色OLED屏的显示,那MM32 eMiniBoard开发板是否能驱动彩色OLED屏呢?</p>

<p>答案是肯定的,其显示效果见图1和图2所示。</p>

<p></p>

<p>图1 字符串及汉字显示</p>

<p>&nbsp;</p>

<p></p>

<p>图2 图标显示</p>

<p>&nbsp;</p>

<p>有别于I2C接口的双色屏,彩色屏所采用的接口是SPI,故要比双色屏占用更多的I/O口。</p>

<p>那使用哪些引脚呢?</p>

<p>这里OLED屏与MCU的连接关系为:</p>

<p>SCK --PB13&nbsp;&nbsp; &nbsp;CL</p>

<p>MISO--PB14&nbsp;&nbsp; SDA</p>

<p>MOSI--PB15&nbsp;&nbsp; RST</p>

<p>SS&nbsp; --PB12&nbsp;&nbsp; &nbsp;DC</p>

<p>LD1 --PA15&nbsp;&nbsp; &nbsp;CS</p>

<p>LD2 --PB3&nbsp;&nbsp;&nbsp; &nbsp;BLK</p>

<p>本想粘一下Arduino接口的光,无奈的是不知何时现在出产的OLED屏都任GND做老大了!</p>

<p>弄的一个好好的Arduino接口,却无法直插OLED屏来使用,真不知他们为何这样居心叵测!</p>

<p>没办法,胳膊拧不过大腿呀!</p>

<p>还是用杜邦线来交换线序吧。</p>

<p>定义相关引脚输出高低电平的语句如下:</p>

<p>#define OLED_SCLK_Clr()&nbsp; GPIO_ResetBits(GPIOB,GPIO_Pin_13)&nbsp; //CLK</p>

<p>#define OLED_SCLK_Set()&nbsp; GPIO_SetBits(GPIOB,GPIO_Pin_13)</p>

<p>&nbsp;</p>

<p>#define OLED_SDIN_Clr()&nbsp; GPIO_ResetBits(GPIOB,GPIO_Pin_14)&nbsp; //DIN</p>

<p>#define OLED_SDIN_Set()&nbsp; GPIO_SetBits(GPIOB,GPIO_Pin_14)</p>

<p>&nbsp;</p>

<p>#define OLED_RST_Clr()&nbsp; GPIO_ResetBits(GPIOB,GPIO_Pin_15) //RES</p>

<p>#define OLED_RST_Set()&nbsp; GPIO_SetBits(GPIOB,GPIO_Pin_15)</p>

<p>&nbsp;</p>

<p>#define OLED_DC_Clr()&nbsp;&nbsp; GPIO_ResetBits(GPIOB,GPIO_Pin_12) //DC</p>

<p>#define OLED_DC_Set()&nbsp;&nbsp; GPIO_SetBits(GPIOB,GPIO_Pin_12)</p>

<p>&nbsp;</p>

<p>#define OLED_CS_Clr()&nbsp;&nbsp; GPIO_ResetBits(GPIOA,GPIO_Pin_15) //CS</p>

<p>#define OLED_CS_Set()&nbsp;&nbsp; GPIO_SetBits(GPIOA,GPIO_Pin_15)</p>

<p>&nbsp;</p>

<p>#define OLED_BLK_Clr()&nbsp; GPIO_ResetBits(GPIOB,GPIO_Pin_3) //BLK</p>

<p>#define OLED_BLK_Set()&nbsp; GPIO_SetBits(GPIOB,GPIO_Pin_3)</p>

<p>&nbsp;</p>

<p>配置引脚为输出功能的函数为:</p>

<pre>
<code class="language-cpp">void APP_OLED_Init(void)
{
    GPIO_InitTypeDef  GPIO_InitStructure;
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
    GPIO_StructInit(&amp;GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14| GPIO_Pin_15| GPIO_Pin_12| GPIO_Pin_3;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOB, &amp;GPIO_InitStructure);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
   GPIO_StructInit(&amp;GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOA, &amp;GPIO_InitStructure);
}</code></pre>

<p>完成字符串显示的函数为:</p>

<pre>
<code class="language-cpp">void LCD_ShowString(u16 x,u16 y,const u8 *p,u16 color)
{        
    while(*p!='\0')
    {      
        if(x&gt;LCD_W-16){x=0;y+=16;}
        if(y&gt;LCD_H-16){y=x=0;LCD_Clear(RED);}
        LCD_ShowChar(x,y,*p,0,color);
        x+=8;
        p++;
    } 
}</code></pre>

<p>实现图标显示的函数为:</p>

<pre>
<code class="language-cpp">void LCD_ShowPicture(u16 x1,u16 y1,u16 x2,u16 y2)
{
           int i;
           LCD_Address_Set(x1,y1,x2,y2);
           for(i=0;i&lt;1600;i++)
           {
                  LCD_WR_DATA8(image);
                  LCD_WR_DATA8(image);        
           }
}</code></pre>

<p>&nbsp;</p>

<p>实现图1和图2显示效果的主程序为:</p>

<pre>
<code class="language-cpp">s32 main(void)
{
           u8 i;
           LED_Init();
           DELAY_Init();
           APP_OLED_Init();
           OLED_BLK_Set();
           Lcd_Init();
         LCD_Clear(BLACK);
           BACK_COLOR=BLACK;
           LCD_ShowChinese(28,0,0,32,YELLOW);
           LCD_ShowChinese(60,0,1,32,YELLOW);
           LCD_ShowChinese(92,0,2,32,YELLOW);
           LCD_ShowChinese(20,40,0,16,YELLOW);
           LCD_ShowChinese(36,40,1,16,YELLOW);
           LCD_ShowChinese(52,40,2,16,YELLOW);
           LCD_ShowChinese(68,40,3,16,YELLOW);
           LCD_ShowChinese(84,40,4,16,YELLOW);
           LCD_ShowChinese(100,40,5,16,YELLOW);
           LCD_ShowChinese(116,40,6,16,YELLOW);
           LCD_ShowString(0,60,"0.96 TFT SPI",YELLOW);
           DELAY_Ms(1000);
           LCD_Clear(BLACK);
           LCD_ShowString(10,0,"LCD_W:",RED);
           LCD_ShowNum(70,0,LCD_W,3,RED);
           LCD_ShowString(10,20,"LCD_H:",RED);
           LCD_ShowNum(70,20,LCD_H,2,RED);
           for(i=0;i&lt;4;i++)
           {
                       LCD_ShowPicture(i*40,40,39+i*40,79);
           }
           while(1);
}</code></pre>

<p>&nbsp;</p>

w494143467 发表于 2020-11-17 09:52

<p>刷屏速度咋样,撕裂效果很容易看到吗?</p>

jinglixixi 发表于 2020-11-17 13:42

本帖最后由 jinglixixi 于 2020-11-17 13:44 编辑

<div class="quote">
<blockquote><font size="2"><a href="forum.php?mod=redirect&amp;goto=findpost&amp;pid=3024952&amp;ptid=1148835" target="_blank"><font color="#999999">w494143467 发表于 2020-11-17 09:52</font></a></font> 刷屏速度咋样,撕裂效果很容易看到吗?</blockquote>
</div>

<p>还好,不想刷2.2&#39;TFT屏那样是一段一段向下展开。</p>

<p>用PIC16F15324做了个双色OLED屏的显示,那家伙真是一块一块的显示呀!</p>

freebsder 发表于 2020-11-17 21:30

<p>可玩的东西好多,中景园好熟悉的名字.</p>

jinglixixi 发表于 2020-11-18 00:06

freebsder 发表于 2020-11-17 21:30
可玩的东西好多,中景园好熟悉的名字.

<p>可玩的东西多,口袋里的银子限制了购买力呀!</p>

<p>以后LED的一灯大师,估计要让位给OLED(O耶)了,<img height="48" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/lol.gif" width="48" /></p>

<p>&nbsp;</p>

okhxyyo 发表于 2020-11-23 10:56

<p><strong><a href="https://bbs.eeworld.com.cn/elecplay/content/145" target="_blank">灵动MM32 eMiniBoard开发板测评</a></strong></p>

<p>汇总贴:<a href="https://bbs.eeworld.com.cn/thread-1146791-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1146791-1-1.html</a></p>

zxopenljx 发表于 2021-5-21 10:10

<p>谢谢分享</p>

jinglixixi 发表于 2021-5-21 20:40

zxopenljx 发表于 2021-5-21 10:10
谢谢分享

<p>感谢支持!</p>
页: [1]
查看完整版本: 【MM32 eMiniBoard测评】+彩色OLED屏的显示驱动