在线时间1124 小时
UID1694538
注册时间2018-5-21
NXP金币5614
TA的每日心情 | 奋斗 昨天 17:40 |
---|
签到天数: 2485 天 连续签到: 110 天 [LV.Master]伴坛终老
金牌会员
 
- 积分
- 14954
- 最后登录
- 2025-8-23
|
本帖最后由 yinwuqing 于 2024-12-21 19:18 编辑
一、简介
前段时间参加了安富利与与非网联合举办的NXP FRDM-MCXN947评测活动,该开发板的性能与外设接口都比较优秀,该开发板更合适开发神经网络单元的应用,板上MCU丝印:MCXN947VCTA,官方提供的资料是基于MCXN947VDFT的,两者相差不大,都属于双核架构,搭载Arm Cortex-M33内核,主频高达150MHz。开发板的资源框架如下:
二、屏接口介绍
论坛上有许多小伙伴使用配套的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这部分接口。硬件连接如下图:
正如上图所示,我们用到8根杜邦线,都集成在J8接口上,对应关系如下:
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
- #include "fsl_common.h"
- #include "fsl_port.h"
- #include "fsl_gpio.h"
- #include "pin_mux.h"
- void BOARD_InitBootPins(void)
- {
- BOARD_InitPins();
- }
- void BOARD_InitPins(void)
- {
- /* Enables the clock for PORT0 controller: Enables clock */
- CLOCK_EnableClock(kCLOCK_Port0);
- /* Enables the clock for PORT1 controller: Enables clock */
- CLOCK_EnableClock(kCLOCK_Port1);
- CLOCK_EnableClock(kCLOCK_Port4);
- gpio_pin_config_t LCD_GPIO_config0 = {
- .pinDirection = kGPIO_DigitalOutput,
- .outputLogic = 0U,
- };
- gpio_pin_config_t LCD_GPIO_config1 = {
- .pinDirection = kGPIO_DigitalOutput,
- .outputLogic = 1U,
- };
-
- GPIO_PinInit(GPIO0, 7U, &LCD_GPIO_config0);
- GPIO_PinInit(GPIO0, 12U, &LCD_GPIO_config0);
- GPIO_PinInit(GPIO4, 0U, &LCD_GPIO_config0);
- GPIO_PinInit(GPIO4, 1U, &LCD_GPIO_config0);
- GPIO_PinInit(GPIO4, 5U, &LCD_GPIO_config0);
- GPIO_PinInit(GPIO4, 7U, &LCD_GPIO_config0);
-
- PORT_SetPinMux(PORT0, 7U, kPORT_MuxAlt0);
- PORT_SetPinMux(PORT0, 12U,kPORT_MuxAlt0);
- PORT_SetPinMux(PORT4, 0U, kPORT_MuxAlt0);
- PORT_SetPinMux(PORT4, 1U, kPORT_MuxAlt0);
- PORT_SetPinMux(PORT4, 5U, kPORT_MuxAlt0);
- PORT_SetPinMux(PORT4, 7U, kPORT_MuxAlt0);
- const port_pin_config_t port0_7_config = {/* Internal pull-up/down resistor is disabled */
- kPORT_PullDisable,
- /* Low internal pull resistor value is selected. */
- kPORT_LowPullResistor,
- /* Fast slew rate is configured */
- kPORT_FastSlewRate,
- /* Passive input filter is disabled */
- kPORT_PassiveFilterDisable,
- /* Open drain output is disabled */
- kPORT_OpenDrainDisable,
- /* Low drive strength is configured */
- kPORT_LowDriveStrength,
- /* Pin is configured as PIO0_10 */
- kPORT_MuxAlt0,
- /* Digital input enabled */
- kPORT_InputBufferEnable,
- /* Digital input is not inverted */
- kPORT_InputNormal,
- /* Pin Control Register fields [15:0] are not locked */
- kPORT_UnlockRegister};
- const port_pin_config_t port0_10_pinB12_config = {/* Internal pull-up/down resistor is disabled */
- kPORT_PullDisable,
- /* Low internal pull resistor value is selected. */
- kPORT_LowPullResistor,
- /* Fast slew rate is configured */
- kPORT_FastSlewRate,
- /* Passive input filter is disabled */
- kPORT_PassiveFilterDisable,
- /* Open drain output is disabled */
- kPORT_OpenDrainDisable,
- /* Low drive strength is configured */
- kPORT_LowDriveStrength,
- /* Pin is configured as PIO0_10 */
- kPORT_MuxAlt0,
- /* Digital input enabled */
- kPORT_InputBufferEnable,
- /* Digital input is not inverted */
- kPORT_InputNormal,
- /* Pin Control Register fields [15:0] are not locked */
- kPORT_UnlockRegister};
- /* PORT0_10 (pin B12) is configured as PIO0_10 */
- PORT_SetPinConfig(PORT0, 10U, &port0_10_pinB12_config);
-
- const port_pin_config_t port0_27_pinE10_config = {/* Internal pull-up/down resistor is disabled */
- kPORT_PullDisable,
- /* Low internal pull resistor value is selected. */
- kPORT_LowPullResistor,
- /* Fast slew rate is configured */
- kPORT_FastSlewRate,
- /* Passive input filter is disabled */
- kPORT_PassiveFilterDisable,
- /* Open drain output is disabled */
- kPORT_OpenDrainDisable,
- /* Low drive strength is configured */
- kPORT_LowDriveStrength,
- /* Pin is configured as PIO0_27 */
- kPORT_MuxAlt0,
- /* Digital input enabled */
- kPORT_InputBufferEnable,
- /* Digital input is not inverted */
- kPORT_InputNormal,
- /* Pin Control Register fields [15:0] are not locked */
- kPORT_UnlockRegister};
- /* PORT0_27 (pin E10) is configured as PIO0_27 */
- PORT_SetPinConfig(PORT0, 27U, &port0_27_pinE10_config);
- const port_pin_config_t port1_2_pinC04_config = {/* Internal pull-up/down resistor is disabled */
- kPORT_PullDisable,
- /* Low internal pull resistor value is selected. */
- kPORT_LowPullResistor,
- /* Fast slew rate is configured */
- kPORT_FastSlewRate,
- /* Passive input filter is disabled */
- kPORT_PassiveFilterDisable,
- /* Open drain output is disabled */
- kPORT_OpenDrainDisable,
- /* Low drive strength is configured */
- kPORT_LowDriveStrength,
- /* Pin is configured as PIO1_2 */
- kPORT_MuxAlt0,
- /* Digital input enabled */
- kPORT_InputBufferEnable,
- /* Digital input is not inverted */
- kPORT_InputNormal,
- /* Pin Control Register fields [15:0] are not locked */
- kPORT_UnlockRegister};
- /* PORT1_2 (pin C04) is configured as PIO1_2 */
- PORT_SetPinConfig(PORT1, 2U, &port1_2_pinC04_config);
- const port_pin_config_t port0_2_pinB16_config = {/* Internal pull-up/down resistor is disabled */
- kPORT_PullDisable,
- /* Low internal pull resistor value is selected. */
- kPORT_LowPullResistor,
- /* Fast slew rate is configured */
- kPORT_FastSlewRate,
- /* Passive input filter is disabled */
- kPORT_PassiveFilterDisable,
- /* Open drain output is disabled */
- kPORT_OpenDrainDisable,
- /* High drive strength is configured */
- kPORT_HighDriveStrength,
- /* Pin is configured as SWO */
- kPORT_MuxAlt1,
- /* Digital input enabled */
- kPORT_InputBufferEnable,
- /* Digital input is not inverted */
- kPORT_InputNormal,
- /* Pin Control Register fields [15:0] are not locked */
- kPORT_UnlockRegister};
- /* PORT0_2 (pin B16) is configured as SWO */
- PORT_SetPinConfig(PORT0, 2U, &port0_2_pinB16_config);
-
- PORT_SetPinConfig(PORT0, 7U, &port0_7_config);
- PORT_SetPinConfig(PORT0, 12U,&port0_7_config);
-
- PORT_SetPinConfig(PORT4, 0U, &port0_7_config);
- PORT_SetPinConfig(PORT4, 1U, &port0_7_config);
- PORT_SetPinConfig(PORT4, 5U, &port0_7_config);
- PORT_SetPinConfig(PORT4, 7U, &port0_7_config);
- }
复制代码- void LCD_Init(void)
- {
-
- LCD_RES_Clr();
- SysTick_DelayTicks(1000);
- LCD_RES_Set();
- SysTick_DelayTicks(1000);
-
- LCD_BLK_Set();
- SysTick_DelayTicks(120000);
- LCD_WR_REG(0x11); //Sleep out
- SysTick_DelayTicks(120000); //Delay 120ms
- LCD_WR_REG(0xB1);
- LCD_WR_DATA8(0x05);
- LCD_WR_DATA8(0x3C);
- LCD_WR_DATA8(0x3C);
- LCD_WR_REG(0xB2);
- LCD_WR_DATA8(0x05);
- LCD_WR_DATA8(0x3C);
- LCD_WR_DATA8(0x3C);
- LCD_WR_REG(0xB3);
- LCD_WR_DATA8(0x05);
- LCD_WR_DATA8(0x3C);
- LCD_WR_DATA8(0x3C);
- LCD_WR_DATA8(0x05);
- LCD_WR_DATA8(0x3C);
- LCD_WR_DATA8(0x3C);
- LCD_WR_REG(0xB4); //Dot inversion
- LCD_WR_DATA8(0x03);
- LCD_WR_REG(0xC0);
- LCD_WR_DATA8(0x28);
- LCD_WR_DATA8(0x08);
- 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(0x2A);
- LCD_WR_REG(0xC4);
- LCD_WR_DATA8(0x8D);
- LCD_WR_DATA8(0xEE);
- LCD_WR_REG(0xC5); //VCOM
- LCD_WR_DATA8(0x1A);
- LCD_WR_REG(0x36); //MX, MY, RGB mode
- if(USE_HORIZONTAL==0)LCD_WR_DATA8(0x00);
- else if(USE_HORIZONTAL==1)LCD_WR_DATA8(0xC0);
- else if(USE_HORIZONTAL==2)LCD_WR_DATA8(0x70);
- else LCD_WR_DATA8(0xA0);
- LCD_WR_REG(0xE0);
- LCD_WR_DATA8(0x04);
- LCD_WR_DATA8(0x22);
- LCD_WR_DATA8(0x07);
- LCD_WR_DATA8(0x0A);
- LCD_WR_DATA8(0x2E);
- LCD_WR_DATA8(0x30);
- LCD_WR_DATA8(0x25);
- LCD_WR_DATA8(0x2A);
- LCD_WR_DATA8(0x28);
- LCD_WR_DATA8(0x26);
- LCD_WR_DATA8(0x2E);
- LCD_WR_DATA8(0x3A);
- LCD_WR_DATA8(0x00);
- LCD_WR_DATA8(0x01);
- LCD_WR_DATA8(0x03);
- LCD_WR_DATA8(0x13);
- LCD_WR_REG(0xE1);
- LCD_WR_DATA8(0x04);
- LCD_WR_DATA8(0x16);
- LCD_WR_DATA8(0x06);
- LCD_WR_DATA8(0x0D);
- LCD_WR_DATA8(0x2D);
- LCD_WR_DATA8(0x26);
- LCD_WR_DATA8(0x23);
- LCD_WR_DATA8(0x27);
- LCD_WR_DATA8(0x27);
- LCD_WR_DATA8(0x25);
- LCD_WR_DATA8(0x2D);
- LCD_WR_DATA8(0x3B);
- LCD_WR_DATA8(0x00);
- LCD_WR_DATA8(0x01);
- LCD_WR_DATA8(0x04);
- LCD_WR_DATA8(0x13);
- LCD_WR_REG(0x3A); //65k mode
- LCD_WR_DATA8(0x05);
- LCD_WR_REG(0x29); //Display on
- }
复制代码- #include "pin_mux.h"
- #include "peripherals.h"
- #include "board.h"
- #include "pic.h"
- #include "lcd_init.h"
- typedef struct
- {
- unsigned char Index[2];
- unsigned char Msk[32];
- }typFNT_GB16;
- /*******************************************************************************
- * Prototypes
- ******************************************************************************/
- extern const typFNT_GB16 tfont16[];
- /*******************************************************************************
- * Variables
- ******************************************************************************/
- volatile uint32_t g_systickCounter;
- /*******************************************************************************
- * Code
- ******************************************************************************/
- void SysTick_Handler(void)
- {
- if (g_systickCounter != 0U)
- {
- g_systickCounter--;
- }
- }
- void SysTick_DelayTicks(uint32_t n)
- {
- g_systickCounter = n;
- while (g_systickCounter != 0U)
- {
- }
- }
- void Display_title(void)
- {
- LCD_Fill(0,0,LCD_W,LCD_H,LIGHTBLUE);
- LCD_ShowIntNum(8,10,2024,4,BLUE,GREEN,16);
- LCD_ShowChinese(40,10,&tfont16[0],BLUE,GREEN,16,0);
- LCD_ShowChinese(56,10,&tfont16[1],BLUE,GREEN,16,0);
- LCD_ShowChinese(72,10,&tfont16[2],BLUE,GREEN,16,0);
- LCD_ShowChinese(88,10,&tfont16[3],BLUE,GREEN,16,0);
- LCD_ShowChinese(104,10,&tfont16[4],BLUE,GREEN,16,0);
- LCD_ShowChinese(8,30,&tfont16[5],BLUE,GREEN,16,0);
- LCD_ShowChinese(24,30,&tfont16[6],BLUE,GREEN,16,0);
- LCD_ShowString(40,30,"MCX",BLUE,GREEN,16,0);
- LCD_ShowString(64,30," ",BLUE,GREEN,16,0);
- LCD_ShowString(72,30,"N",BLUE,GREEN,16,0);
- LCD_ShowString(80,30," ",BLUE,GREEN,16,0);
- LCD_ShowChinese(88,30,&tfont16[7],BLUE,GREEN,16,0);
- LCD_ShowChinese(104,30,&tfont16[8],BLUE,GREEN,16,0);
-
- LCD_ShowChinese(8,50,&tfont16[9],BLUE,GREEN,16,0);
- LCD_ShowChinese(24,50,&tfont16[10],BLUE,GREEN,16,0);
- LCD_ShowChinese(40,50,&tfont16[11],BLUE,GREEN,16,0);
- LCD_ShowChinese(56,50,&tfont16[12],BLUE,GREEN,16,0);
- LCD_ShowChinese(72,50,&tfont16[13],BLUE,GREEN,16,0);
- LCD_ShowChinese(88,50,&tfont16[5],BLUE,GREEN,16,0);
- LCD_ShowChinese(104,50,&tfont16[14],BLUE,GREEN,16,0);
- LCD_ShowChinese(8,70,&tfont16[15],BLUE,GREEN,16,0);
- LCD_ShowChinese(24,70,&tfont16[16],BLUE,GREEN,16,0);
- LCD_ShowString(44,140,"2024-12-20",BLUE,GREEN,16,0);
- SysTick_DelayTicks(500000);
- }
- /*!
- * @brief Main function
- */
- int main(void)
- {
- CLOCK_EnableClock(kCLOCK_Gpio0);
- CLOCK_EnableClock(kCLOCK_Gpio1);
- CLOCK_EnableClock(kCLOCK_Gpio4);
- BOARD_InitPins();
- LED_RED_INIT(LOGIC_LED_OFF);
- LED_BLUE_INIT(LOGIC_LED_OFF);
- LED_GREEN_INIT(LOGIC_LED_OFF);
-
- /* Set systick reload value to generate 1ms interrupt */
- if (SysTick_Config(SystemCoreClock / 1000000U))
- {
- while (1)
- {
- }
- }
-
- LCD_Init();
- SysTick_DelayTicks(200U);
- LCD_Fill(0,0,LCD_W,LCD_H,YELLOW);
- SysTick_DelayTicks(200);
- LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
- while (1)
- {
- LCD_ShowPicture(0,0,128,160,gImage_1);
- SysTick_DelayTicks(500000);
- Display_title();
- LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
- LCD_ShowPicture(0,0,91,160,gImage_2);
- SysTick_DelayTicks(500000);
- }
- }
复制代码 四、显示效果
画的bmp图使用Img2Lcd工具导出数组。圣诞节快到了,提前祝大伙圣诞节快乐!感谢在2024年里,与论坛的一路同行!
|
|