本人儿时痴迷
电子,十余岁得一MP4,迷之,觉其小小屏幕,却能观花鸟虫鱼百兽,寻其原理,恐余年少,不得解。便励志日后必要知其理。而今,年长,购得一
STM32核心板加一TFT(ST7789V),敲代码四周,惜TFT依旧白屏无响应,读数据,无所获。郁闷,恨年少励志,却不能完成。今在此一帖,若有能有幸,得大神相助,了却儿时心愿,便无悔,定将平生所积积分赠与大神!坐等!!! 代码奉上(无关代码 没有上):
LCD_Init.c
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "LCD_Init.h"
#include "Sys
tickInit.h"
//初始化GPIO
/**
DB0-DB15 GPIOF0-GPIOF15
CS GPIOE2
RS GPIOE3
WR GPIOE4
RD GPIOE5
IM0 GPIOE6
IM3 GPIOE7
REST GPIOE8
**/
void LCD_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF,ENABLE);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;
GPIO_Init(GPIOE,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
// GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
GPIO_Init(GPIOF,&GPIO_InitStructure);
LCD_CS_SET;
LCD_IM3_CLR;
LCD_IM0_CLR;
LCD_RST_SET;
Delay_us(200);//延时2ms
LCD_RST_CLR;
Delay_us(2000);//延时20ms
LCD_RST_SET;
}
void LCD_GPIO_Init2(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
GPIO_Init(GPIOF,&GPIO_InitStructure);
}
void LCD_WR_Data(u16 dat)
{
LCD_RS_SET;
LCD_RD_SET;
LCD_WR_SET;
LCD_CS_CLR;
GPIOF->ODR=dat;
LCD_WR_CLR;
LCD_WR_SET;
Delay_us(10);
LCD_CS_SET;
}
void LCD_WR_Cmd(u8 cmd)
{
LCD_RS_CLR;
LCD_RD_SET;
LCD_WR_SET;
LCD_CS_CLR;
GPIOF->ODR=cmd;
//GPIO_SetBits(GPIOF,GPIO_Pin_2);
LCD_WR_CLR;
LCD_WR_SET;
Delay_us(10);
LCD_CS_SET;
}
u16 LCD_RD_Cmd(void)
{
u16 dat;
LCD_RS_SET;
LCD_RD_SET;
LCD_WR_SET;
LCD_CS_CLR;
LCD_RD_CLR;
LCD_RD_SET;
dat=GPIO_ReadInputData(GPIOF);
Delay_us(10);
LCD_CS_SET;
return dat;
}
void LCD_WR_Reg(u16 reg,u16 dat)
{
LCD_WR_Cmd(reg);
LCD_WR_Data(dat);
}
void LCD_Init(void)
{
LCD_GPIO_Init();
LCD_WR_Cmd(0xaa);
LCD_WR_Cmd(0xb2);
LCD_WR_Data(0x0c);
LCD_WR_Data(0x0c);
LCD_WR_Data(0x00);
LCD_WR_Data(0x33);
LCD_WR_Data(0x33);
LCD_WR_Cmd(0xb7);
LCD_WR_Data(0x35);
//---------------------------------ST7789S Power setting--------------------------------------//
LCD_WR_Cmd(0xbb);
LCD_WR_Data(0x2b);
LCD_WR_Cmd(0xc3);
LCD_WR_Data(0x17);
LCD_WR_Cmd(0xc4);
LCD_WR_Data(0x20);
LCD_WR_Cmd(0xc6);//NLA2 NLA1 NLA0 (0x00: dot/0x07: column) RTNA4 RTNA3 RTNA2 RTNA1 RTNA0 Frame
LCD_WR_Data(0x0f);
LCD_WR_Cmd(0x3A);
LCD_WR_Data(0x55);
LCD_WR_Cmd(0x36);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xd0);
LCD_WR_Data(0xa4);
LCD_WR_Data(0xa2);
//--------------------------------ST7789S gamma setting---------------------------------------//
LCD_WR_Cmd(0xe0);
LCD_WR_Data(0xf0);
LCD_WR_Data(0x00);
LCD_WR_Data(0x0a);
LCD_WR_Data(0x10);
LCD_WR_Data(0x12);
LCD_WR_Data(0x1b);
LCD_WR_Data(0x39);
LCD_WR_Data(0x44);
LCD_WR_Data(0x47);
LCD_WR_Data(0x28);
LCD_WR_Data(0x12);
LCD_WR_Data(0x10);
LCD_WR_Data(0x16);
LCD_WR_Data(0x1b);
LCD_WR_Cmd(0xe1);
LCD_WR_Data(0xf0);
LCD_WR_Data(0x00);
LCD_WR_Data(0x0a);
LCD_WR_Data(0x10);
LCD_WR_Data(0x11);
LCD_WR_Data(0x1a);
LCD_WR_Data(0x3b);
LCD_WR_Data(0x34);
LCD_WR_Data(0x4e);
LCD_WR_Data(0x3a);
LCD_WR_Data(0x17);
LCD_WR_Data(0x16);
LCD_WR_Data(0x21);
LCD_WR_Data(0x22);
LCD_WR_Cmd(0x11); // Sleep out
Delay_us(10000);
LCD_WR_Cmd(0x29); // Display on
LCD_WR_Cmd(0x2c);
}
void LCD_Brush(void)
{
int i,j;
LCD_GPIO_Init();
LCD_WR_Cmd(0x002C);
for(i=0;i<320;i++)
{
for(j=0;j<240;j++)
{
// LCD_WRITE_DATA(color>>8);
// LCD_WRITE_DATA(color);
LCD_WR_Data(0x00);
}
}
while(1);
}
main.c
#include "stm32f10x.h"
#include "SysTickInit.h"
#include "LCD_Init.h"
#include "LED_TEST.h"
#include "USART3_Config.h"
int main()
{
u16 dat;
SystemInit();
SysTickInit();
//led_test();
//LCD_Init();
// LCD_Brush();
USART3_Init();
LCD_GPIO_Init();
LCD_WR_Cmd(0x01);
while(1)
{
Delay_us(500000);
LCD_GPIO_Init();
LCD_WR_Cmd(0x04);
dat=GPIO_ReadOutputData(GPIOF);
LCD_GPIO_Init2();
SendData(dat);
dat=LCD_RD_Cmd();
// SendData(dat);
// LCD_GPIO_Init2();
SendData(dat);
dat=LCD_RD_Cmd();
// SendData(dat);
// LCD_GPIO_Init2();
SendData(dat);
dat=LCD_RD_Cmd();
SendData(dat);
dat=LCD_RD_Cmd();
// SendData(dat);
// LCD_GPIO_Init2();
SendData(dat);
// Delay_us(500000);
}
}
我错了 大兄弟 马上奉上带注释的
一周热门 更多>