本帖最后由 jinglixixi 于 2020-6-10 07:55 编辑
使用SPI接口,还可以驱动TFT2.4寸彩屏。 该TFT屏与MCU的连接关系为: LCD_ SCK ——PB11 LCD_ SDI ——PB12 LCD_LED ——3.3V LCD_CS ——GND LCD_DC ——PB5 LCD_ REST ——PB4 其余的两个引脚则接3.3V工作电源
定义GPIO口输出高低电平的语句为: #define LCD_CS_High() GPIO_SetPinLevel(GPIOA, GPIO_PIN8, GPIO_LEVEL_HIGH // PA8 #define LCD_CS_Low() GPIO_SetPinLevel(GPIOA, GPIO_PIN8, GPIO_LEVEL_LOW);
#define LCD_SCK_High() GPIO_SetPinLevel(GPIOB, GPIO_PIN11, GPIO_LEVEL_HIGH); // PB11 #define LCD_SCK_Low() GPIO_SetPinLevel(GPIOB, GPIO_PIN11, GPIO_LEVEL_LOW);
#define LCD_SDI_High() GPIO_SetPinLevel(GPIOB, GPIO_PIN12, GPIO_LEVEL_HIGH); // PB12 #define LCD_SDI_Low() GPIO_SetPinLevel(GPIOB, GPIO_PIN12, GPIO_LEVEL_LOW);
#define LCD_DC_High() GPIO_SetPinLevel(GPIOB, GPIO_PIN5, GPIO_LEVEL_HIGH); // PB5 #define LCD_DC_Low() GPIO_SetPinLevel(GPIOB, GPIO_PIN5, GPIO_LEVEL_LOW);
#define LCD_REST_High() GPIO_SetPinLevel(GPIOB, GPIO_PIN4, GPIO_LEVEL_HIGH); // PB4 #define LCD_REST_Low() GPIO_SetPinLevel(GPIOB, GPIO_PIN4, GPIO_LEVEL_LOW);
TFT屏的初始化函数为: void Lcd_Init(void)
{
LCD_REST_Low();
mdelay(20);
LCD_REST_High();
mdelay(20);
LCD_CS_Low();
LCD_WR_REG(0xCB);
LCD_WR_DATA8(0x39);
LCD_WR_DATA8(0x2C);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x34);
LCD_WR_DATA8(0x02);
LCD_WR_REG(0xCF);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0XC1);
LCD_WR_DATA8(0X30);
LCD_WR_REG(0xE8);
LCD_WR_DATA8(0x85);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x78);
LCD_WR_REG(0xEA);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x00);
LCD_WR_REG(0xED);
LCD_WR_DATA8(0x64);
LCD_WR_DATA8(0x03);
LCD_WR_DATA8(0X12);
LCD_WR_DATA8(0X81);
LCD_WR_REG(0xF7);
LCD_WR_DATA8(0x20);
LCD_WR_REG(0xC0); //Power control
LCD_WR_DATA8(0x23); //VRH[5:0]
LCD_WR_REG(0xC1); //Power control
LCD_WR_DATA8(0x10); //SAP[2:0];BT[3:0]
LCD_WR_REG(0xC5); //VCM control
LCD_WR_DATA8(0x3e); //?????
LCD_WR_DATA8(0x28);
LCD_WR_REG(0xC7); // VCM control2
LCD_WR_DATA8(0x86); // --
LCD_WR_REG(0x36); // Memory Access Control
LCD_WR_DATA8(0x48); // C8
LCD_WR_REG(0x3A);
LCD_WR_DATA8(0x55);
LCD_WR_REG(0xB1);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x18);
LCD_WR_REG(0xB6); // Display Function Control
LCD_WR_DATA8(0x08);
LCD_WR_DATA8(0x82);
LCD_WR_DATA8(0x27);
LCD_WR_REG(0xF2); // 3Gamma Function Disable
LCD_WR_DATA8(0x00);
LCD_WR_REG(0x26); // Gamma curve selected
LCD_WR_DATA8(0x01);
LCD_WR_REG(0xE0); // Set Gamma
LCD_WR_DATA8(0x0F);
LCD_WR_DATA8(0x31);
LCD_WR_DATA8(0x2B);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x08);
LCD_WR_DATA8(0x4E);
LCD_WR_DATA8(0xF1);
LCD_WR_DATA8(0x37);
LCD_WR_DATA8(0x07);
LCD_WR_DATA8(0x10);
LCD_WR_DATA8(0x03);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x09);
LCD_WR_DATA8(0x00);
LCD_WR_REG(0XE1); //Set Gamma
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x14);
LCD_WR_DATA8(0x03);
LCD_WR_DATA8(0x11);
LCD_WR_DATA8(0x07);
LCD_WR_DATA8(0x31);
LCD_WR_DATA8(0xC1);
LCD_WR_DATA8(0x48);
LCD_WR_DATA8(0x08);
LCD_WR_DATA8(0x0F);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x31);
LCD_WR_DATA8(0x36);
LCD_WR_DATA8(0x0F);
LCD_WR_REG(0x11); //Exit Sleep
mdelay(120);
LCD_WR_REG(0x29); //Display on
LCD_WR_REG(0x2c);
}
清屏处理函数为: void LCD_Clear(uint16_t Color)
{
char VH,VL;
uint16_t i,j;
VH=Color>>8;
VL=Color;
Address_set(0,0,LCD_W-1,LCD_H-1);
for(i=0;i<LCD_W;i++)
{
for (j=0;j<LCD_H;j++)
{
LCD_WR_DATA8(VH);
LCD_WR_DATA8(VL);
}
}
}
实现图1和图2显示效果的主程序为: int main(void)
{
InitDelay();
mdelay(200);
GPIO_Configuration();
Lcd_Init();
LCD_Clear(RED);
BACK_COLOR=RED;
POINT_COLOR=WHITE;
LCD_ShowString(20,80,160,16,16,"AC8701 TEST");
LCD_ShowString(20,100,200,16,16,"SPI_TFT 2.4' 240*320");
LCD_ShowString(20,120,160,16,16,"jinglxixi ");
mdelay(1000);
LCD_Clear(WHITE);
show_imageh(10,300,1);
while(1);
}
图1 文字显示效果
图2的显示函数为: void show_imageh(unsigned int x,unsigned int y,unsigned int n) //200*200
{
unsigned int i,j,k;
unsigned int da;
k=0;
for(i=0;i<200;i++)
{
for(j=0;j<200;j++)
{
//if(n==0) da=gImage_yj[k*2];
if(n==1) da=gImage_zs[k*2];
da<<=8;
//if(n==0) da|=gImage_yj[k*2+1];
if(n==1) da|=gImage_zs[k*2+1];
POINT_COLOR=da;
LCD_DrawPoint(x+i,y-j);
k++;
}
}
}
图2 图片显示效果
|