目录
一、功能实现
实现1.8寸TFT_LCD真彩屏显示。显示数字、图片、字符串等。
二、设备准备
1.TFT_LCD真彩屏(1.8寸)
该真彩屏使用SPI通信。
2.MSP430F149开发板
三、接线表设计
MSP430F149 | TFT_LCD真彩屏 |
P5.0 | SCL |
P5.1 | SDA |
P5.2 | RES |
P5.3 | DC |
P5.4 | CS |
P5.5 | BL |
VCC | 5V |
GND | GND |
因为液晶显示,只需要将所有引脚设置成输出模式即可。
四、代码实现
1.TFT_LCD IO口初始化
//TFT LCD 液晶IO初始化配置
//P5.0 SCL
//P5.1 SDA
//P5.2 RES
//P5.3 DC
//P5.4 CS
//P5.5 BL
void LCD_GPIO_Init(void)
{
P5SEL = 0x00;
P5DIR|= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5;
}
2.TFT_LCD功能初始化
//LCD Init For 1.44Inch LCD Panel with ST7735R.
void Lcd_Init(void)
{
LCD_GPIO_Init();
Lcd_Reset(); //Reset before LCD Init.
//LCD Init For 1.44Inch LCD Panel with ST7735R.
Lcd_WriteIndex(0x11);//Sleep exit
delay_ms (120);
//ST7735R Frame Rate
Lcd_WriteIndex(0xB1);
Lcd_WriteData(0x01);
Lcd_WriteData(0x2C);
Lcd_WriteData(0x2D);
Lcd_WriteIndex(0xB2);
Lcd_WriteData(0x01);
Lcd_WriteData(0x2C);
Lcd_WriteData(0x2D);
Lcd_WriteIndex(0xB3);
Lcd_WriteData(0x01);
Lcd_WriteData(0x2C);
Lcd_WriteData(0x2D);
Lcd_WriteData(0x01);
Lcd_WriteData(0x2C);
Lcd_WriteData(0x2D);
Lcd_WriteIndex(0xB4); //Column inversion
Lcd_WriteData(0x07);
//ST7735R Power Sequence
Lcd_WriteIndex(0xC0);
Lcd_WriteData(0xA2);
Lcd_WriteData(0x02);
Lcd_WriteData(0x84);
Lcd_WriteIndex(0xC1);
Lcd_WriteData(0xC5);
Lcd_WriteIndex(0xC2);
Lcd_WriteData(0x0A);
Lcd_WriteData(0x00);
Lcd_WriteIndex(0xC3);
Lcd_WriteData(0x8A);
Lcd_WriteData(0x2A);
Lcd_WriteIndex(0xC4);
Lcd_WriteData(0x8A);
Lcd_WriteData(0xEE);
Lcd_WriteIndex(0xC5); //VCOM
Lcd_WriteData(0x0E);
Lcd_WriteIndex(0x36); //MX, MY, RGB mode
Lcd_WriteData(0xC0);
//ST7735R Gamma Sequence
Lcd_WriteIndex(0xe0);
Lcd_WriteData(0x0f);
Lcd_WriteData(0x1a);
Lcd_WriteData(0x0f);
Lcd_WriteData(0x18);
Lcd_WriteData(0x2f);
Lcd_WriteData(0x28);
Lcd_WriteData(0x20);
Lcd_WriteData(0x22);
Lcd_WriteData(0x1f);
Lcd_WriteData(0x1b);
Lcd_WriteData(0x23);
Lcd_WriteData(0x37);
Lcd_WriteData(0x00);
Lcd_WriteData(0x07);
Lcd_WriteData(0x02);
Lcd_WriteData(0x10);
Lcd_WriteIndex(0xe1);
Lcd_WriteData(0x0f);
Lcd_WriteData(0x1b);
Lcd_WriteData(0x0f);
Lcd_WriteData(0x17);
Lcd_WriteData(0x33);
Lcd_WriteData(0x2c);
Lcd_WriteData(0x29);
Lcd_WriteData(0x2e);
Lcd_WriteData(0x30);
Lcd_WriteData(0x30);
Lcd_WriteData(0x39);
Lcd_WriteData(0x3f);
Lcd_WriteData(0x00);
Lcd_WriteData(0x07);
Lcd_WriteData(0x03);
Lcd_WriteData(0x10);
Lcd_WriteIndex(0x2a);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x7f);
Lcd_WriteIndex(0x2b);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x9f);
Lcd_WriteIndex(0xF0); //Enable test command
Lcd_WriteData(0x01);
Lcd_WriteIndex(0xF6); //Disable ram power save mode
Lcd_WriteData(0x00);
Lcd_WriteIndex(0x3A); //65k mode
Lcd_WriteData(0x05);
Lcd_WriteIndex(0x29);//Display on
}
和51、AVR、STM32中的代码基本无异。
3.主函数(main.c)
#include <msp430x14x.h>
#include "Config.h"
#include "Lcd_Driver.h"
#include "QDTFT_demo.h"
#define LCD_BL_CLR P5OUT &= ~BIT5 //BL置低
#define LCD_BL_SET P5OUT |= BIT5 //BL置高
//***********************************************************************
// 主程序
//***********************************************************************
void main(void)
{
WDT_Init();
Clock_Init(); //时钟初始化
Lcd_Init();
LCD_BL_SET;//通过IO控制背光亮
while(1)
{
QDTFT_Test_Demo();
}
}
涉及文件较多,只贴出部分核心代码,其他代码基本没有修改(主要修改一些变量的类型,如u8修改成unsigned char,因为该处理器不识别),直接移植。