lcd.c
void lcd_init()
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE );//PORTA时钟使能
RCC_APB2PeriphClockCmd( RCC_APB2Periph_SPI1, ENABLE );//SPI1时钟使能
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_8|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_SetBits(GPIOA,GPIO_Pin_4|GPIO_Pin_8|GPIO_Pin_15);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOB,GPIO_Pin_3);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6| GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA
GPIO_SetBits(GPIOA,GPIO_Pin_5 | GPIO_Pin_6| GPIO_Pin_7); //PB13/14/15上拉
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //设置SPI单向或者双向的数据模式:SPI设置为双线双向全双工
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //设置SPI工作模式:设置为主SPI
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //设置SPI的数据大小:SPI发送接收8位帧结构
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //串行同步时钟的空闲状态为高电平
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; //串行同步时钟的第二个跳变沿(上升或下降)数据被采样
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //NSS信号由硬件(NSS管脚)还是软件(使用SSI位)管理:内部NSS信号有SSI位控制
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; //定义波特率预分频的值:波特率预分频值为256
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //指定数据传输从MSB位还是LSB位开始:数据传输从MSB位开始
SPI_InitStructure.SPI_CRCPolynomial = 7; //CRC值计算的多项式
SPI_Init(SPI1, &SPI_InitStructure); //根据SPI_InitStruct中指定的参数初始化外设SPIx寄存器
SPI_Cmd(SPI1, ENABLE); //使能SPI外设
// lcd_read_write_byte(0xff);//启动传输
lcd_rst=1;
delay_ms(120);
lcd_rst=0;
delay_ms(120);
lcd_rst=1;
delay_ms(120);
/* Sleep Out */
lcd_write_cmd(0x11);
/* wait for power stability */
delay_ms(120);
lcd_write_cmd(0x36);
lcd_write_data(0x00);
lcd_write_cmd(0x3a);
lcd_write_data(0x05);
//--------------------------------ST7789V Frame rate setting----------------------------------//
lcd_write_cmd(0xb2);
lcd_write_data(0x0c);
lcd_write_data(0x0c);
lcd_write_data(0x00);
lcd_write_data(0x33);
lcd_write_data(0x33);
lcd_write_cmd(0xb7);
lcd_write_data(0x35);
//---------------------------------ST7789V Power setting--------------------------------------//
lcd_write_cmd(0xbb);
lcd_write_data(0x1c);
lcd_write_cmd(0xc0);
lcd_write_data(0x2c);
lcd_write_cmd(0xc2);
lcd_write_data(0x01);
lcd_write_cmd(0xc3);
lcd_write_data(0x0b);
lcd_write_cmd(0xc4);
lcd_write_data(0x20);
lcd_write_cmd(0xc6);
lcd_write_data(0x0f);
lcd_write_cmd(0xd0);
lcd_write_data(0xa4);
lcd_write_data(0xa1);
//--------------------------------ST7789V gamma setting---------------------------------------//
lcd_write_cmd(0xe0);
lcd_write_data(0xd0);
lcd_write_data(0x00);
lcd_write_data(0x03);
lcd_write_data(0x09);
lcd_write_data(0x13);
lcd_write_data(0x1c);
lcd_write_data(0x3a);
lcd_write_data(0x55);
lcd_write_data(0x48);
lcd_write_data(0x18);
lcd_write_data(0x12);
lcd_write_data(0x0e);
lcd_write_data(0x19);
lcd_write_data(0x1e);
lcd_write_cmd(0xe1);
lcd_write_data(0xd0);
lcd_write_data(0x00);
lcd_write_data(0x03);
lcd_write_data(0x09);
lcd_write_data(0x05);
lcd_write_data(0x25);
lcd_write_data(0x3a);
lcd_write_data(0x55);
lcd_write_data(0x50);
lcd_write_data(0x3d);
lcd_write_data(0x1c);
lcd_write_data(0x1d);
lcd_write_data(0x1d);
lcd_write_data(0x1e);
lcd_write_cmd(0x29);
lcd_address_set(0, 0, LCD_Width - 1, LCD_Height - 1);
lcd_set_speed(SPI_BaudRatePrescaler_2);
open_lcd();
}
|