【FRDM-MCXN947】硬件SPI方式驱动LCD12864
[复制链接]
测试使用硬件方式驱动LCD12864。
在上篇帖子https://bbs.eeworld.com.cn/thread-1301831-1-1.html的基础上,将SPI方式有模拟方式改为硬件SPI方式
一、配置接口
显示屏只有写,没有读接口,用到了SPI的MOSI和SCK引脚。下图是配置为硬件SPI
配置FC6_FLEXCOMM时钟
SPI配置为12MHz
二、程序部分
spi初始化。
void lcd_init_spi(void)
{
uint32_t srcClock_Hz;
lpspi_master_config_t masterConfig;
lpspi_transfer_t masterXfer;
init_lcd_jlx12864g_pins();
/* attach FRO 12M to FLEXCOMM6 */
// CLOCK_SetClkDiv(kCLOCK_DivFlexcom6Clk, 1u);
// CLOCK_AttachClk(kFRO12M_to_FLEXCOMM6);
// /*Master config*/
LPSPI_MasterGetDefaultConfig(&masterConfig);
masterConfig.baudRate = TRANSFER_BAUDRATE;
masterConfig.whichPcs = EXAMPLE_LPSPI_MASTER_PCS_FOR_INIT;
masterConfig.pcsToSckDelayInNanoSec = 1000000000U / (masterConfig.baudRate * 2U);
masterConfig.lastSckToPcsDelayInNanoSec = 1000000000U / (masterConfig.baudRate * 2U);
masterConfig.betweenTransferDelayInNanoSec = 1000000000U / (masterConfig.baudRate * 2U);
srcClock_Hz = LPSPI_MASTER_CLK_FREQ;
LPSPI_MasterInit(EXAMPLE_LPSPI_MASTER_BASEADDR, &masterConfig, srcClock_Hz);
}
void fc6_spi_writebyte(uint8_t byte)
{
uint8_t srcBuff[2];
uint8_t destBuff[2];
srcBuff[0]=byte;
lpspi_transfer_t masterXfer;
/*Start master transfer*/
masterXfer.txData = srcBuff;
masterXfer.rxData = destBuff;
masterXfer.dataSize = 1;
masterXfer.configFlags = EXAMPLE_LPSPI_MASTER_PCS_FOR_TRANSFER | kLPSPI_MasterPcsContinuous | kLPSPI_MasterByteSwap;
LPSPI_MasterTransferBlocking(EXAMPLE_LPSPI_MASTER_BASEADDR, &masterXfer);
}
void lcd_jlx12864g_write_cmd(uint8_t cmd)
{
uint8_t i=0;
lcd_jlx12864g_cs_l();
lcd_jlx12864g_rs_l();
fc6_spi_writebyte(cmd);
}
void lcd_jlx12864g_write_dat(uint8_t dat)
{
uint8_t i=0;
lcd_jlx12864g_cs_l();
lcd_jlx12864g_rs_h();
fc6_spi_writebyte(dat);
}
main.c
#include "main.h"
int main(void)
{
uint8_t i;
CLOCK_EnableClock(kCLOCK_Gpio0);
BOARD_InitDEBUG_UARTPins();
BOARD_PowerMode_OD();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
init_utick();
SysTick_Init();
//init_p3t1755();
init_led();
init_key();
//p3t1755_test();
init_lcd_jlx12864g();
lcd_showString(0,0, (uint8_t*)"MCXN947_BOARD_TEST",6,12);
lcd_showString(0,13,(uint8_t*)"JLX12864G-SPI",6,12);
lcd_showString(0,26,(uint8_t*)"2024/12/14",6,12);
lcd_refreshGram();
while (1)
{
SysTick_Delay_ms(500);
led_red_tog();
//lcd_clear();
lcd_showString(0,39,(uint8_t*)"MCXN947_BOARD [OK]",6,12);
lcd_refreshGram();
SysTick_Delay_ms(500);
//lcd_clear();
lcd_showString(0,39,(uint8_t*)"TTTTTTTTTTTTT [OK]",6,12);
lcd_refreshGram();
}
}
三、运行结果
jlx128642
|