书接上回:
【Curiosity Nano测评报告】PIC16F13145点灯之旅 - Microchip论坛 - PIC单片机论坛 - Microchip(微芯科技)MCU官方技术支持论坛 - 21ic电子技术开**坛
https://bbs.21ic.com/icview-3400974-1-1.html
点灯之旅之后,还不过瘾,咱们接着开启点屏之行,也就是PIC16F13145驱动TFT LCD屏幕。
这款屏幕采用的是ILI9320主控,SPI接口。
TFT模块与[size=1em]Curiosity Nano开发板的接线方式如图:
//CS RC0
//RST RC1
//RS RC2
//SDA RC3
//CLK RA4
硬件准备完毕,接下来就是软件编写环节。
本例采用IO口模拟SPI协议,这样具备快速移植的优点,当然速度不及硬件SPI。
首先在MCC界面中分别设置RC0、RC1、RC2、RC3、RC4、RA4为输出(OUTPUT)
然后确认下每个IO的设置状态,以及Custom name(默认)
左侧的Device resources 添加DELAY函数,在TFT的驱动中需要用到毫秒延时函数。
接下来就是程序编写。
main.c比较简单,对TFT进行初始化,以及刷屏。
- #include "mcc_generated_files/system/system.h"
- #include"mcc_generated_files/timer/delay.h"
- #include "TFT.h"
- //*****************************************************************************
- //CS RC0
- //RST RC1
- //RS RC2
- //SDA RC3
- //CLK RA4
- //*****************************************************************************
- #define white 0xFFFF //LCD color
- #define black 0x0000
- #define blue 0x001F
- #define blue2 0x051F
- #define red 0xF800
- #define magenta 0xF81F
- #define green 0x07E0
- #define cyan 0x7FFF
- #define yellow 0xFFE0
- int main(void)
- {
- SYSTEM_Initialize();
- Lcd_Init(); //初始化LCD
- DELAY_microseconds(1) ; //延时一段时间
- Lcd_Clear(black );
- while(1)
- {
- Show_RGB(0,0,176,44,blue);
- Show_RGB(0,44,176,88,green);
- Show_RGB(0,88,176,132,magenta);
- Show_RGB(0,132,176,176,red);
- Show_RGB(0,176,176,220,yellow);
- Show_RGB(0,0,176,44,yellow);
- Show_RGB(0,44,176,88,red);
- Show_RGB(0,88,176,132,blue2);
- Show_RGB(0,132,176,176,green);
- Show_RGB(0,176,176,220,blue);
- }
- }
最主要的驱动在TFT.c中
关键部分展示如下:
- #include "TFT.h"
- #include "mcc_generated_files/system/system.h"
- #include"mcc_generated_files/timer/delay.h"
- //*****************************************************************************
- //CS RC0
- //RST RC1
- //RS RC2
- //SDA RC3
- //CLK RA4
- //*****************************************************************************
- #define CS_1 IO_RC0_SetHigh();
- #define CS_0 IO_RC0_SetLow();
- #define RST_1 IO_RC1_SetHigh();
- #define RST_0 IO_RC1_SetLow();
- #define RS_1 IO_RC2_SetHigh();
- #define RS_0 IO_RC2_SetLow();
- #define SDA_1 IO_RC3_SetHigh();
- #define SDA_0 IO_RC3_SetLow();
- #define CLK_1 IO_RA4_SetHigh();
- #define CLK_0 IO_RA4_SetLow();
- //软件模拟SPI协议的关键函数
最后的显示结果如图。
源程序及展示视频上传:
|