1.8寸lcd使用gpio模拟spi驱动
由于板子引出的接口限制,故使用gpio模拟spi驱动中景园的1.8寸lcd
1.77寸液晶屏 1.8寸TFT LCD SPI TFT彩屏st7735驱动128x160高清屏-淘宝网 (taobao.com)
使用RASC 的gpio配置
根据厂家提供的驱动文件移植
#define LCD_SCLK_Clr() g_ioport.p_api->pinWrite(g_ioport.p_ctrl, BSP_IO_PORT_00_PIN_04, BSP_IO_LEVEL_LOW) //SCL=SCLK
#define LCD_SCLK_Set() g_ioport.p_api->pinWrite(g_ioport.p_ctrl, BSP_IO_PORT_00_PIN_04, BSP_IO_LEVEL_HIGH)#define LCD_MOSI_Clr() g_ioport.p_api->pinWrite(g_ioport.p_ctrl, BSP_IO_PORT_00_PIN_05, BSP_IO_LEVEL_LOW) //SDA=MOSI
#define LCD_MOSI_Set() g_ioport.p_api->pinWrite(g_ioport.p_ctrl, BSP_IO_PORT_00_PIN_05, BSP_IO_LEVEL_HIGH)#define LCD_RES_Clr() g_ioport.p_api->pinWrite(g_ioport.p_ctrl, BSP_IO_PORT_00_PIN_06, BSP_IO_LEVEL_LOW) //RES
#define LCD_RES_Set() g_ioport.p_api->pinWrite(g_ioport.p_ctrl, BSP_IO_PORT_00_PIN_06, BSP_IO_LEVEL_HIGH)#define LCD_DC_Clr() g_ioport.p_api->pinWrite(g_ioport.p_ctrl, BSP_IO_PORT_03_PIN_08, BSP_IO_LEVEL_LOW) //DC
#define LCD_DC_Set() g_ioport.p_api->pinWrite(g_ioport.p_ctrl, BSP_IO_PORT_03_PIN_08, BSP_IO_LEVEL_HIGH)#define LCD_CS_Clr() g_ioport.p_api->pinWrite(g_ioport.p_ctrl, BSP_IO_PORT_03_PIN_07, BSP_IO_LEVEL_LOW) //CS
#define LCD_CS_Set() g_ioport.p_api->pinWrite(g_ioport.p_ctrl, BSP_IO_PORT_03_PIN_07, BSP_IO_LEVEL_HIGH)#define LCD_BLK_Clr() g_ioport.p_api->pinWrite(g_ioport.p_ctrl, BSP_IO_PORT_03_PIN_06, BSP_IO_LEVEL_LOW) //BLK
#define LCD_BLK_Set() g_ioport.p_api->pinWrite(g_ioport.p_ctrl, BSP_IO_PORT_03_PIN_06, BSP_IO_LEVEL_HIGH)
提供延时函数
void delay_ms(int ms)
{R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS);
}
屏蔽stm32先关头文件和gpio初始化
void LCD_GPIO_Init(void)
{
// GPIO_InitTypeDef GPIO_InitStructure;
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能A端口时钟
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//速度50MHz
// GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化GPIOA
// GPIO_SetBits(GPIOA,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5);
}
下载测试