//LCD Init For 1.44Inch LCD Panel with ST7735.
void Lcd_Init(void)
{
LCD_GPIO_Init();
Lcd_Reset(); //Reset before LCD Init.
//LCD Init For 1.44Inch LCD Panel with ST7735.
Lcd_WriteCmd(0x11);//Sleep exit
delay_ms (120);
/*1.若你为了快速完成工作需求,只需要理解功能即可
直接复制粘贴下面代码,会移植就0K.
2.若你有大把的空闲时间(学生),建议还是学会翻阅Datasheet
弄清原理,打好基础,深入了解液晶屏的底层驱动
3.精通一种型号屏的底层驱动,万变不离其中,其他屏也信手拈来*/
//ST7735R Frame Rate
Lcd_WriteCmd(0xB1);
Lcd_WriteData(0x01);
Lcd_WriteData(0x2C);
Lcd_WriteData(0x2D);
Lcd_WriteCmd(0xB2);
Lcd_WriteData(0x01);
Lcd_WriteData(0x2C);
Lcd_WriteData(0x2D);
Lcd_WriteCmd(0xB3);
Lcd_WriteData(0x01);
Lcd_WriteData(0x2C);
Lcd_WriteData(0x2D);
Lcd_WriteData(0x01);
Lcd_WriteData(0x2C);
Lcd_WriteData(0x2D);
Lcd_WriteCmd(0xB4); //Column inversion
Lcd_WriteData(0x07);
//ST7735R Power Sequence
Lcd_WriteCmd(0xC0);
Lcd_WriteData(0xA2);
Lcd_WriteData(0x02);
Lcd_WriteData(0x84);
Lcd_WriteCmd(0xC1);
Lcd_WriteData(0xC5);
Lcd_WriteCmd(0xC2);
Lcd_WriteData(0x0A);
Lcd_WriteData(0x00);
Lcd_WriteCmd(0xC3);
Lcd_WriteData(0x8A);
Lcd_WriteData(0x2A);
Lcd_WriteCmd(0xC4);
Lcd_WriteData(0x8A);
Lcd_WriteData(0xEE);
Lcd_WriteCmd(0xC5); //VCOM
Lcd_WriteData(0x0E);
Lcd_WriteCmd(0x36); //MX, MY, RGB mode
Lcd_WriteData(0xC0);
//ST7735R Gamma Sequence
Lcd_WriteCmd(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_WriteCmd(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_WriteCmd(0x2a);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x7f);
Lcd_WriteCmd(0x2b);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x9f);
Lcd_WriteCmd(0xF0); //Enable test command
Lcd_WriteData(0x01);
Lcd_WriteCmd(0xF6); //Disable ram power save mode
Lcd_WriteData(0x00);
Lcd_WriteCmd(0x3A); //65k mode
Lcd_WriteData(0x05);
Lcd_WriteCmd(0x29);//Display on
}
ST7735S------>Datasheet链接:https://pan.baidu.com/s/1tBDSJ4NsbFSTCXCxqnkzAg 提取码:uapn
建议先看看:苦练基本功《如何阅读看懂一篇Datasheet》
1.查阅Datasheet的96页COMMAND的篇章
Datasheet96页,在Instruction一栏中,看到SWRESET(Software Reset简写),再看D/CX一栏写为0,即低电平,即表示命令(而D/CX高电平表示数据),及其后面所对应的功能Software Reset,直译为“软件复位”,实际也就是“屏幕重置”的功能。数据传送有8位D7-D0,十六进制表示(Hex)为0x01。
1.很多Datasheet中(甚至计算机领域)很多命名都遵守见名知意的约定,让人一下就能猜出它的意思,可读性极高。
2.D/CX---->D表示Data数据的意思,C表示Command命令的意思
3.还有我们常说的片选信号CS------>Chip Select
4.R/W计算机术语---->读和写操作
5.还有专业Datasheet的,会在芯片引脚图(就以D/C为例)C的头上加上一撇,表示低电平有效,这让阅读Datasheet的工程师快速在图中获取信息,必要时才去看文字介绍 。正所谓–>先看目录,后看内容,先看图,后看文字
现在我写个命令
void Lcd_WriteCmd(u8 Cmd)
Lcd_WriteCmd(0x01);//表示屏幕重置
现在我们完成一个挑战,如何去读TFT屏幕的ID
OK,看到RDDID,功能介绍为Read Display ID,看到D/Cx为0,知道是–>写命令,按照D7-D0的顺序HEX为0x04.
Lcd_WriteCmd(0x04);//表示Read Display ID 读取ID
方法交给你们了,就自行探索了,不要怕英文,Datasheet专业术语都是固定的,Voltage总是万年的电压,Current总是万年的电流。Current当时我在Datasheet中认为是形容词------>”当前的“ , 被我大学老师笑话了一顿,每次看到这个单词,脑海中总是浮现那个情景,哈哈!
2.程序实战软件模拟SPI
//SCL--->主机的时钟信号
void SPI_WriteData(u8 Data)
{
unsigned char i=0;
for(i=8;i>0;i--)
{
if(Data&0x80)
LCD_SDA_HIGH;
else
LCD_SDA_LOW;
LCD_SCL_LOW;
LCD_SCL_HIGH; //表示SCL时钟信号处于上升沿,开始一位数据传送
Data<<=1;
}
}
/*在上面SPI_WriteData()函数基础上再进行封装,在CS片选信号拉低的情况下,
操作D/C----->(96页Datasheet中,高电平表示数据,低电平表示命令)
分别封装成写命令Lcd_WriteCmd(Cmd)函数和写数据Lcd_WriteData(Data)函数*/
//RS命令和数据切换,命令低电平有效,数据高电平有效
void Lcd_WriteCmd(u8 Cmd)
{
LCD_CS_LOW;//CS片选信号低电平有效
LCD_DC_LOW; //命令
SPI_WriteData(Cmd);
LCD_CS_HIGH;
}
void Lcd_WriteData(u8 Data)
{
LCD_CS_LOW;
LCD_DC_HIGH; //数据
SPI_WriteData(Data);
LCD_CS_HIGH;
}
/*在SPI_WriteData()基础上封装成16bit处理*/
void Lcd_WriteData_16bit(u16 Data)
{
LCD_CS_LOW;
LCD_DC_HIGH;
SPI_WriteData(Data>>8);//
SPI_WriteData(Data);
LCD_CS_HIGH;
}
/*同时写命令和数据*/
void Lcd_WriteReg(u8 Cmd,u8 Data)
{
Lcd_WriteCmd(Cmd);
Lcd_WriteData(Data);
}
3.查阅Datasheet的97页COMMAND的篇章
通过对Datasheet中的command篇章的配置信息,可帮助我们对TFT液晶屏上完成我们想要的功能配置
1.Column Address Set 列地址设置(Datasheet中Instruction简写为CASET,后方Function一栏有更详细的功能介绍)
2.Row Address Set 行地址设置 (Datasheet中Instruction简写为RASET)
3.Memory Write(Datasheet中Instruction简写为RAMWR)
Lcd_WriteCmd(0x2A); //列地址设置命令
Lcd_WriteCmd(0x2B); //行地址设置命令
Lcd_WriteCmd(0x2C); //Memory Write填充
/*************************************************
函数名:LCD_Set_Region
功能:设置lcd显示区域,在此区域写点数据自动换行
入口参数:xy起点和终点
返回值:无
*************************************************/
void Lcd_SetRegion(u16 x_start,u16 y_start,u16 x_end,u16 y_end)
{
Lcd_WriteCmd(0x2a);
Lcd_WriteData(0x00);
Lcd_WriteData(x_start);//Lcd_WriteData(x_start+2);
Lcd_WriteData(0x00);
Lcd_WriteData(x_end+2);
Lcd_WriteCmd(0x2b);
Lcd_WriteData(0x00);
Lcd_WriteData(y_start+0);
Lcd_WriteData(0x00);
Lcd_WriteData(y_end+1);
Lcd_WriteCmd(0x2c);
}
计算机最让人着迷之处,也是最伟大的思想之一就是“封装”,当然也为后来者的学习道路留下了重重障碍,颇有一种“只见树木,不见森林”的现象,容易为了细节而迷失其中,迷雾重重。
在《Linux kernel development》一文中,序言有这样一句话:但是所有人都必须直面一个问题:内核的学习曲线变得越来越长,也越来越陡峭。系统规模不断扩大,复杂程度不断提高。虽然现在的内核开发者对内核的掌握越发炉火纯青,但新手却无法跟上内核发展的步伐,长此以往将出现青黄不接的断层。
最近知乎看到这句话(郑培柱 - 知乎 (zhihu.com)—>“对于求知欲特别强的人,有时候一定要学会“浅尝辄止”,充分利用前辈经验,避免陷入技术的误区,比如放着公式不用,非得自己用二重积分推导一遍。”说的简直不能再好,当初我也是这样跌跌撞撞过来的,很有感触。
版权声明:本文为CSDN博主「嵌入式历练者」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Eterlove/article/details/122150263
暂无评论