调试字体颜色为#define PURPLE 0xF81F //紫,实际显示为绿色
调试字体颜色为#define WHITE 0xFFFF //白,实际显示为黄色
不知道哪设置不对
//屏幕转向和RGB格式
tft_write_reg(0x36);
tft_write_byte(0xA0);
//设置A8也不行
tft_write_byte(0xA8);
//***********************************************************************
//TFT常用颜色(RGB565采用两个字节表示颜色,前5位表示红色,中间6位表示绿色,后面5位表示蓝色)
#define RED 0xF800 //红
#define YELLOW 0xFFE0 //黄
#define GREEN 0x07E0 //绿
#define CYAN 0x07FF //青
#define BLUE 0x001F //蓝
#define PURPLE 0xF81F //紫
#define BLACK 0x0000 //黑
#define WHITE 0xFFFF //白
#define GRAY 0x7BEF //灰
//LCD初始化
void tft_init(void)
{
sys_delay = 20/10;
LCD_RST = 0;
while(sys_delay){rst_wdi();}
LCD_RST = 1;
//等待芯片复位时间200ms
sys_delay = 200/10;
while(sys_delay){rst_wdi();}
//端口初始化
LCD_CS = 1;
LCD_CLK = 0;
//芯片初始化
tft_write_reg(0x11);
sys_delay = 200/10;
while(sys_delay){rst_wdi();}
//tft_write_reg(0x21); //显示反转
//帧速率设置
tft_write_reg(0xB1);
tft_write_byte(0x01);
tft_write_byte(0x2c);
tft_write_byte(0x2d);
tft_write_reg(0xB2);
tft_write_byte(0x01);
tft_write_byte(0x2c);
tft_write_byte(0x2d);
tft_write_reg(0xB3);
tft_write_byte(0x01);
tft_write_byte(0x2c);
tft_write_byte(0x2d);
tft_write_byte(0x01);
tft_write_byte(0x2c);
tft_write_byte(0x2d);
//列反转模式设置
tft_write_reg(0xB4);
tft_write_byte(0x07);
//POWER CONTROL
tft_write_reg(0xC0);
tft_write_byte(0xa2);
tft_write_byte(0x02);
tft_write_byte(0x84);
//电压设置
tft_write_reg(0xC1);
tft_write_byte(0xC5);
tft_write_reg(0xC2);
tft_write_byte(0x0a);
tft_write_byte(0x00);
tft_write_reg(0xC3);
tft_write_byte(0x8a);
tft_write_byte(0x2A);
tft_write_reg(0xC4);
tft_write_byte(0x8a);
tft_write_byte(0xEE);
tft_write_reg(0xC5); //VCOM/
tft_write_byte(0x0e);
//屏幕转向和RGB格式
tft_write_reg(0x36);
tft_write_byte(0xA0);
tft_write_reg(0xe0);
tft_write_byte(0x0f);
tft_write_byte(0x1a);
tft_write_byte(0x0f);
tft_write_byte(0x18);
tft_write_byte(0x2f);
tft_write_byte(0x28);
tft_write_byte(0x20);
tft_write_byte(0x22);
tft_write_byte(0x1f);
tft_write_byte(0x1b);
tft_write_byte(0x23);
tft_write_byte(0x37);
tft_write_byte(0x00);
tft_write_byte(0x07);
tft_write_byte(0x02);
tft_write_byte(0x10);
tft_write_reg(0xe1);
tft_write_byte(0x0f);
tft_write_byte(0x1b);
tft_write_byte(0x0f);
tft_write_byte(0x17);
tft_write_byte(0x33);
tft_write_byte(0x2c);
tft_write_byte(0x29);
tft_write_byte(0x2e);
tft_write_byte(0x30);
tft_write_byte(0x30);
tft_write_byte(0x39);
tft_write_byte(0x3f);
tft_write_byte(0x00);
tft_write_byte(0x07);
tft_write_byte(0x03);
tft_write_byte(0x10);
//interface 16bit / pixle
tft_write_reg(0x3A);
tft_write_byte(0x05);
tft_write_reg(0x29);
tft_clear();
}
void tft_write_char (uint8_t sx,uint8_t sy,uint8_t in_data)
{
uint8_t i = 0, j= 0,temp;
uint8_t *ptr = ASCII + ((in_data - 0x20) * 16);
tft_window_set(sx,sy,sx+7,sy+15);
for (i = 0;i < 16; i++)
{
temp = *ptr;
for (j = 0; j < 8; j++)
{
if(temp & 0x01){tft_write_word(PURPLE);}
else{tft_write_word(BLACK);}
temp >>= 1;
}
ptr++;
}
}
void tft_write_msg(uint8_t sx,uint8_t sy,uint8_t *str)
{
unsigned char i = 0;
rst_wdi();
while((*str != '\0')&&(i < 20))//最大限制为20字符
{
tft_write_char (sx,sy,*str++);
sx += 8;
i++;
}
}
|