Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
NXP 微控制器
【NXP-MCXA153】TFT驱动移植
发布于 2024-07-23 22:32:29 浏览:239
订阅该版
[tocm] ## 介绍 GC9A01是一款1.28寸的圆形TFT显示屏模块,分辨率为240x240,支持三种颜色格式:RGB444、RGB565、RGB666,本次实验将在NXP-MCXA153开发板上移植TFT LCD驱动 ## 移植流程 ① 绑定TFT LCD上面的GPIO,如SCL_PIN、SDA_PIN、RES_PIN、DC_PIN、CS_PIN,实现GPIO初始化接口:LCD_GPIO_Init ② 根据LCD的读写时序编写bus数据传送接口、命令/数据发送接口等:LCD_Writ_Bus、LCD_WR_DATA、LCD_WR_REG ③ 时序TFT LCD的初始化接口:LCD_Init ④ 对绘图接口进行再一步封装:LCD_Fill、LCD_DrawPoint、Draw_Circle、LCD_ShowChinese、LCD_ShowPicture ## 引脚配置 GC9A01模块和开发板连接配置如下 | 引脚 | GPIO | 功能 | | :-----: | :---: | :------------: | | SCL_PIN | P1_1 | 时钟引脚 | | SDA_PIN | P1_0 | MOSI,数据引脚 | | RES_PIN | P3_30 | 复位引脚 | | DC_PIN | P3_1 | 数据命令引脚 | | CS_PIN | P1_3 | 片选引脚 | ## 驱动文件 ### lcd_init.h 定义LCD初始化相关的接口 ```c #ifndef __LCD_INIT_H #define __LCD_INIT_H #include "drv_pin.h" typedef unsigned short u16; typedef unsigned char u8; typedef unsigned int u32; #define USE_HORIZONTAL 0 #define USE_HARDWARE_SPI 0 #define LCD_W 240 #define LCD_H 240 #define SCL_PIN ((1*32)+1) #define SDA_PIN ((1*32)+0) #define RES_PIN ((3*32)+30) #define DC_PIN ((3*32)+1) #define CS_PIN ((1*32)+3) #define LCD_SCLK_Clr() rt_pin_write(SCL_PIN, PIN_LOW) #define LCD_SCLK_Set() rt_pin_write(SCL_PIN, PIN_HIGH) #define LCD_MOSI_Clr() rt_pin_write(SDA_PIN, PIN_LOW) #define LCD_MOSI_Set() rt_pin_write(SDA_PIN, PIN_HIGH) #define LCD_RES_Clr() rt_pin_write(RES_PIN, PIN_LOW) #define LCD_RES_Set() rt_pin_write(RES_PIN, PIN_HIGH) #define LCD_DC_Clr() rt_pin_write(DC_PIN, PIN_LOW) #define LCD_DC_Set() rt_pin_write(DC_PIN, PIN_HIGH) #define LCD_CS_Clr() rt_pin_write(CS_PIN, PIN_LOW) #define LCD_CS_Set() rt_pin_write(CS_PIN, PIN_HIGH) #define LCD_BLK_Clr() {} #define LCD_BLK_Set() {} void LCD_GPIO_Init(void); void LCD_Writ_Bus(u8 dat); void LCD_WR_DATA8(u8 dat); void LCD_WR_DATA(u16 dat); void LCD_WR_REG(u8 dat); void LCD_Address_Set(u16 x1,u16 y1,u16 x2,u16 y2); void LCD_Init(void); #endif ``` ### lcd_init.c LCD初始化相关的接口实现 ```c #include "lcd_init.h" #include
#include
#include
static struct rt_spi_device *spi_device; #define SPI_BUS_NAME "spi0" #define SPI_DEV_NAME "spi00" void LCD_GPIO_Init(void) { // init gpios rt_base_t cs = 1*32+3; rt_pin_mode(cs, PIN_MODE_OUTPUT); rt_pin_mode(DC_PIN, PIN_MODE_OUTPUT); rt_pin_mode(RES_PIN, PIN_MODE_OUTPUT); rt_pin_mode(SDA_PIN, PIN_MODE_OUTPUT); rt_pin_mode(SCL_PIN, PIN_MODE_OUTPUT); #if USE_HARDWARE_SPI rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_DEV_NAME, cs); struct rt_spi_configuration cfg; spi_device = (struct rt_spi_device *)rt_device_find(SPI_DEV_NAME); if (!spi_device) { rt_kprintf("can't find %s device!\n", SPI_BUS_NAME); } cfg.data_width = 8; cfg.mode = RT_SPI_MASTER | RT_SPI_MODE_0 | RT_SPI_MSB; cfg.max_hz = 12* 1000 * 1000; /* 500K */ rt_spi_configure(spi_device, &cfg); #endif } void LCD_Writ_Bus(u8 dat) { #if 0 rt_uint8_t recv_buf[1]; rt_spi_transfer(spi_device, &dat, recv_buf, 1); #else u8 i; LCD_CS_Clr(); for(i=0;i<8;i++) { LCD_SCLK_Clr(); if(dat&0x80) { LCD_MOSI_Set(); } else { LCD_MOSI_Clr(); } LCD_SCLK_Set(); dat<<=1; } LCD_CS_Set(); #endif } void LCD_WR_DATA8(u8 dat) { LCD_Writ_Bus(dat); } void LCD_WR_DATA(u16 dat) { LCD_Writ_Bus(dat>>8); LCD_Writ_Bus(dat); } void LCD_WR_REG(u8 dat) { LCD_DC_Clr(); LCD_Writ_Bus(dat); LCD_DC_Set(); } void LCD_Address_Set(u16 x1,u16 y1,u16 x2,u16 y2) { LCD_WR_REG(0x2a); LCD_WR_DATA(x1); LCD_WR_DATA(x2); LCD_WR_REG(0x2b); LCD_WR_DATA(y1); LCD_WR_DATA(y2); LCD_WR_REG(0x2c); } void LCD_Init(void) { LCD_GPIO_Init(); LCD_RES_Clr(); rt_thread_mdelay(100); LCD_RES_Set(); rt_thread_mdelay(100); LCD_BLK_Set(); rt_thread_mdelay(100); LCD_WR_REG(0xEF); LCD_WR_REG(0xEB); LCD_WR_DATA8(0x14); LCD_WR_REG(0xFE); LCD_WR_REG(0xEF); LCD_WR_REG(0xEB); LCD_WR_DATA8(0x14); LCD_WR_REG(0x84); LCD_WR_DATA8(0x40); LCD_WR_REG(0x85); LCD_WR_DATA8(0xFF); LCD_WR_REG(0x86); LCD_WR_DATA8(0xFF); LCD_WR_REG(0x87); LCD_WR_DATA8(0xFF); LCD_WR_REG(0x88); LCD_WR_DATA8(0x0A); LCD_WR_REG(0x89); LCD_WR_DATA8(0x21); LCD_WR_REG(0x8A); LCD_WR_DATA8(0x00); LCD_WR_REG(0x8B); LCD_WR_DATA8(0x80); LCD_WR_REG(0x8C); LCD_WR_DATA8(0x01); LCD_WR_REG(0x8D); LCD_WR_DATA8(0x01); LCD_WR_REG(0x8E); LCD_WR_DATA8(0xFF); LCD_WR_REG(0x8F); LCD_WR_DATA8(0xFF); LCD_WR_REG(0xB6); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x20); LCD_WR_REG(0x36); if(USE_HORIZONTAL==0)LCD_WR_DATA8(0x08); else if(USE_HORIZONTAL==1)LCD_WR_DATA8(0xC8); else if(USE_HORIZONTAL==2)LCD_WR_DATA8(0x68); else LCD_WR_DATA8(0xA8); LCD_WR_REG(0x3A); LCD_WR_DATA8(0x05); LCD_WR_REG(0x90); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x08); LCD_WR_REG(0xBD); LCD_WR_DATA8(0x06); LCD_WR_REG(0xBC); LCD_WR_DATA8(0x00); LCD_WR_REG(0xFF); LCD_WR_DATA8(0x60); LCD_WR_DATA8(0x01); LCD_WR_DATA8(0x04); LCD_WR_REG(0xC3); LCD_WR_DATA8(0x13); LCD_WR_REG(0xC4); LCD_WR_DATA8(0x13); LCD_WR_REG(0xC9); LCD_WR_DATA8(0x22); LCD_WR_REG(0xBE); LCD_WR_DATA8(0x11); LCD_WR_REG(0xE1); LCD_WR_DATA8(0x10); LCD_WR_DATA8(0x0E); LCD_WR_REG(0xDF); LCD_WR_DATA8(0x21); LCD_WR_DATA8(0x0c); LCD_WR_DATA8(0x02); LCD_WR_REG(0xF0); LCD_WR_DATA8(0x45); LCD_WR_DATA8(0x09); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x26); LCD_WR_DATA8(0x2A); LCD_WR_REG(0xF1); LCD_WR_DATA8(0x43); LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x72); LCD_WR_DATA8(0x36); LCD_WR_DATA8(0x37); LCD_WR_DATA8(0x6F); LCD_WR_REG(0xF2); LCD_WR_DATA8(0x45); LCD_WR_DATA8(0x09); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x26); LCD_WR_DATA8(0x2A); LCD_WR_REG(0xF3); LCD_WR_DATA8(0x43); LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x72); LCD_WR_DATA8(0x36); LCD_WR_DATA8(0x37); LCD_WR_DATA8(0x6F); LCD_WR_REG(0xED); LCD_WR_DATA8(0x1B); LCD_WR_DATA8(0x0B); LCD_WR_REG(0xAE); LCD_WR_DATA8(0x77); LCD_WR_REG(0xCD); LCD_WR_DATA8(0x63); LCD_WR_REG(0x70); LCD_WR_DATA8(0x07); LCD_WR_DATA8(0x07); LCD_WR_DATA8(0x04); LCD_WR_DATA8(0x0E); LCD_WR_DATA8(0x0F); LCD_WR_DATA8(0x09); LCD_WR_DATA8(0x07); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x03); LCD_WR_REG(0xE8); LCD_WR_DATA8(0x34); LCD_WR_REG(0x62); LCD_WR_DATA8(0x18); LCD_WR_DATA8(0x0D); LCD_WR_DATA8(0x71); LCD_WR_DATA8(0xED); LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x18); LCD_WR_DATA8(0x0F); LCD_WR_DATA8(0x71); LCD_WR_DATA8(0xEF); LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x70); LCD_WR_REG(0x63); LCD_WR_DATA8(0x18); LCD_WR_DATA8(0x11); LCD_WR_DATA8(0x71); LCD_WR_DATA8(0xF1); LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x18); LCD_WR_DATA8(0x13); LCD_WR_DATA8(0x71); LCD_WR_DATA8(0xF3); LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x70); LCD_WR_REG(0x64); LCD_WR_DATA8(0x28); LCD_WR_DATA8(0x29); LCD_WR_DATA8(0xF1); LCD_WR_DATA8(0x01); LCD_WR_DATA8(0xF1); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x07); LCD_WR_REG(0x66); LCD_WR_DATA8(0x3C); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0xCD); LCD_WR_DATA8(0x67); LCD_WR_DATA8(0x45); LCD_WR_DATA8(0x45); LCD_WR_DATA8(0x10); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x00); LCD_WR_REG(0x67); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x3C); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x01); LCD_WR_DATA8(0x54); LCD_WR_DATA8(0x10); LCD_WR_DATA8(0x32); LCD_WR_DATA8(0x98); LCD_WR_REG(0x74); LCD_WR_DATA8(0x10); LCD_WR_DATA8(0x85); LCD_WR_DATA8(0x80); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x4E); LCD_WR_DATA8(0x00); LCD_WR_REG(0x98); LCD_WR_DATA8(0x3e); LCD_WR_DATA8(0x07); LCD_WR_REG(0x35); LCD_WR_REG(0x21); LCD_WR_REG(0x11); rt_thread_mdelay(120); LCD_WR_REG(0x29); rt_thread_mdelay(20); } ``` ### lcd.h 绘图接口声明 ```c #ifndef __LCD_H #define __LCD_H typedef unsigned short u16; typedef unsigned char u8; typedef unsigned int u32; void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color); void LCD_DrawPoint(u16 x,u16 y,u16 color); void LCD_DrawLine(u16 x1,u16 y1,u16 x2,u16 y2,u16 color); void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2,u16 color); void Draw_Circle(u16 x0,u16 y0,u8 r,u16 color); void LCD_ShowChinese(u16 x,u16 y,u8 *s,u16 fc,u16 bc,u8 sizey,u8 mode); void LCD_ShowChinese12x12(u16 x,u16 y,u8 *s,u16 fc,u16 bc,u8 sizey,u8 mode); void LCD_ShowChinese16x16(u16 x,u16 y,u8 *s,u16 fc,u16 bc,u8 sizey,u8 mode); void LCD_ShowChinese24x24(u16 x,u16 y,u8 *s,u16 fc,u16 bc,u8 sizey,u8 mode); void LCD_ShowChinese32x32(u16 x,u16 y,u8 *s,u16 fc,u16 bc,u8 sizey,u8 mode); void LCD_ShowChar(u16 x,u16 y,u8 num,u16 fc,u16 bc,u8 sizey,u8 mode); void LCD_ShowString(u16 x,u16 y,const u8 *p,u16 fc,u16 bc,u8 sizey,u8 mode); u32 mypow(u8 m,u8 n); void LCD_ShowIntNum(u16 x,u16 y,u16 num,u8 len,u16 fc,u16 bc,u8 sizey); void LCD_ShowFloatNum1(u16 x,u16 y,float num,u8 len,u16 fc,u16 bc,u8 sizey); void LCD_ShowPicture(u16 x,u16 y,u16 length,u16 width,const u8 pic[]); #define WHITE 0xFFFF #define BLACK 0x0000 #define BLUE 0x001F #define BRED 0XF81F #define GRED 0XFFE0 #define GBLUE 0X07FF #define RED 0xF800 #define MAGENTA 0xF81F #define GREEN 0x07E0 #define CYAN 0x7FFF #define YELLOW 0xFFE0 #define BROWN 0XBC40 #define BRRED 0XFC07 #define GRAY 0X8430 #define DARKBLUE 0X01CF #define LIGHTBLUE 0X7D7C #define GRAYBLUE 0X5458 #define LIGHTGREEN 0X841F #define LGRAY 0XC618 #define LGRAYBLUE 0XA651 #define LBBLUE 0X2B12 #endif ``` ### lcd.c 绘图接口实现 ```c #include "lcd.h" #include "lcd_init.h" #include "lcdfont.h" void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color) { u16 i,j; LCD_Address_Set(xsta,ysta,xend-1,yend-1); for(i=ysta;i
0)incx=1; else if (delta_x==0)incx=0; else {incx=-1;delta_x=-delta_x;} if(delta_y>0)incy=1; else if (delta_y==0)incy=0; else {incy=-1;delta_y=-delta_y;} if(delta_x>delta_y)distance=delta_x; else distance=delta_y; for(t=0;t
distance) { xerr-=distance; uRow+=incx; } if(yerr>distance) { yerr-=distance; uCol+=incy; } } } void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2,u16 color) { LCD_DrawLine(x1,y1,x2,y1,color); LCD_DrawLine(x1,y1,x1,y2,color); LCD_DrawLine(x1,y2,x2,y2,color); LCD_DrawLine(x2,y1,x2,y2,color); } void Draw_Circle(u16 x0,u16 y0,u8 r,u16 color) { int a,b; a=0;b=r; while(a<=b) { LCD_DrawPoint(x0-b,y0-a,color); //3 LCD_DrawPoint(x0+b,y0-a,color); //0 LCD_DrawPoint(x0-a,y0+b,color); //1 LCD_DrawPoint(x0-a,y0-b,color); //2 LCD_DrawPoint(x0+b,y0+a,color); //4 LCD_DrawPoint(x0+a,y0-b,color); //5 LCD_DrawPoint(x0+a,y0+b,color); //6 LCD_DrawPoint(x0-b,y0+a,color); //7 a++; if((a*a+b*b)>(r*r)) { b--; } } } void LCD_ShowChinese(u16 x,u16 y,u8 *s,u16 fc,u16 bc,u8 sizey,u8 mode) { while(*s!=0) { if(sizey==12) LCD_ShowChinese12x12(x,y,s,fc,bc,sizey,mode); else if(sizey==16) LCD_ShowChinese16x16(x,y,s,fc,bc,sizey,mode); else if(sizey==24) LCD_ShowChinese24x24(x,y,s,fc,bc,sizey,mode); else if(sizey==32) LCD_ShowChinese32x32(x,y,s,fc,bc,sizey,mode); else return; s+=2; x+=sizey; } } void LCD_ShowChinese12x12(u16 x,u16 y,u8 *s,u16 fc,u16 bc,u8 sizey,u8 mode) { u8 i,j,m=0; u16 k; u16 HZnum; u16 TypefaceNum; u16 x0=x; TypefaceNum=(sizey/8+((sizey%8)?1:0))*sizey; HZnum=sizeof(tfont12)/sizeof(typFNT_GB12); for(k=0;k
#include
#include "stdlib.h" #include "lcd.h" #include "lcd_init.h" #include "pic.h" int main(void) { int j = 0; LCD_Init(); LCD_Fill(0, 0, 240, 240, BLACK); while(1) { for(int i = 0; i < 240; i += 10) { Draw_Circle(120, 120, i, 400 * j); } if(j++ > 65536 / 400) { j = 0; } rt_thread_mdelay(1); } return 0; } ``` 实验效果 ![tft-lcd.png](https://oss-club.rt-thread.org/uploads/20240819/dfbb2a9675586858cc68fbeb6b105d0c.png.webp) ## 参考 [GC9A01 1.28寸圆形TFT: GC9A01 1.28寸圆形TFT (gitee.com)](https://gitee.com/meta-mcu/gc9a01-tft)
0
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
hywing
嵌入式系统开发工程师,从事物联网、工业自动化、汽车电子开发工作
文章
6
回答
3
被采纳
0
关注TA
发私信
相关文章
1
试贴-消灭0主题
2
LPC M4的一些资料
3
LPC4088的临时分支
4
lpc1788 ad 不稳定
5
1788 LCD控制器缓冲区字节问题
6
一起来学习LPC4088吧
7
上传LPC4088的realtouch主工程
8
RealBoard 4088预定帖 [第一批板子不多,预定提前结束]
9
晒RealBoard LPC4088开箱照啦,速带小板凳前来围观
10
4088主程序需要的SD卡资源
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
WIZnet_W5500
UART
ota在线升级
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
keil_MDK
rt_mq_消息队列_msg_queue
ulog
C++_cpp
at_device
本月问答贡献
踩姑娘的小蘑菇
7
个答案
3
次被采纳
a1012112796
13
个答案
2
次被采纳
张世争
9
个答案
2
次被采纳
rv666
5
个答案
2
次被采纳
用户名由3_15位
11
个答案
1
次被采纳
本月文章贡献
程序员阿伟
8
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
大龄码农
1
篇文章
5
次点赞
ThinkCode
1
篇文章
1
次点赞
Betrayer
1
篇文章
1
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部