STM32F429-DISCO 学习之驱动800X480屏幕

/ 0评 / 1

用STM32F429最大的优点就是驱动TFT屏幕,支持RGB的SYNC模式,最大支持到1024*768,不过好像性价比比较高的,还是1024*600的,当然,更便宜一些的,就是5寸的800*480,因为7寸的还要一个外部电路,可没想象中的几十元那么便宜.当然,我指的都是淘宝随便的拆机屏.当然,我是为了验证功能的,就不要跟我说什么程序结构了,毫无结构可言.
驱动屏幕并没什么难事,只是涉及到计算参数.首先是像素时钟需要计算,然后查手册知道同步前沿同步后沿,如图,填下:
QQ截图20151211103739
然后得出结果变成代码:

  /* Timing configuration */
  /* Configure horizontal synchronization width */
  LTDC_InitStruct.LTDC_HorizontalSync = 1;
  /* Configure vertical synchronization height */
  LTDC_InitStruct.LTDC_VerticalSync = 1;
  /* Configure accumulated horizontal back porch */
  LTDC_InitStruct.LTDC_AccumulatedHBP = 40;
  /* Configure accumulated vertical back porch */
  LTDC_InitStruct.LTDC_AccumulatedVBP = 23;;
  /* Configure accumulated active width */
  LTDC_InitStruct.LTDC_AccumulatedActiveW = 840;
  /* Configure accumulated active height */
  LTDC_InitStruct.LTDC_AccumulatedActiveH = 503;
  /* Configure total width */
  LTDC_InitStruct.LTDC_TotalWidth = 880;
  /* Configure total height */
  LTDC_InitStruct.LTDC_TotalHeigh = 516;

然后建立一个完全显示图层,来做测试,要知道LTDC_HorizontalStart和LTDC_VerticalStart,其中LTDC_HorizontalStart应该是LTDC_AccumulatedHBP+1,而LTDC_VerticalStart应该是LTDC_AccumulatedVBP+1,结束像素就顺延+1吧.为什么是+1呢,因为同步时钟也是1啊.

  LTDC_Layer_InitStruct.LTDC_HorizontalStart = 41;
  LTDC_Layer_InitStruct.LTDC_HorizontalStop = (800 + 40);
  LTDC_Layer_InitStruct.LTDC_VerticalStart = 24;
  LTDC_Layer_InitStruct.LTDC_VerticalStop = 480 + 23;

然后做一个清空整个屏幕的函数,首先肯定是整个RAM写0,然后写另一个颜色,再写自己颜色,就能确定自己能完整填满framebuffer.

void cLCD_Clear(uint16_t Color)
{
    uint32_t index = 0;
    for (index = 0x00; index < 0x400000; index++)
    {
        *(volatile uint16_t *)(0xd0000000 + (2 * index)) = 0x0000;
    }
    for (index = 0x00; index < 0x400000; index++)
    {
        *(volatile uint16_t *)(0xd0000000 + (2 * index)) = 0x03f0;
    }
    for (index = 0x00; index < 480 * 800; index++)
    {
        *(volatile uint16_t *)(0xd0000000 + (2 * index)) = (uint16_t)Color;
    }
}

如果最后只刷480 * 800 - 1的话,最后一个点的颜色,就是0x03f0了.可以测试一下.我的Main函数:

int main(void)
{
    /* Configure LCD */
    LCD_Config();
    /* Enable Layer 1 */
    LTDC_LayerCmd(LTDC_Layer1, ENABLE);
    /* Reload LTDC configuration  */
    LTDC_ReloadConfig(LTDC_IMReload);
    /* Enable The LCD */
    LTDC_Cmd(ENABLE);
    cLCD_Clear(0x00f8);
    //LCD_Clear(0xf800);
    for(;;);
}

效果(白色是因为反光,不是屏幕显示问题):
QQ截图20151211105037
完整源文件如下:
800x480_RGB_429
PS:马上要过年了,更新可能要延缓哦...

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注