jinglixixi 发表于 2024-11-8 21:38

【翌创ET6001测评】LCD屏显示驱动

<p>尽管前面已经介绍了串行数码管模块的显示方式,但相对来讲其显示的信息量量及显示形式还相对有限,为此这里在为它添加了一种LCD屏的显示方式。</p>

<p >该显示屏采用SPI接口的工作发送,其显示分辨率为160*80像素点。</p>

<p >&nbsp;</p>

<p >为驱动该显示屏,是使用图1所示的接口来连接显示屏。</p>

<p > &nbsp;</p>

<p>图1 所用接口</p>

<p >&nbsp;</p>

<p >其中:</p>

<p >SCL---GPIO2_2</p>

<p >DIN---GPIO2_3</p>

<p >RES---GPIO2_4</p>

<p >DC---GPIO2_5</p>

<p >CS---GPIO2_1</p>

<p >&nbsp;</p>

<p >将这5个引脚设置为输出口且置为高电平输出的函数为:</p>

<p >为程序中输出高低电平的相应,特进行如下定义:</p>

<p >#define LCD__Set &nbsp;&nbsp;GPIO_WritePin(GPIO2, GPIO_PIN_02, SET) &nbsp;//CLK</p>

<p >#define LCD_SCLK_Clr &nbsp;&nbsp;GPIO_WritePin(GPIO2, GPIO_PIN_02, RESET)</p>

<p >&nbsp;</p>

<p >#define LCD_SDIN_Set &nbsp;&nbsp;GPIO_WritePin(GPIO2, GPIO_PIN_03, SET) &nbsp;//DIN</p>

<p >#define LCD_SDIN_Clr &nbsp;&nbsp;GPIO_WritePin(GPIO2, GPIO_PIN_03, RESET)</p>

<p >&nbsp;</p>

<p >#define LCD_RST_Set &nbsp;&nbsp;&nbsp;GPIO_WritePin(GPIO2, GPIO_PIN_04, SET) &nbsp;//RES</p>

<p >#define LCD_RST_Clr &nbsp;&nbsp;&nbsp;GPIO_WritePin(GPIO2, GPIO_PIN_04, RESET)</p>

<p >&nbsp;</p>

<p >#define LCD_DC_Set &nbsp;&nbsp;&nbsp;&nbsp;GPIO_WritePin(GPIO2, GPIO_PIN_05, SET) &nbsp;//DC</p>

<p >#define LCD_DC_Clr &nbsp;&nbsp;&nbsp;&nbsp;GPIO_WritePin(GPIO2, GPIO_PIN_05, RESET)</p>

<p >&nbsp;</p>

<p >#define LCD_CS_Set &nbsp;&nbsp;&nbsp;&nbsp;GPIO_WritePin(GPIO2, GPIO_PIN_01, SET) &nbsp;//CS</p>

<p >#define LCD_CS_Clr &nbsp;&nbsp;&nbsp;&nbsp;GPIO_WritePin(GPIO2, GPIO_PIN_01, RESET)</p>

<p >&nbsp;</p>

<p >该LCD屏的初始化函数为:</p>

<pre>
<code class="language-cpp">static void Lcd_Init(void)
{
LCD_RST_Clr;
Delay(0x2FFFFF);
LCD_RST_Set;
Delay(0x2FFFFF);
LCD_WR_REG(0x11);
Delay(0x1FFFFF);
LCD_WR_REG(0x21);
LCD_WR_REG(0xB1);
LCD_WR_DATA8(0x05);
LCD_WR_DATA8(0x3A);
LCD_WR_DATA8(0x3A);
LCD_WR_REG(0xB2);
LCD_WR_DATA8(0x05);
LCD_WR_DATA8(0x3A);
LCD_WR_DATA8(0x3A);
LCD_WR_REG(0xB3);
LCD_WR_DATA8(0x05);
LCD_WR_DATA8(0x3A);
LCD_WR_DATA8(0x3A);
LCD_WR_DATA8(0x05);
LCD_WR_DATA8(0x3A);
LCD_WR_DATA8(0x3A);
LCD_WR_REG(0xB4);
LCD_WR_DATA8(0x03);
LCD_WR_REG(0xC0);
LCD_WR_DATA8(0x62);
LCD_WR_DATA8(0x02);
LCD_WR_DATA8(0x04);
LCD_WR_REG(0xC1);
LCD_WR_DATA8(0xC0);
LCD_WR_REG(0xC2);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x00);
LCD_WR_REG(0xC3);
LCD_WR_DATA8(0x8D);
LCD_WR_DATA8(0x6A);
LCD_WR_REG(0xC4);
LCD_WR_DATA8(0x8D);
LCD_WR_DATA8(0xEE);
LCD_WR_REG(0xC5);
LCD_WR_DATA8(0x0E);
LCD_WR_REG(0xE0);
LCD_WR_DATA8(0x10);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x02);
LCD_WR_DATA8(0x03);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x07);
LCD_WR_DATA8(0x02);
LCD_WR_DATA8(0x07);
LCD_WR_DATA8(0x0A);
LCD_WR_DATA8(0x12);
LCD_WR_DATA8(0x27);
LCD_WR_DATA8(0x37);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x10);
LCD_WR_REG(0xE1);
LCD_WR_DATA8(0x10);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x03);
LCD_WR_DATA8(0x03);
LCD_WR_DATA8(0x0F);
LCD_WR_DATA8(0x06);
LCD_WR_DATA8(0x02);
LCD_WR_DATA8(0x08);
LCD_WR_DATA8(0x0A);
LCD_WR_DATA8(0x13);
LCD_WR_DATA8(0x26);
LCD_WR_DATA8(0x36);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x10);
LCD_WR_REG(0x3A);
LCD_WR_DATA8(0x05);
LCD_WR_REG(0x36);
LCD_WR_DATA8(0x78);
LCD_WR_REG(0x29);
}</code></pre>

<p>&nbsp;</p>

<p>该显示屏的清屏函数为:</p>

<pre>
<code class="language-cpp">static 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>&nbsp;</p>

<p>在添加字库的情况下,该显示屏的字符串显示函数为:</p>

<pre>
<code class="language-cpp">static 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,1,color);
      x+=8;
      p++;
    }
}</code></pre>

<p>&nbsp;</p>

<p>该显示屏显示字符串的主程序为:</p>

<pre>
<code class="language-cpp">int main(void)
{
    EVB_LEDInit();
    Lcd_Init();
    LCD_Clear(RED);
    LCD_ShowString(10,10,"ETEB-6001DPX",YELLOW);
    LCD_ShowString(10,30,"jinglixixi",YELLOW);
    while (1)
    {
          Delay(0x5FFFFF);
                  LCD_Clear(YELLOW);
                  Delay(0x5FFFFF);
                  LCD_Clear(BLUE);
                  Delay(0x5FFFFF);
                  LCD_Clear(GREEN);
                  Delay(0x5FFFFF);
                  LCD_Clear(MAGENTA);
    }
}</code></pre>

<p>&nbsp;</p>

<p>经程序的编译与运行,其显示结果如图2至图4所示,说明显示功能正常。</p>

<p> &nbsp;</p>

<p>图2 显示紫色</p>

<p>&nbsp;</p>

<p> &nbsp;</p>

<p>图3 显示绿色</p>

<p>&nbsp;</p>

<p> &nbsp;</p>

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

<p>&nbsp;</p>

<p >后续在添加数值显示功能的情况下,可与A/D数据采集功能相结合来实现温度检测功能。</p>

<p >&nbsp;</p>

<p>视频:</p>

<p>24e96d1fcfe37c223cf89ac7e6eede34<br />
&nbsp;</p>

Jacktang 发表于 2024-11-16 09:11

<p>期待后续与A/D数据采集功能相结合来实现温度检测功能。</p>

jinglixixi 发表于 2024-11-17 08:25

Jacktang 发表于 2024-11-16 09:11
期待后续与A/D数据采集功能相结合来实现温度检测功能。

<p>时间允许的情况下,整一个。</p>
页: [1]
查看完整版本: 【翌创ET6001测评】LCD屏显示驱动