为了能更加充分的显示图像信息,为MCXN947开发板配置了一款2.4’的TFT显示屏,其分辨率为320*240像素点。
为了减少连线的烦恼,便使用开发板所配置的Arduino接口来连接这款显示屏,该接口的引脚连接关系如图1所示。
图1 使用接口引脚
为以I/O能模拟SPI接口,所做的引脚输出高低电平定义语句为:
#define LCD_CS_High() GPIO_PortSet(GPIO0, 1U << 25U)
#define LCD_CS_Low() GPIO_PortClear(GPIO0, 1U << 25U)
#define LCD_REST_High() GPIO_PortSet(GPIO0, 1U << 26U)
#define LCD_REST_Low() GPIO_PortClear(GPIO0, 1U << 26U)
#define LCD_DC_High() GPIO_PortSet(GPIO0, 1U << 24U)
#define LCD_DC_Low() GPIO_PortClear(GPIO0, 1U << 24U)
#define LCD_SDI_High() GPIO_PortSet(GPIO0, 1U << 27U)
#define LCD_SDI_Low() GPIO_PortClear(GPIO0, 1U << 27U)
#define LCD_SCK_High() GPIO_PortSet(GPIO0, 1U << 10U)
#define LCD_SCK_Low() GPIO_PortClear(GPIO0, 1U << 10U)
#define LCD_LED_High() GPIO_PortSet(GPIO0, 1U << 28U)
对该显示屏的初始化函数为:
void tft_Init(void)
{ // ili9220B
LCD_REST_Low();
delay1();
LCD_REST_High();
delay1();
LCD_CS_Low();
LCD_WR_REG(0xCB);
LCD_WR_DATA8(0x39);
LCD_WR_DATA8(0x2C);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x34);
LCD_WR_DATA8(0x02);
LCD_WR_REG(0xCF);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0XC1);
LCD_WR_DATA8(0X30);
LCD_WR_REG(0xE8);
LCD_WR_DATA8(0x85);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x78);
LCD_WR_REG(0xEA);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x00);
LCD_WR_REG(0xED);
LCD_WR_DATA8(0x64);
LCD_WR_DATA8(0x03);
LCD_WR_DATA8(0X12);
LCD_WR_DATA8(0X81);
LCD_WR_REG(0xF7);
LCD_WR_DATA8(0x20);
LCD_WR_REG(0xC0);
LCD_WR_DATA8(0x23);
LCD_WR_REG(0xC1);
LCD_WR_DATA8(0x10);
LCD_WR_REG(0xC5);
LCD_WR_DATA8(0x3e);
LCD_WR_DATA8(0x28);
LCD_WR_REG(0xC7);
LCD_WR_DATA8(0x86);
LCD_WR_REG(0x36);
LCD_WR_DATA8(0x48);
LCD_WR_REG(0x3A);
LCD_WR_DATA8(0x55);
LCD_WR_REG(0xB1);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x18);
LCD_WR_REG(0xB6);
LCD_WR_DATA8(0x08);
LCD_WR_DATA8(0x82);
LCD_WR_DATA8(0x27);
LCD_WR_REG(0xF2);
LCD_WR_DATA8(0x00);
LCD_WR_REG(0x26);
LCD_WR_DATA8(0x01);
LCD_WR_REG(0xE0);
LCD_WR_DATA8(0x0F);
LCD_WR_DATA8(0x31);
LCD_WR_DATA8(0x2B);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x08);
LCD_WR_DATA8(0x4E);
LCD_WR_DATA8(0xF1);
LCD_WR_DATA8(0x37);
LCD_WR_DATA8(0x07);
LCD_WR_DATA8(0x10);
LCD_WR_DATA8(0x03);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x09);
LCD_WR_DATA8(0x00);
LCD_WR_REG(0XE1);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x14);
LCD_WR_DATA8(0x03);
LCD_WR_DATA8(0x11);
LCD_WR_DATA8(0x07);
LCD_WR_DATA8(0x31);
LCD_WR_DATA8(0xC1);
LCD_WR_DATA8(0x48);
LCD_WR_DATA8(0x08);
LCD_WR_DATA8(0x0F);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x31);
LCD_WR_DATA8(0x36);
LCD_WR_DATA8(0x0F);
LCD_WR_REG(0x11);
delay1();
LCD_WR_REG(0x29);
LCD_WR_REG(0x2c);
LCD_LED_High();
}
模拟SPI方式发送字节数据的函数为:
void LCD_Writ_Bus(unsigned char com)
{
unsigned char uci;
for(uci=0;uci<8;uci++)
{
if(com & 0x80)
{
LCD_SDI_High();
}
else
{
LCD_SDI_Low();
}
com = com << 1;
delay2();
LCD_SCK_Low();
LCD_SCK_High();
}
}
实现指定色彩清除屏幕的函数为:
void LCD_Clear(unsigned int Color)
{
char VH,VL;
unsigned int i,j;
VH=Color>>8;
VL=Color;
Address_set(0,0,LCD_W-1,LCD_H-1);
for(i=0;i<LCD_W;i++)
{
for (j=0;j<LCD_H;j++)
{
LCD_WR_DATA8(VH);
LCD_WR_DATA8(VL);
}
}
}
为便于字符串信息的显示,所配置的对应函数为:
void LCD_ShowString(unsigned int x,unsigned int y,const char *p)
{
while(*p!='\0')
{
if(x>LCD_W-16){x=0;y+=16;}
if(y>LCD_H-16){y=x=0;}
LCD_ShowChar(x,y,*p,0);
x+=8;
p++;
}
}
实现显示屏驱动性能测试的主程序为:
int main(void)
{
gpio_pin_config_t led_config = {
kGPIO_DigitalOutput,
0,
};
CLOCK_SetClkDiv(kCLOCK_DivFlexcom4Clk, 1u);
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
CLOCK_EnableClock(kCLOCK_Gpio0);
CLOCK_EnableClock(kCLOCK_Gpio1);
BOARD_InitPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
GPIO_PinInit(GPIO1, 2U, &led_config);
GPIO_PinInit(GPIO0, 25U, &led_config);
GPIO_PinInit(GPIO0, 26U, &led_config);
GPIO_PinInit(GPIO0, 24U, &led_config);
GPIO_PinInit(GPIO0, 27U, &led_config);
GPIO_PinInit(GPIO0, 10U, &led_config);
GPIO_PinInit(GPIO0, 28U, &led_config);
tft_Init();
delay2();
LCD_Clear(BLACK);
LCD_Clear(RED);
BACK_COLOR=RED;
POINT_COLOR=YELLOW;
LCD_ShowString(20,16,"MCXN947");
LCD_DrawLine(0, 40, 239,40);
POINT_COLOR=GREEN;
LCD_ShowNum(180,16,123,3);
GPIO_PortSet(GPIO0, 1U << 27U);
GPIO_PortSet(GPIO0, 1U << 10U);
while (1)
{
delay();
GPIO_PortToggle(GPIO1, 1u << 2U);
}
}
经程序的便于和下载,其测试效果如图2所示,说明驱动成功能服务于显示任务的需要。
图2 连接及测试效果
|