标题: STM32单片机移植emwin不显示直接黑屏? [打印本页]

作者: 南湖悲    时间: 2024-9-25 14:17
标题: STM32单片机移植emwin不显示直接黑屏?
我用的是原子的战舰V4板,lcd显示屏是在网上买的5寸屏幕,854*480的程序是正点提供的官方emwin例程,lcd的驱动程序事先验证过能够正常显示包括字符串文字
lcd的画点函数以及读点函数等都是用的正点的函数,只是改了底层配置
但是跟着正点加入emwin的程序后就不能正常显示移植黑屏,有没有大佬知道具体的原因
代码如下:

这里是单片机主程序
int main(void)
{
    HAL_Init();                         /* 初始化HAL库 */
    sys_stm32_clock_init(RCC_PLL_MUL9); /* 设置时钟, 72Mhz */
    delay_init(72);                     /* 延时初始化 */
    usart_init(115200);                 /* 串口初始化为115200 */
    usmart_dev.init(72);                /* 初始化USMART */
    led_init();                         /* 初始化LED */
    lcd_init();                         /* 初始化LCD */
    key_init();                         /* 初始化按键 */
    sram_init();                        /* SRAM初始化 */
    my_mem_init(SRAMIN);                /* 初始化内部SRAM内存池 */
    my_mem_init(SRAMEX);                /* 初始化外部SRAM内存池 */
    btim_timx_int_init(999,71);         /* 定时1ms */
    __HAL_RCC_CRC_CLK_ENABLE();         /* 使能CRC时钟 */
    GUI_Init();                         /* emWin 初始化 */
//    GUIDEMO_Main();
        GUI_SetBkColor(GUI_RED);                                              /* 设置背景颜色 */
        GUI_SetColor(GUI_BLUE);
        GUI_Clear();                                                                          /* 清屏 */
        GUI_SetColor(GUI_BLACK);                                                  /* 设置颜色 */
        GUI_SetFont(&GUI_Font32_ASCII);                                     /* 设置字体 */
        GUI_DispStringAt("Hello emWin!", 0, 0);                            /* 在指定位置显示字符串 */

    while(1);
}


下面是显示相关的函数
static void _SetPixelIndex(GUI_DEVICE * pDevice, int x, int y, LCD_PIXELINDEX PixelIndex) {
  #ifdef WIN32
    LCDSIM_SetPixelIndex(x, y, PixelIndex, pDevice->LayerIndex);
  #else
    //
    // Convert logical into physical coordinates (Dep. on LCDConf.h)
    //
    #if (LCD_MIRROR_X == 1) || (LCD_MIRROR_Y == 1) || (LCD_SWAP_XY == 1)
      int xPhys, yPhys;

      xPhys = LOG2PHYS_X(x, y);
      yPhys = LOG2PHYS_Y(x, y);
    #else
      #define xPhys x
      #define yPhys y
    #endif
    GUI_USE_PARA(pDevice);
    GUI_USE_PARA(x);
    GUI_USE_PARA(y);
    GUI_USE_PARA(PixelIndex);
    {
      //
      // Write into hardware ... Adapt to your system
      //
      // TBD by customer...
      //
        lcd_draw_point(x,y,PixelIndex);
    }
    #if (LCD_MIRROR_X == 0) && (LCD_MIRROR_Y == 0) && (LCD_SWAP_XY == 0)
      #undef xPhys
      #undef yPhys
    #endif
  #endif
}


static LCD_PIXELINDEX _GetPixelIndex(GUI_DEVICE * pDevice, int x, int y) {
  LCD_PIXELINDEX PixelIndex;
  #ifdef WIN32
    PixelIndex = LCDSIM_GetPixelIndex(x, y, pDevice->LayerIndex);
  #else
    //
    // Convert logical into physical coordinates (Dep. on LCDConf.h)
    //
    #if (LCD_MIRROR_X == 1) || (LCD_MIRROR_Y == 1) || (LCD_SWAP_XY == 1)
      int xPhys, yPhys;

      xPhys = LOG2PHYS_X(x, y);
      yPhys = LOG2PHYS_Y(x, y);
    #else
      #define xPhys x
      #define yPhys y
    #endif
    GUI_USE_PARA(pDevice);
    GUI_USE_PARA(x);
    GUI_USE_PARA(y);
    {
      //
      // Write into hardware ... Adapt to your system
      //
      // TBD by customer...
      //
      PixelIndex = lcd_read_point(x,y);
    }
    #if (LCD_MIRROR_X == 0) && (LCD_MIRROR_Y == 0) && (LCD_SWAP_XY == 0)
      #undef xPhys
      #undef yPhys
    #endif
  #endif
  return PixelIndex;
}

static void _FillRect(GUI_DEVICE * pDevice, int x0, int y0, int x1, int y1) {

        int x;
    if (GUI_pContext->DrawMode & LCD_DRAWMODE_XOR)
    {
        for (; y0 <= y1; y0++)
        {
            for (x = x0; x <= x1; x++)
            {
                _XorPixel(pDevice, x, y0);
            }
        }
    }
    else
    {
        lcd_fill(x0,y0,x1,y1,LCD_COLORINDEX);
    }
}


static void _DrawBitLine16BPP(GUI_DEVICE * pDevice, int x, int y, U16 const * p, int xsize) {

    LCD_PIXELINDEX pixel;
    lcd_set_cursor(x,y);
    *(__IO uint16_t *)(UCGUI_LCD_CMD) = lcddev.wramcmd; /* 写入颜色值 */
    for (;xsize > 0; xsize --, x++, p++)
    {
      pixel = *p;
      *(__IO uint16_t *)(UCGUI_LCD_DATA) = pixel;
    }
}



作者: zhuls    时间: 2024-9-28 10:07
LCD的接线、驱动对不对哦?
作者: 南湖悲    时间: 2024-9-28 15:00
都是对的,我已经找到问题了
作者: 南湖悲    时间: 2024-9-28 15:02
我用的是正点原子的板子和代码,在SRAM初始化里面将 fsmc_readwritetim.DataSetupTime = 0x00; 改为0x03,就正常了,之前问题我没描述好,程序是卡死在了GUI_Init()里面了




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1