中颖电子sh32f9001芯片开发lcd显示屏驱动
1、spi初始化
static void spi0_init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
SPI_InitTypeDef SPI_InitStruct;
RCC_AHBPeriphClockOnOff(RCC_AHB_IOCLK, SH_ON);
RCC_APB1PeriphClockOnOff(RCC_APB1_SPI0, SH_ON);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_ODrv = GPIO_ODrv_NORMAL;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_SET);
GPIO_WriteBit(GPIOC, GPIO_Pin_12, Bit_SET);
GPIO_WriteBit(GPIOC, GPIO_Pin_13, Bit_SET);
GPIO_WriteBit(GPIOC, GPIO_Pin_14, Bit_SET);
GPIO_PinAFConfig(GPIOC, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14, GPIO_AF_SPI0);
SPI_InitStruct.Clock = SPR_PCKL1_DIV_128;
SPI_InitStruct.SSPin = PIN_SS_DISABLE;
SPI_InitStruct.ClkIdleState = CLK_IDLE_HIGH;
SPI_InitStruct.CaptureEdge = CAP_CLK_EDGE1;
SPI_InitStruct.MasterOrSlave = SPI_MASTER;
SPI_InitStruct.Direction = SPI_TRANS_MSB;
SPI_InitStruct.DataSize = SPI_DATASIZE_8b;
SPI_InitStruct.SlaveTransMode = SPI_SLAVE_NORMAL;
SPI_InitStruct.bufferSize = SPI_BUFFERSIZE_SPDATL;
SPI_Init(SPI0, &SPI_InitStruct);
SPI_OnOff(SPI0, SH_ON);
}
2、spi数据手法接口
static uint8_t spi0_sendByte(uint8_t SendByte)
{
SPI_SendData(SPI0, SendByte);
SPI_ClearFlag(SPI0, SPI_FLAG_RECEIVE_INT);
while(SPI_GetFlagStatus(SPI0, SPI_FLAG_RECEIVE_INT) == 0){
__nop();
}
return (uint8_t)SPI_ReceiveData(SPI0);
}
3、lcd7789发送数据
static void lcd7789_data(uint8_t data)
{
lcd_SPI_CS_reset;
lcd_DC_set;
SPI_SendByte(SPI0_ID, data);
lcd_SPI_CS_set;
}
4、lcd7789发送命令
static void lcd7789_command(uint8_t data)
{
lcd_SPI_CS_reset;
lcd_DC_reset;
SPI_SendByte(SPI0_ID, data);
lcd_SPI_CS_set;
}
5、lcd7789屏初始化
void lcd7789_init(void)
{
lcd_gpioInit();
lcd_BL_set; //BL high
lcd7789_reset();
delay_ms(120);
lcd7789_command(0x11);
delay_ms(120);
lcd7789_command(0x36);
lcd7789_data(0x00);
lcd7789_command(0x3A);
lcd7789_data(0x06);
lcd7789_command(0xB2);
lcd7789_data(0x0C);
lcd7789_data(0x0C);
lcd7789_data(0x00);
lcd7789_data(0x33);
lcd7789_data(0x33);
lcd7789_command(0xB7);
lcd7789_data(0x35);
lcd7789_command(0xBB);
lcd7789_data(0x13);
lcd7789_command(0xC0);
lcd7789_data(0x2C);
lcd7789_command(0xC2);
lcd7789_data(0x01);
lcd7789_command(0xC3);
lcd7789_data(0x0B);
lcd7789_command(0xC4);
lcd7789_data(0x20);
lcd7789_command(0xC6);
lcd7789_data(0x0F);
lcd7789_command(0xD0);
lcd7789_data(0xA4);
lcd7789_data(0xA1);
lcd7789_command(0x21);
lcd7789_command(0xE0);
lcd7789_data(0x00);
lcd7789_data(0x03);
lcd7789_data(0x07);
lcd7789_data(0x08);
lcd7789_data(0x07);
lcd7789_data(0x15);
lcd7789_data(0x2A);
lcd7789_data(0x44);
lcd7789_data(0x42);
lcd7789_data(0x0A);
lcd7789_data(0x17);
lcd7789_data(0x18);
lcd7789_data(0x25);
lcd7789_data(0x27);
lcd7789_command(0xE1);
lcd7789_data(0x00);
lcd7789_data(0x03);
lcd7789_data(0x08);
lcd7789_data(0x07);
lcd7789_data(0x07);
lcd7789_data(0x23);
lcd7789_data(0x2A);
lcd7789_data(0x43);
lcd7789_data(0x42);
lcd7789_data(0x09);
lcd7789_data(0x18);
lcd7789_data(0x17);
lcd7789_data(0x25);
lcd7789_data(0x27);
lcd7789_command(0x29);
lcd7789_command(0x2A);
lcd7789_data(0x00);
lcd7789_data(0x23);
lcd7789_data(0x00);
lcd7789_data(0xCC);
lcd7789_command(0x2B);
lcd7789_data(0x00);
lcd7789_data(0x00);
lcd7789_data(0x01);
lcd7789_data(0x3F);
lcd7789_command(0x2C);
}
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_45270358/article/details/133931005
|