本帖最后由 liunan 于 2018-10-22 23:24 编辑
前几天从某宝上买了一块ST7735R液晶屏,在stm32f103上进行代码移植。初始化发现刷屏颜 {MOD}不对应黑 {MOD}刷成白 {MOD},白 {MOD}刷成黑 {MOD}其他颜 {MOD}一团糟。求路过的大佬帮看看呀感激不尽!
代码如下
#define LCD_HEIGHT 160
#define LCD_WIDTH 128
//画笔颜 {MOD}
#define RED 0XF800 //红 {MOD}
#define GREEN 0X07E0 //绿 {MOD}
#define BLUE 0X001F //蓝 {MOD}
#define BRED 0XF81F
#define GRED 0XFFE0 //灰 {MOD}
#define GBLUE 0X07FF //
#define BLACK 0X0000 //黑 {MOD}
#define WHITE 0XFFFF //白 {MOD}
#define YELLOW 0xFFE0 //黄 {MOD}
void ST7725R_Init(void)
{
LCD_GPIO_Init(); //端口初始化
LCD_Reset(); //LCD复位,在LCD初始化之前
delay_ms(300);
LCD_WR_CMD(0x11); //Sleep out 退出睡眠模式
delay_ms(120); //Delay 120ms
//------------------------------------ST7735R Frame Rate-----------------------------------------//
/* Set the frame frequency of the full colors normal mode. */
LCD_WR_CMD(0xB1); //In Normal Mode (Full Colors) 全屏模式
LCD_WR_Byte(0x05); //设置 RTNA Set 1-line Period 一行周期
LCD_WR_Byte(0x3A); //设置 FPA: Front Porch
LCD_WR_Byte(0x3A); //设置 BPA: Back Porch
//Frame rate=fosc/((RTNA x 2 + 40) x (LINE + FPA + BPA +2))
//其中 fosc = 850kHz
/* Set the frame frequency of the Idle mode. */
LCD_WR_CMD(0xB2); //In Idle Mode (8-colors)
LCD_WR_Byte(0x05);
LCD_WR_Byte(0x3A);
LCD_WR_Byte(0x3A);
/* Set the frame frequency of the Partial mode/ full colors. */
LCD_WR_CMD(0xB3);
LCD_WR_Byte(0x05);
LCD_WR_Byte(0x3A);
LCD_WR_Byte(0x3A);
LCD_WR_Byte(0x05);
LCD_WR_Byte(0x3A);
LCD_WR_Byte(0x3A);
//------------------------------------End ST7735R Frame Rate-----------------------------------------//
LCD_WR_CMD(0xB4); //Display Inversion Control 显示反转控制
LCD_WR_Byte(0x07); //LCD_WR_Byte(0x03); 原来为3,改为7
// 低三位从高到低,分别为 full colors normal mode 、Idle mode 、
// full Colors partial mode 的 点反转 或 列反转 ,1为列反转
LCD_WR_CMD(0xC0); //Power Control Setting 电源控制设置
LCD_WR_Byte(0x28);
LCD_WR_Byte(0x08);
LCD_WR_Byte(0x84);
LCD_WR_CMD(0xC1);
LCD_WR_Byte(0XC0);
LCD_WR_CMD(0xC2);
LCD_WR_Byte(0x0C);
LCD_WR_Byte(0x00);
LCD_WR_CMD(0xC3);
LCD_WR_Byte(0x8C);
LCD_WR_Byte(0x2A);
LCD_WR_CMD(0xC4);
LCD_WR_Byte(0x8A);
LCD_WR_Byte(0xEE);
//---------------------------------End ST7735R Power Sequence-------------------------------------//
LCD_WR_CMD(0xC5); // VCOM 电压配置
LCD_WR_Byte(0x0C); // -0.725
//------------------------------------ST7735R Gamma Sequence-----------------------------------------//
LCD_WR_CMD(0x36); //MX, MY, RGB mode
LCD_WR_Byte(0xC8); //0x68
LCD_WR_CMD(0xE0);
LCD_WR_Byte(0x05);
LCD_WR_Byte(0x1A);
LCD_WR_Byte(0x0C);
LCD_WR_Byte(0x0E);
LCD_WR_Byte(0x3A);
LCD_WR_Byte(0x34);
LCD_WR_Byte(0x2D);
LCD_WR_Byte(0x2F);
LCD_WR_Byte(0x2D);
LCD_WR_Byte(0x2A);
LCD_WR_Byte(0x2F);
LCD_WR_Byte(0x3C);
LCD_WR_Byte(0x00);
LCD_WR_Byte(0x01);
LCD_WR_Byte(0x02);
LCD_WR_Byte(0x10);
LCD_WR_CMD(0xE1);
LCD_WR_Byte(0x04);
LCD_WR_Byte(0x1B);
LCD_WR_Byte(0x0D);
LCD_WR_Byte(0x0E);
LCD_WR_Byte(0x2D);
LCD_WR_Byte(0x29);
LCD_WR_Byte(0x24);
LCD_WR_Byte(0x29);
LCD_WR_Byte(0x28);
LCD_WR_Byte(0x26);
LCD_WR_Byte(0x31);
LCD_WR_Byte(0x3B);
LCD_WR_Byte(0x00);
LCD_WR_Byte(0x00);
LCD_WR_Byte(0x03);
LCD_WR_Byte(0x12);
//------------------------------------End ST7735R Gamma Sequence-----------------------------------------//
LCD_WR_CMD(0x3A); //65k mode
LCD_WR_Byte(0x05);
LCD_WR_CMD(0x29); //开显示 Display on
LCD_WR_CMD(0x2c); //
LCD_Clear(BLACK); //刷屏黑 {MOD}
}
//设置lcd显示区域,在此区域写点数据自动换行
//xy起点和终点
void LCD_SetRegion(u16 x_start,u16 y_start,u16 x_end,u16 y_end)
{
LCD_WR_CMD(0x2a);
LCD_WR_Byte(0x00);
LCD_WR_Byte(x_start);
LCD_WR_Byte(0x00);
LCD_WR_Byte(x_end);
LCD_WR_CMD(0x2b);
LCD_WR_Byte(0x00);
LCD_WR_Byte(y_start);
LCD_WR_Byte(0x00);
LCD_WR_Byte(y_end);
LCD_WR_CMD(0x2c);
}
//设置光标位置
//Xpos:横坐标
//Ypos:纵坐标
void LCD_SetCursor(u16 x, u16 y)
{
LCD_SetRegion(x,y,x,y);
}
//LCD清屏函数
//color:填充的函数
void LCD_Clear(u16 color)
{
u16 i,m;
LCD_SetRegion(0,0,LCD_WIDTH-1,LCD_HEIGHT-1);
LCD_WR_CMD(0x2C);
for(i=0;i<LCD_HEIGHT;i++)
for(m=0;m<LCD_WIDTH;m++)
{
LCD_WR_Byte16Bit(color);
}
}
//向液晶屏写一个16位数据
void LCD_WR_Byte16Bit(u16 data)
{
u8 bit8,DATAH,DATAL;
DATAH=(data>>8);
DATAL=(data&0xff);
LCD_RS=1;
LCD_CS=0;
for(bit8=0;bit8<8;bit8++)
{
LCD_SCLK=0;
if((DATAH&0x80)==0x80)
LCD_SDIN=1;
else
LCD_SDIN=0;
LCD_SCLK=1;
DATAH=(DATAH<<1);
}
LCD_CS=1;
LCD_CS=0;
for(bit8=0;bit8<8;bit8++)
{
LCD_SCLK=0;
if((DATAL&0x80)==0x80)
LCD_SDIN=1;
else
LCD_SDIN=0;
LCD_SCLK=1;
DATAL=(DATAL<<1);
}
LCD_CS=1;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
楼主这个问题解决了吗?
一周热门 更多>