stm32f103rct6驱动LCD屏NT35310初始化
时间: 2023-06-18 14:03:02 浏览: 245
STM32F103初始化文件
驱动LCD屏NT35310需要完成以下几个步骤:
1. 确认LCD屏的通信接口和通信协议,NT35310常用的通信接口为SPI和RGB接口,通信协议为9位或16位数据总线协议。
2. 确认STM32F103RCT6的硬件资源,包括GPIO口、SPI接口等。
3. 初始化SPI接口,设置SPI的时钟分频、传输模式等。
4. 初始化LCD的控制端口,包括复位引脚、片选引脚、数据/命令选择引脚等。
5. 发送初始化命令序列,包括复位命令、使能命令、电源设置命令、像素格式设置命令、显示方向设置命令等。
下面是一个简单的代码示例,仅供参考:
```c
#include "stm32f10x.h"
#define LCD_RST_Pin GPIO_Pin_1
#define LCD_RST_GPIO_Port GPIOA
#define LCD_CS_Pin GPIO_Pin_4
#define LCD_CS_GPIO_Port GPIOA
#define LCD_DC_Pin GPIO_Pin_5
#define LCD_DC_GPIO_Port GPIOA
void SPI_Configuration(void)
{
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE);
}
void LCD_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = LCD_RST_Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LCD_RST_GPIO_Port, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = LCD_CS_Pin | LCD_DC_Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void LCD_Reset(void)
{
GPIO_SetBits(LCD_RST_GPIO_Port, LCD_RST_Pin);
Delay(100);
GPIO_ResetBits(LCD_RST_GPIO_Port, LCD_RST_Pin);
Delay(100);
GPIO_SetBits(LCD_RST_GPIO_Port, LCD_RST_Pin);
Delay(100);
}
void LCD_Write_Cmd(uint8_t cmd)
{
GPIO_ResetBits(GPIOA, LCD_DC_Pin);
GPIO_ResetBits(GPIOA, LCD_CS_Pin);
SPI_I2S_SendData(SPI1, cmd);
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);
GPIO_SetBits(GPIOA, LCD_CS_Pin);
}
void LCD_Write_Data(uint8_t data)
{
GPIO_SetBits(GPIOA, LCD_DC_Pin);
GPIO_ResetBits(GPIOA, LCD_CS_Pin);
SPI_I2S_SendData(SPI1, data);
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);
GPIO_SetBits(GPIOA, LCD_CS_Pin);
}
void LCD_Init(void)
{
SPI_Configuration();
LCD_GPIO_Configuration();
LCD_Reset();
LCD_Write_Cmd(0x01); //软复位
Delay(100);
LCD_Write_Cmd(0x11); //睡眠解除
Delay(100);
LCD_Write_Cmd(0xB0); //设置LCD偏压
LCD_Write_Data(0x10);
Delay(1);
LCD_Write_Data(0x10);
Delay(1);
LCD_Write_Data(0x10);
Delay(1);
LCD_Write_Cmd(0x3A); //设置像素格式
LCD_Write_Data(0x05);
LCD_Write_Cmd(0x36); //设置显示方向
LCD_Write_Data(0x08);
LCD_Write_Cmd(0x29); //设置显示开关
}
```
需要注意的是,上述代码仅供参考,具体代码实现可能需要根据具体的硬件和软件环境进行修改。
阅读全文