|
Lcd_Init();
Lcd_Clear_xy(0,0,BLACK);
// Gui_DrawFont_GBK16(0,0,YELLOW,RED,"TTTTTT");//显示字符串
//
// Gui_DrawFont_GBK16(0,0,YELLOW,RED,"YYYY");
// Gui_DrawFont_GBK16(32,0,YELLOW,RED," ");
//
// Lcd_Clear_xy(64,100,YELLOW);//清空 从64,100到128,128
// Lcd_Clear_xy_xy(30,30,100,60,YELLOW);//清空从 30,30到100,60
// Lcd_Clear_xy_xy(32,30,68,33,YELLOW);
HAL_TIM_Base_Start_IT(&htim2);
showimage(gImage_zxc);//显示图片
//Gui_DrawFont_GBK16(40,116,YELLOW,RED,(uint8_t *)"TTTTTT");
//Lcd_Clear(RED);//清屏填充颜色
//showimage(gImage_zxc);
//向液晶屏写一个8位指令
void Lcd_WriteIndex(uint8_t Index)
{
//SPI 写命令时序开始
//NSS = 0;
LCD_CS_CLR;
LCD_RS_CLR; //LCD_RS_CLR
HAL_SPI_Transmit(&hspi1,&Index,1,0xfff);
//NSS = 1;
LCD_CS_SET;
}
//向液晶屏写一个8位数据
void Lcd_WriteData(uint8_t Data)
{
LCD_CS_CLR;
LCD_RS_SET;
HAL_SPI_Transmit(&hspi1,&Data,1,0xfff);
LCD_CS_SET;
}
void LCD_WriteData_16Bit(uint16_t Data)
{
uint8_t Data_H = Data>>8;
uint8_t Data_L = Data&0xFF;
LCD_CS_CLR;
LCD_RS_SET;
HAL_SPI_Transmit(&hspi1,&Data_H,1,0xfff); //写入高8位数据
HAL_SPI_Transmit(&hspi1,&Data_L,1,0xfff); //写入低8位数据
LCD_CS_SET;
}
//LCD Init For 1.44Inch LCD Panel with ST7735R.
void Lcd_Init(void)
{
// LCD_GPIO_Init();
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, 1);
LCD_RST_CLR;
HAL_Delay(100);
LCD_RST_SET;
HAL_Delay(50);
Lcd_WriteIndex(0x11);//Sleep exit
HAL_Delay(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(0xC8);
//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
}
|
-
-
SPITEST.7z
5.82 MB, 下载次数: 89, 下载积分: 黑币 -5
STM32CubeMXTFTLCD
|