本帖最后由 jinglixixi 于 2020-8-17 09:09 编辑
2.2' TFT屏是一款彩色TFT显示屏,可用于信息显示及图形绘制等。 在合理配置引脚使用的情况下,可驱动TFT显示屏。为此使TFT显示屏与NV32F100建立如下的连接关系: CS --- PD1 REST--- PH1 DC --- P H0 SDI --- PE0 SCK --- PE1
为驱动TFT显示屏使相关引脚输出高低电平的语句为: #define LCD_CS_High() GPIO_PinSet(GPIO_PTD1); #define LCD_CS_Low() GPIO_PinClear(GPIO_PTD1); #define LCD_REST_High() GPIO_PinSet(GPIO_PTH1); #define LCD_REST_Low() GPIO_PinClear(GPIO_PTH1); #define LCD_DC_High() GPIO_PinSet(GPIO_PTH0); #define LCD_DC_Low() GPIO_PinClear(GPIO_PTH0); #define LCD_SDI_High() GPIO_PinSet(GPIO_PTE0); #define LCD_SDI_Low() GPIO_PinClear(GPIO_PTE0); #define LCD_SCK_High() GPIO_PinSet(GPIO_PTE1); #define LCD_SCK_Low() GPIO_PinClear(GPIO_PTE1);
相关引脚的配置函数为: void GPIO_Configuration(void)
{
GPIO_Init(GPIOB, GPIO_PTE0_MASK, GPIO_PinOutput);
GPIO_Init(GPIOB, GPIO_PTE1_MASK, GPIO_PinOutput);
GPIO_Init(GPIOB, GPIO_PTH0_MASK, GPIO_PinOutput);
GPIO_Init(GPIOB, GPIO_PTH1_MASK, GPIO_PinOutput);
GPIO_Init(GPIOA, GPIO_PTD1_MASK, GPIO_PinOutput);
}
进行TFT显示屏初始化的函数为: void Lcd_Init(void)
{
LCD_REST_Low();
delay_ms(20);
LCD_REST_High();
delay_ms(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
delay_ms(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);
}
}
}
显示字符串的函数为: void LCD_ShowStringH(uint16_t x,uint16_t y,uint16_t width,uint16_t height,char size,char *p)
{
char x0=x;
width+=x;
height+=y;
while((*p<='~')&&(*p>=' '))
{
if(x>=width){x=x0;y+=size;}
if(y>=height)break;
LCD_ShowCharZ(x,y,*p,size,1);
x-=size/2;
p++;
}
}
屏幕显示效果的函数为: void xianshi(void)
{
BACK_COLOR=RED;
POINT_COLOR=WHITE;
LCD_ShowStringH(240,70,100,16,16,"NV32F100FL64E");
LCD_ShowStringH(240,100,100,16,16,"2.4'TFT TEST");
LCD_ShowStringH(240,130,100,16,16,"jinglixixi");
LCD_ShowStringH(240,160,100,16,16,"2020.8.16");
}
显示效果的主程序为: int main (void)
{
sysinit();
cpu_identify();
GPIO_Init(GPIOB, GPIO_PTE7_MASK, GPIO_PinOutput);
GPIO_Init(GPIOB, GPIO_PTE7_MASK, GPIO_PinOutput);
GPIO_Configuration();
Lcd_Init();
LCD_Clear(RED);
xianshi();
while(1);
}
字符串显示效果
中文显示效果
|