打印
[MM32硬件]

TFTLCD FSMC方式驱动

[复制链接]
836|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
tpgf|  楼主 | 2024-4-8 09:45 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
一、FSMC手册资料

FSMC方式可以驱动多种类型的总线设备,这里显示屏使用的是8080控制方式。




二、代码

主要代码部分如下
2.1、lcd.c

/*
* Copyright 2021 MindMotion Microelectronics Co., Ltd.
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include "lcd.h"
#include "board_init.h"
#include "delay.h"

extern void LCD_InitHardware(void);
extern void LCD_WriteCmd(uint16_t cmd);
extern void LCD_WriteData(uint16_t dat);
extern uint16_t LCD_ReadData(void);


static void lcd_rst(void)
{
    GPIO_SetBits(BOARD_LCD_RST_GPIO_PORT, BOARD_LCD_RST_GPIO_PIN);   
    delay_ms(1);
    GPIO_ClearBits(BOARD_LCD_RST_GPIO_PORT, BOARD_LCD_RST_GPIO_PIN);  
    delay_ms(10);             // This delay time is necessary
    GPIO_SetBits(BOARD_LCD_RST_GPIO_PORT, BOARD_LCD_RST_GPIO_PIN);
    delay_ms(120);
}


void LCD_Init(LCD_Init_Type * init)
{
        uint32_t id=0;
        LCD_InitHardware();
        lcd_rst();

        LCD_WriteCmd(0x0011);        //exit SLEEP mode
        delay_ms(120);

        LCD_WriteCmd(0x0036);
        LCD_WriteData(0x0060);            //MADCTL: memory data access control
        LCD_WriteCmd(0x003A);
        LCD_WriteData(0x0005);            //COLMOD: Interface Pixel format *** I use 262K-colors in 18bit/pixel format when using 8-bit interface to allow 3-bytes per pixel
    //    TFT_24_7789_Write_Command(0x003A);TFT_24_7789_Write_Data(0x0055);//COLMOD: Interface Pixel format  *** I use 65K-colors in 16bit/pixel (5-6-5) format when using 16-bit interface to allow 1-byte per pixel
        LCD_WriteCmd(0x00B2);
        LCD_WriteData(0x000C);
        LCD_WriteData(0x000C);
        LCD_WriteData(0x0000);
        LCD_WriteData(0x0033);
        LCD_WriteData(0x0033);            //PORCTRK: Porch setting
        LCD_WriteCmd(0x00B7);
        LCD_WriteData(0x0035);            //GCTRL: Gate Control
        LCD_WriteCmd(0x00BB);
        LCD_WriteData(0x001c);            //VCOMS: VCOM setting
        LCD_WriteCmd(0x00C0);
        LCD_WriteData(0x002C);            //LCMCTRL: LCM Control
        LCD_WriteCmd(0x00C2);
        LCD_WriteData(0x0001);
        LCD_WriteData(0x00FF);            //VDVVRHEN: VDV and VRH Command Enable
        LCD_WriteCmd(0x00C3);
        LCD_WriteData(0x000B);            //VRHS: VRH Set
        LCD_WriteCmd(0x00C4);
        LCD_WriteData(0x0020);            //VDVS: VDV Set
        LCD_WriteCmd(0x00C6);
        LCD_WriteData(0x000F);            //FRCTRL2: Frame Rate control in normal mode
        LCD_WriteCmd(0x00D0);
        LCD_WriteData(0x00A4);
        LCD_WriteData(0x00A1);            //PWCTRL1: Power Control 1
        LCD_WriteCmd(0x00E0);
        LCD_WriteData(0x00D0);
        LCD_WriteData(0x0000);
        LCD_WriteData(0x0003);
        LCD_WriteData(0x0009);
        LCD_WriteData(0x0013);
        LCD_WriteData(0x001c);
        LCD_WriteData(0x003a);
        LCD_WriteData(0x0055);
        LCD_WriteData(0x0048);
        LCD_WriteData(0x0018);
        LCD_WriteData(0x0012);
        LCD_WriteData(0x000e);
        LCD_WriteData(0x0019);
        LCD_WriteData(0x001e);            //PVGAMCTRL: Positive Voltage Gamma control
        LCD_WriteCmd(0x00E1);
        LCD_WriteData(0x00D0);
        LCD_WriteData(0x0000);
        LCD_WriteData(0x0003);
        LCD_WriteData(0x0009);
        LCD_WriteData(0x0005);
        LCD_WriteData(0x0025);
        LCD_WriteData(0x003a);
        LCD_WriteData(0x0055);
        LCD_WriteData(0x0050);
        LCD_WriteData(0x003d);
        LCD_WriteData(0x001c);
        LCD_WriteData(0x001d);
        LCD_WriteData(0x001d);
        LCD_WriteData(0x001e);            
        LCD_WriteCmd(0x0029);                //display ON
}

void LCD_SetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
{
    LCD_WriteCmd(0x2a);
    LCD_WriteData(x0 >> 8);
    LCD_WriteData(x0 & 0xff);
    LCD_WriteData(x1 >> 8);
    LCD_WriteData(x1 & 0xff);
    LCD_WriteCmd(0x2b);
    LCD_WriteData(y0 >> 8);
    LCD_WriteData(y0 & 0xff);
    LCD_WriteData(y1 >> 8);
    LCD_WriteData(y1 & 0xff);
}

void LCD_ClearWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color)
{
    LCD_SetWindow(x0, y0, x1, y1);
    LCD_WriteCmd(0x2c);
    for(uint32_t i = 0; i <= x1 - x0; i++)
    {
        for(uint32_t j = 0; j <= y1 - y0; j++)
        {
            LCD_WriteData(color);
        }
    }
}

void LCD_FillWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t * color)
{
    LCD_SetWindow(x0, y0, x1, y1);
    LCD_WriteCmd(0x2c);
    for(uint32_t i = 0; i <= x1 - x0; i++)
    {
        for(uint32_t j = 0; j <= y1 - y0; j++)
        {
            LCD_WriteData((* color++));
        }
    }
}

void LCD_DrawPixel(uint16_t x, uint16_t y, uint16_t color)
{
    LCD_ClearWindow(x, y, x, y, color);
}



2.2、lcd_port.c

/*
* Copyright 2021 MindMotion Microelectronics Co., Ltd.
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include "lcd.h"
#include "board_init.h"


void LCD_InitHardware(void)
{
    FSMC_Init_Type fsmc_init =
    {
        .MemType = FSMC_MemType_SRAM,
        .MemSize = FSMC_MemSize_64MB
    };
    FSMC_Conf_Type fsmc_conf =
    {
        .ReadPeriod    = 0x1u,
        .AddrSetTime   = 0x3u,
        .WriteHoldTime = 0x1u,
        .WritePeriod   = 0x2u,
        .ReadySignal   = FSMC_ReadySignal_Internal,
        .SMReadPipe    = 0u,
        .BusWidth      = FSMC_BusWidth_16b
    };

    FSMC_Init(BOARD_LCD_FSMC_PORT, 3, &fsmc_init);
    FSMC_SetConf(BOARD_LCD_FSMC_PORT, BOARD_LCD_FSMC_SET_INDEX, &fsmc_conf);
    FSMC_EnableConf(BOARD_LCD_FSMC_PORT, 3, BOARD_LCD_FSMC_SET_INDEX);

    GPIO_WriteBit(BOARD_LCD_BL_GPIO_PORT, BOARD_LCD_BL_GPIO_PIN, 1u); /* enable back light. */
}

void LCD_WriteCmd(uint16_t cmd)
{
    FSMC_PutData16(BOARD_LCD_FSMC_PORT, 3, 0, cmd);
}

void LCD_WriteData(uint16_t dat)
{
    FSMC_PutData16(BOARD_LCD_FSMC_PORT, 3, (1u << BOARD_LCD_FSMC_RS_BIT_INDEX), dat);
}

uint16_t LCD_ReadData(void)
{
    return FSMC_GetData16(BOARD_LCD_FSMC_PORT, 3, (1 << BOARD_LCD_FSMC_RS_BIT_INDEX));
}

/* EOF. */



2.3、main.c

int main(void)
{
        BOARD_Init();
        delay_init();
        /* init the lcd. */
    LCD_Init_Type lcd_init =
    {
        .DisplayMode = LCD_DisplayMode_Landspace,
    };
    LCD_Init(&lcd_init);
        printf("\r\nmm32f5270 test.\r\n");
        while(1)
        {               
                GPIO_WriteBit(BOARD_LED0_GPIO_PORT, BOARD_LED0_GPIO_PIN, 1u);
                delay_ms(100);
                GPIO_WriteBit(BOARD_LED0_GPIO_PORT, BOARD_LED0_GPIO_PIN, 0u);
                delay_ms(100);

                LCD_ClearWindow(0u, 0u, BOARD_LCD_HEIGHT-1u, BOARD_LCD_WIDTH-1u, LCD_COLOR_RED);

        delay_ms(1000);
                LCD_ClearWindow(0u, 0u, BOARD_LCD_HEIGHT-1u, BOARD_LCD_WIDTH-1u, LCD_COLOR_GREEN);

        delay_ms(1000);
                LCD_ClearWindow(0u, 0u, BOARD_LCD_HEIGHT-1u, BOARD_LCD_WIDTH-1u, LCD_COLOR_BLUE);
                delay_ms(1000);

        }
}


三、程序运行
显示刷屏



————————————————

                            版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

原文链接:https://blog.csdn.net/weixin_47569031/article/details/127427167

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1975

主题

15764

帖子

12

粉丝