jinglixixi 发表于 2020-10-9 00:46

【AT-START-F403A测评】+彩色OLED屏的显示驱动

<p>AT32F403A有1024&nbsp;K字节的内存和96+128&nbsp;K字节的SRAM,另外还配有高达16&nbsp;M字节的SPI闪存,面对这么丰富的存储资源不为它配个彩屏啥的,真有点委屈了它们。</p>

<p>这里就先为其配上一个0.96&#39;的彩色OLED屏,该显示屏采用SPI接口,为此将I2C接口和SPI接口联合起来驱动它。</p>

<p></p>

<p>图1 接口资源</p>

<p>&nbsp;</p>

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

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

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

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

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

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

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

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

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

<p>&nbsp;#define OLED_CS_Clr()&nbsp;&nbsp; &nbsp;&nbsp;GPIO_ResetBits(GPIOB, GPIO_Pins_13)</p>

<p>#define OLED_CS_Set()&nbsp;&nbsp; &nbsp;&nbsp;GPIO_SetBits(GPIOB, GPIO_Pins_13)</p>

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

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

<p>&nbsp;</p>

<p>OLED屏的引脚功能定义函数为:</p>

<pre>
<code class="language-cpp">void AT32_OLED_Init(void)
{
  GPIO_InitType GPIO_InitStructure;
  RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOB, ENABLE);
  GPIO_StructInit(&amp;GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pins=GPIO_Pins_8|GPIO_Pins_9|GPIO_Pins_11|GPIO_Pins_12|GPIO_Pins_13|GPIO_Pins_14;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT_PP;
  GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_10MHz;
  GPIO_Init(GPIOB, &amp;GPIO_InitStructure);
  OLED_BLK_Set();
}</code></pre>

<p>图片的显示函数为:</p>

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

<p>&nbsp;</p>

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

<pre>
<code class="language-cpp">int main(void)  //OLED 0.96 CORLOR
{
         uint8_t i;
         AT32_Board_Init();
         AT32_OLED_Init();
         OLED_Init();
         Delay_ms(200);
         LCD_Clear(BLACK);
         BACK_COLOR=BLACK;
         LCD_ShowString(10,0,"AT32F403A TEST",RED);
         LCD_ShowString(10,20,"OLED Display",RED);
         LCD_ShowString(10,40,"jinglixixi",RED);
         LCD_ShowString(10,60,"2020.10.5",RED);
         Delay_ms(2000);
         LCD_Clear(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(20,60,"0.96 TFT SPI",YELLOW);
         Delay_ms(2000);
         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);
         }
         Delay_ms(2000);
         LCD_ShowPicturea(0,0,159,79);
       while(1);
}</code></pre>

<p>编译下载后,所显示的效果如图2~图5所示,怎么样存储资源少的芯片是不敢轻易来直接用数组存放图片数据的。</p>

<p></p>

<p>图2 字符串显示</p>

<p>&nbsp;</p>

<p></p>

<p>图3 中文显示</p>

<p>&nbsp;</p>

<p></p>

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

<p>&nbsp;</p>

<p></p>

<p>图5 图片显示</p>

damiaa 发表于 2020-10-9 09:18

<p>不点屏确实浪费。<img height="48" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/congra.gif" width="48" /></p>

jinglixixi 发表于 2020-10-9 13:23

damiaa 发表于 2020-10-9 09:18
不点屏确实浪费。

<p><img height="48" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/handshake.gif" width="48" /></p>

okhxyyo 发表于 2020-10-9 15:05

<p>雅特力AT-START-F403A测评汇总</p>

<p><a href="https://bbs.eeworld.com.cn/thread-1143018-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1143018-1-1.html</a></p>
页: [1]
查看完整版本: 【AT-START-F403A测评】+彩色OLED屏的显示驱动