查看: 915|回复: 0

[分享] 【庆典三:项目速成设计】MCXN947之LCD显示

[复制链接]
  • TA的每日心情
    奋斗
    昨天 17:40
  • 签到天数: 2485 天

    连续签到: 110 天

    [LV.Master]伴坛终老

    25

    主题

    7737

    帖子

    21

    金牌会员

    Rank: 6Rank: 6

    积分
    14954
    最后登录
    2025-8-23
    发表于 2024-12-21 19:10:37 | 显示全部楼层 |阅读模式
    本帖最后由 yinwuqing 于 2024-12-21 19:18 编辑

    一、简介
         前段时间参加了安富利与与非网联合举办的NXP FRDM-MCXN947评测活动,该开发板的性能与外设接口都比较优秀,该开发板更合适开发神经网络单元的应用,板上MCU丝印:MCXN947VCTA,官方提供的资料是基于MCXN947VDFT的,两者相差不大,都属于双核架构,搭载Arm Cortex-M33内核,主频高达150MHz。开发板的资源框架如下:
    框架.png
    二、屏接口介绍
          论坛上有许多小伙伴使用配套的LCD去实现LVGL图形显示,由于板上有预留的J8插座是专门针对LCD模块的,因此有了配套的LCD模块就很好验证官方提供的demo示例了。这里简介驱动SPI串口屏,此屏是基于ST7735S的,ST7735S是用于262K彩色图形型TFT-LCD的单芯片控制器/驱动器。由396条组成源极线和162个栅极线驱动电路。
          此屏是笔者在得捷电子商城上购买的,AFL128160A0-1.77N12NTM-ANO屏为1.77寸,分辨率128*160。模块有预留触摸功能部分的电路,开发者可自行购买相对于TP IC。这里我们只是简单驱动显示,因此只需连接SPI这部分接口。硬件连接如下图:
    接线.jpg
          正如上图所示,我们用到8根杜邦线,都集成在J8接口上,对应关系如下:
    接口原理图.png
    ST7735STFT-LCD屏                 FRDM-MCXN947开发板
    VCC                                           P3V3
    GND                                          GND
    SCLK                                         P4_1(SCL)
    MOSI                                        P4_0(SDA)
    DC(Data/Command)              P0_7
    CS(Chip Select)                       P0_12
    BLK(Backlight)                        P4_5
    RES                                           P4_7

    三、参考代码
    pin_mux.c
    1. #include "fsl_common.h"
    2. #include "fsl_port.h"
    3. #include "fsl_gpio.h"
    4. #include "pin_mux.h"

    5. void BOARD_InitBootPins(void)
    6. {
    7.     BOARD_InitPins();
    8. }

    9. void BOARD_InitPins(void)
    10. {
    11.     /* Enables the clock for PORT0 controller: Enables clock */
    12.     CLOCK_EnableClock(kCLOCK_Port0);
    13.    /* Enables the clock for PORT1 controller: Enables clock */
    14.     CLOCK_EnableClock(kCLOCK_Port1);
    15.     CLOCK_EnableClock(kCLOCK_Port4);

    16.     gpio_pin_config_t LCD_GPIO_config0 = {
    17.       .pinDirection = kGPIO_DigitalOutput,
    18.       .outputLogic = 0U,
    19.   };
    20.     gpio_pin_config_t LCD_GPIO_config1 = {
    21.       .pinDirection = kGPIO_DigitalOutput,
    22.       .outputLogic = 1U,
    23.   };
    24.         
    25.   GPIO_PinInit(GPIO0, 7U, &LCD_GPIO_config0);
    26.   GPIO_PinInit(GPIO0, 12U, &LCD_GPIO_config0);
    27.   GPIO_PinInit(GPIO4, 0U, &LCD_GPIO_config0);
    28.   GPIO_PinInit(GPIO4, 1U, &LCD_GPIO_config0);
    29.   GPIO_PinInit(GPIO4, 5U, &LCD_GPIO_config0);
    30.   GPIO_PinInit(GPIO4, 7U, &LCD_GPIO_config0);
    31.         
    32.    PORT_SetPinMux(PORT0, 7U, kPORT_MuxAlt0);
    33.    PORT_SetPinMux(PORT0, 12U,kPORT_MuxAlt0);
    34.    PORT_SetPinMux(PORT4, 0U, kPORT_MuxAlt0);
    35.    PORT_SetPinMux(PORT4, 1U, kPORT_MuxAlt0);
    36.    PORT_SetPinMux(PORT4, 5U, kPORT_MuxAlt0);
    37.    PORT_SetPinMux(PORT4, 7U, kPORT_MuxAlt0);

    38.    const port_pin_config_t port0_7_config = {/* Internal pull-up/down resistor is disabled */
    39.                                                       kPORT_PullDisable,
    40.                                                       /* Low internal pull resistor value is selected. */
    41.                                                       kPORT_LowPullResistor,
    42.                                                       /* Fast slew rate is configured */
    43.                                                       kPORT_FastSlewRate,
    44.                                                       /* Passive input filter is disabled */
    45.                                                       kPORT_PassiveFilterDisable,
    46.                                                       /* Open drain output is disabled */
    47.                                                       kPORT_OpenDrainDisable,
    48.                                                       /* Low drive strength is configured */
    49.                                                       kPORT_LowDriveStrength,
    50.                                                       /* Pin is configured as PIO0_10 */
    51.                                                       kPORT_MuxAlt0,
    52.                                                       /* Digital input enabled */
    53.                                                       kPORT_InputBufferEnable,
    54.                                                       /* Digital input is not inverted */
    55.                                                       kPORT_InputNormal,
    56.                                                       /* Pin Control Register fields [15:0] are not locked */
    57.                                                       kPORT_UnlockRegister};

    58.    const port_pin_config_t port0_10_pinB12_config = {/* Internal pull-up/down resistor is disabled */
    59.                                                       kPORT_PullDisable,
    60.                                                       /* Low internal pull resistor value is selected. */
    61.                                                       kPORT_LowPullResistor,
    62.                                                       /* Fast slew rate is configured */
    63.                                                       kPORT_FastSlewRate,
    64.                                                       /* Passive input filter is disabled */
    65.                                                       kPORT_PassiveFilterDisable,
    66.                                                       /* Open drain output is disabled */
    67.                                                       kPORT_OpenDrainDisable,
    68.                                                       /* Low drive strength is configured */
    69.                                                       kPORT_LowDriveStrength,
    70.                                                       /* Pin is configured as PIO0_10 */
    71.                                                       kPORT_MuxAlt0,
    72.                                                       /* Digital input enabled */
    73.                                                       kPORT_InputBufferEnable,
    74.                                                       /* Digital input is not inverted */
    75.                                                       kPORT_InputNormal,
    76.                                                       /* Pin Control Register fields [15:0] are not locked */
    77.                                                       kPORT_UnlockRegister};
    78.     /* PORT0_10 (pin B12) is configured as PIO0_10 */
    79.     PORT_SetPinConfig(PORT0, 10U, &port0_10_pinB12_config);
    80.                                                                                                                                                                                                   
    81.     const port_pin_config_t port0_27_pinE10_config = {/* Internal pull-up/down resistor is disabled */
    82.                                                       kPORT_PullDisable,
    83.                                                       /* Low internal pull resistor value is selected. */
    84.                                                       kPORT_LowPullResistor,
    85.                                                       /* Fast slew rate is configured */
    86.                                                       kPORT_FastSlewRate,
    87.                                                       /* Passive input filter is disabled */
    88.                                                       kPORT_PassiveFilterDisable,
    89.                                                       /* Open drain output is disabled */
    90.                                                       kPORT_OpenDrainDisable,
    91.                                                       /* Low drive strength is configured */
    92.                                                       kPORT_LowDriveStrength,
    93.                                                       /* Pin is configured as PIO0_27 */
    94.                                                       kPORT_MuxAlt0,
    95.                                                       /* Digital input enabled */
    96.                                                       kPORT_InputBufferEnable,
    97.                                                       /* Digital input is not inverted */
    98.                                                       kPORT_InputNormal,
    99.                                                       /* Pin Control Register fields [15:0] are not locked */
    100.                                                       kPORT_UnlockRegister};
    101.     /* PORT0_27 (pin E10) is configured as PIO0_27 */
    102.     PORT_SetPinConfig(PORT0, 27U, &port0_27_pinE10_config);

    103.     const port_pin_config_t port1_2_pinC04_config = {/* Internal pull-up/down resistor is disabled */
    104.                                                       kPORT_PullDisable,
    105.                                                       /* Low internal pull resistor value is selected. */
    106.                                                       kPORT_LowPullResistor,
    107.                                                       /* Fast slew rate is configured */
    108.                                                       kPORT_FastSlewRate,
    109.                                                       /* Passive input filter is disabled */
    110.                                                       kPORT_PassiveFilterDisable,
    111.                                                       /* Open drain output is disabled */
    112.                                                       kPORT_OpenDrainDisable,
    113.                                                       /* Low drive strength is configured */
    114.                                                       kPORT_LowDriveStrength,
    115.                                                       /* Pin is configured as PIO1_2 */
    116.                                                       kPORT_MuxAlt0,
    117.                                                       /* Digital input enabled */
    118.                                                       kPORT_InputBufferEnable,
    119.                                                       /* Digital input is not inverted */
    120.                                                       kPORT_InputNormal,
    121.                                                       /* Pin Control Register fields [15:0] are not locked */
    122.                                                       kPORT_UnlockRegister};
    123.     /* PORT1_2 (pin C04) is configured as PIO1_2 */
    124.     PORT_SetPinConfig(PORT1, 2U, &port1_2_pinC04_config);                                                                                                                                                                                                                        
    125.     const port_pin_config_t port0_2_pinB16_config = {/* Internal pull-up/down resistor is disabled */
    126.                                                      kPORT_PullDisable,
    127.                                                      /* Low internal pull resistor value is selected. */
    128.                                                      kPORT_LowPullResistor,
    129.                                                      /* Fast slew rate is configured */
    130.                                                      kPORT_FastSlewRate,
    131.                                                      /* Passive input filter is disabled */
    132.                                                      kPORT_PassiveFilterDisable,
    133.                                                      /* Open drain output is disabled */
    134.                                                      kPORT_OpenDrainDisable,
    135.                                                      /* High drive strength is configured */
    136.                                                      kPORT_HighDriveStrength,
    137.                                                      /* Pin is configured as SWO */
    138.                                                      kPORT_MuxAlt1,
    139.                                                      /* Digital input enabled */
    140.                                                      kPORT_InputBufferEnable,
    141.                                                      /* Digital input is not inverted */
    142.                                                      kPORT_InputNormal,
    143.                                                      /* Pin Control Register fields [15:0] are not locked */
    144.                                                      kPORT_UnlockRegister};
    145.     /* PORT0_2 (pin B16) is configured as SWO */
    146.     PORT_SetPinConfig(PORT0, 2U, &port0_2_pinB16_config);
    147.                                                                                                                                                                                                    
    148.     PORT_SetPinConfig(PORT0, 7U, &port0_7_config);
    149.     PORT_SetPinConfig(PORT0, 12U,&port0_7_config);
    150.                                                                                                                                                                                                    
    151.    PORT_SetPinConfig(PORT4, 0U, &port0_7_config);
    152.    PORT_SetPinConfig(PORT4, 1U, &port0_7_config);
    153.    PORT_SetPinConfig(PORT4, 5U, &port0_7_config);
    154.    PORT_SetPinConfig(PORT4, 7U, &port0_7_config);
    155. }
    复制代码
    1. void LCD_Init(void)
    2. {
    3.         
    4.         LCD_RES_Clr();
    5.         SysTick_DelayTicks(1000);
    6.         LCD_RES_Set();
    7.         SysTick_DelayTicks(1000);
    8.         
    9.         LCD_BLK_Set();
    10.         SysTick_DelayTicks(120000);

    11.         LCD_WR_REG(0x11); //Sleep out
    12.         SysTick_DelayTicks(120000);  //Delay 120ms

    13.         LCD_WR_REG(0xB1);
    14.         LCD_WR_DATA8(0x05);
    15.         LCD_WR_DATA8(0x3C);
    16.         LCD_WR_DATA8(0x3C);
    17.         LCD_WR_REG(0xB2);
    18.         LCD_WR_DATA8(0x05);
    19.         LCD_WR_DATA8(0x3C);
    20.         LCD_WR_DATA8(0x3C);
    21.         LCD_WR_REG(0xB3);
    22.         LCD_WR_DATA8(0x05);
    23.         LCD_WR_DATA8(0x3C);
    24.         LCD_WR_DATA8(0x3C);
    25.         LCD_WR_DATA8(0x05);
    26.         LCD_WR_DATA8(0x3C);
    27.         LCD_WR_DATA8(0x3C);

    28.         LCD_WR_REG(0xB4); //Dot inversion
    29.         LCD_WR_DATA8(0x03);

    30.         LCD_WR_REG(0xC0);
    31.         LCD_WR_DATA8(0x28);
    32.         LCD_WR_DATA8(0x08);
    33.         LCD_WR_DATA8(0x04);
    34.         LCD_WR_REG(0xC1);
    35.         LCD_WR_DATA8(0XC0);
    36.         LCD_WR_REG(0xC2);
    37.         LCD_WR_DATA8(0x0D);
    38.         LCD_WR_DATA8(0x00);
    39.         LCD_WR_REG(0xC3);
    40.         LCD_WR_DATA8(0x8D);
    41.         LCD_WR_DATA8(0x2A);
    42.         LCD_WR_REG(0xC4);
    43.         LCD_WR_DATA8(0x8D);
    44.         LCD_WR_DATA8(0xEE);
    45.         LCD_WR_REG(0xC5); //VCOM
    46.         LCD_WR_DATA8(0x1A);
    47.         LCD_WR_REG(0x36); //MX, MY, RGB mode
    48.         if(USE_HORIZONTAL==0)LCD_WR_DATA8(0x00);
    49.         else if(USE_HORIZONTAL==1)LCD_WR_DATA8(0xC0);
    50.         else if(USE_HORIZONTAL==2)LCD_WR_DATA8(0x70);
    51.         else LCD_WR_DATA8(0xA0);

    52.         LCD_WR_REG(0xE0);
    53.         LCD_WR_DATA8(0x04);
    54.         LCD_WR_DATA8(0x22);
    55.         LCD_WR_DATA8(0x07);
    56.         LCD_WR_DATA8(0x0A);
    57.         LCD_WR_DATA8(0x2E);
    58.         LCD_WR_DATA8(0x30);
    59.         LCD_WR_DATA8(0x25);
    60.         LCD_WR_DATA8(0x2A);
    61.         LCD_WR_DATA8(0x28);
    62.         LCD_WR_DATA8(0x26);
    63.         LCD_WR_DATA8(0x2E);
    64.         LCD_WR_DATA8(0x3A);
    65.         LCD_WR_DATA8(0x00);
    66.         LCD_WR_DATA8(0x01);
    67.         LCD_WR_DATA8(0x03);
    68.         LCD_WR_DATA8(0x13);
    69.         LCD_WR_REG(0xE1);
    70.         LCD_WR_DATA8(0x04);
    71.         LCD_WR_DATA8(0x16);
    72.         LCD_WR_DATA8(0x06);
    73.         LCD_WR_DATA8(0x0D);
    74.         LCD_WR_DATA8(0x2D);
    75.         LCD_WR_DATA8(0x26);
    76.         LCD_WR_DATA8(0x23);
    77.         LCD_WR_DATA8(0x27);
    78.         LCD_WR_DATA8(0x27);
    79.         LCD_WR_DATA8(0x25);
    80.         LCD_WR_DATA8(0x2D);
    81.         LCD_WR_DATA8(0x3B);
    82.         LCD_WR_DATA8(0x00);
    83.         LCD_WR_DATA8(0x01);
    84.         LCD_WR_DATA8(0x04);
    85.         LCD_WR_DATA8(0x13);

    86.         LCD_WR_REG(0x3A); //65k mode
    87.         LCD_WR_DATA8(0x05);
    88.         LCD_WR_REG(0x29); //Display on
    89. }
    复制代码
    1. #include "pin_mux.h"
    2. #include "peripherals.h"
    3. #include "board.h"
    4. #include "pic.h"
    5. #include "lcd_init.h"

    6. typedef struct
    7. {
    8.         unsigned char Index[2];
    9.         unsigned char Msk[32];
    10. }typFNT_GB16;
    11. /*******************************************************************************
    12. * Prototypes
    13. ******************************************************************************/
    14. extern const typFNT_GB16 tfont16[];
    15. /*******************************************************************************
    16. * Variables
    17. ******************************************************************************/
    18. volatile uint32_t g_systickCounter;
    19. /*******************************************************************************
    20. * Code
    21. ******************************************************************************/

    22. void SysTick_Handler(void)
    23. {
    24.     if (g_systickCounter != 0U)
    25.     {
    26.         g_systickCounter--;
    27.     }
    28. }

    29. void SysTick_DelayTicks(uint32_t n)
    30. {
    31.     g_systickCounter = n;
    32.     while (g_systickCounter != 0U)
    33.     {
    34.     }
    35. }

    36. void Display_title(void)
    37. {
    38.         LCD_Fill(0,0,LCD_W,LCD_H,LIGHTBLUE);
    39.         LCD_ShowIntNum(8,10,2024,4,BLUE,GREEN,16);
    40.         LCD_ShowChinese(40,10,&tfont16[0],BLUE,GREEN,16,0);
    41.         LCD_ShowChinese(56,10,&tfont16[1],BLUE,GREEN,16,0);
    42.         LCD_ShowChinese(72,10,&tfont16[2],BLUE,GREEN,16,0);
    43.         LCD_ShowChinese(88,10,&tfont16[3],BLUE,GREEN,16,0);
    44.         LCD_ShowChinese(104,10,&tfont16[4],BLUE,GREEN,16,0);
    45.         LCD_ShowChinese(8,30,&tfont16[5],BLUE,GREEN,16,0);
    46.         LCD_ShowChinese(24,30,&tfont16[6],BLUE,GREEN,16,0);
    47.         LCD_ShowString(40,30,"MCX",BLUE,GREEN,16,0);
    48.         LCD_ShowString(64,30," ",BLUE,GREEN,16,0);
    49.         LCD_ShowString(72,30,"N",BLUE,GREEN,16,0);
    50.         LCD_ShowString(80,30," ",BLUE,GREEN,16,0);
    51.         LCD_ShowChinese(88,30,&tfont16[7],BLUE,GREEN,16,0);
    52.         LCD_ShowChinese(104,30,&tfont16[8],BLUE,GREEN,16,0);
    53.         
    54.         LCD_ShowChinese(8,50,&tfont16[9],BLUE,GREEN,16,0);
    55.         LCD_ShowChinese(24,50,&tfont16[10],BLUE,GREEN,16,0);
    56.         LCD_ShowChinese(40,50,&tfont16[11],BLUE,GREEN,16,0);
    57.         LCD_ShowChinese(56,50,&tfont16[12],BLUE,GREEN,16,0);
    58.         LCD_ShowChinese(72,50,&tfont16[13],BLUE,GREEN,16,0);
    59.         LCD_ShowChinese(88,50,&tfont16[5],BLUE,GREEN,16,0);
    60.         LCD_ShowChinese(104,50,&tfont16[14],BLUE,GREEN,16,0);
    61.         LCD_ShowChinese(8,70,&tfont16[15],BLUE,GREEN,16,0);
    62.         LCD_ShowChinese(24,70,&tfont16[16],BLUE,GREEN,16,0);
    63.         LCD_ShowString(44,140,"2024-12-20",BLUE,GREEN,16,0);
    64.         SysTick_DelayTicks(500000);
    65. }

    66. /*!
    67. * @brief Main function
    68. */
    69. int main(void)
    70. {
    71.     CLOCK_EnableClock(kCLOCK_Gpio0);
    72.     CLOCK_EnableClock(kCLOCK_Gpio1);
    73.     CLOCK_EnableClock(kCLOCK_Gpio4);
    74.     BOARD_InitPins();
    75.     LED_RED_INIT(LOGIC_LED_OFF);
    76.     LED_BLUE_INIT(LOGIC_LED_OFF);
    77.     LED_GREEN_INIT(LOGIC_LED_OFF);
    78.         
    79.     /* Set systick reload value to generate 1ms interrupt */
    80.     if (SysTick_Config(SystemCoreClock / 1000000U))
    81.     {
    82.         while (1)
    83.         {
    84.         }
    85.     }
    86.                
    87.         LCD_Init();
    88.         SysTick_DelayTicks(200U);
    89.         LCD_Fill(0,0,LCD_W,LCD_H,YELLOW);
    90.         SysTick_DelayTicks(200);
    91.         LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
    92.         while (1)
    93.         {
    94.                         LCD_ShowPicture(0,0,128,160,gImage_1);
    95.                         SysTick_DelayTicks(500000);
    96.                         Display_title();
    97.                         LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
    98.                         LCD_ShowPicture(0,0,91,160,gImage_2);
    99.                         SysTick_DelayTicks(500000);
    100.                 }
    101. }
    复制代码
    四、显示效果
            画的bmp图使用Img2Lcd工具导出数组。圣诞节快到了,提前祝大伙圣诞节快乐!感谢在2024年里,与论坛的一路同行!
    导入图片.png
    圣诞节.png
    显示.gif
    该会员没有填写今日想说内容.
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-8-24 14:26 , Processed in 0.089373 second(s), 20 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表