/**************************************************************************************************** //=========================================电源接线================================================// // LCD模块 STM32单片机 // VCC 接 DC5V/3.3V //电源 // GND 接 GND //电源地 //=======================================液晶屏数据线接线==========================================// //本模块默认数据总线类型为SPI总线 // LCD模块 STM32单片机 // SDA 接 PB15 //液晶屏SPI总线数据写信号 //=======================================液晶屏控制线接线==========================================// // LCD模块 STM32单片机 // SCK 接 PB13 //液晶屏SPI总线时钟信号 // A0 接 PB10 //液晶屏数据/命令控制信号 // RESET 接 PB12 //液晶屏复位控制信号 // CS 接 PB11 //液晶屏片选控制信号 **************************************************************************************************/ /* @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, QD electronic SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. **************************************************************************************************/ #include "lcd.h" #include "stdlib.h" #include "spi.h" #include "main.h" //管理LCD重要参数 //默认为竖屏 _lcd_dev lcddev; //画笔颜色,背景颜色 uint16_t POINT_COLOR = 0x0000,BACK_COLOR = 0xFFFF; uint16_t DeviceCode; /***************************************************************************** * @name :u8 SPI_WriteByte(x,u8 Byte) * @date :2018-08-09 * @function :Write a byte of data using STM32's hardware SPI * @parameters : Byte:Data to be written ******************************************************************************/ uint8_t SPI2_ReadWriteByte( uint8_t TxData) { uint8_t Rxdata; HAL_SPI_TransmitReceive(&hspi2,&TxData,&Rxdata,1, 1000); return Rxdata; } /***************************************************************************** * @name :void LCD_WR_REG(uint8_t data) * @date :2018-08-09 * @function :Write an 8-bit command to the LCD screen * @parameters :data:Command value to be written * @retvalue :None ******************************************************************************/ void LCD_WR_REG(uint8_t data) { LCD_CS_CLR; LCD_RS_CLR; SPI2_ReadWriteByte(data); LCD_CS_SET; } /***************************************************************************** * @name :void LCD_WR_DATA(uint8_t data) * @date :2018-08-09 * @function :Write an 8-bit data to the LCD screen * @parameters :data:data value to be written * @retvalue :None ******************************************************************************/ void LCD_WR_DATA(uint8_t data) { LCD_CS_CLR; LCD_RS_SET; SPI2_ReadWriteByte(data); LCD_CS_SET; } /***************************************************************************** * @name :void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue) * @date :2018-08-09 * @function :Write data into registers * @parameters :LCD_Reg:Register address LCD_RegValue:Data to be written * @retvalue :None ******************************************************************************/ void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue) { LCD_WR_REG(LCD_Reg); LCD_WR_DATA(LCD_RegValue); } /***************************************************************************** * @name :void LCD_WriteRAM_Prepare(void) * @date :2018-08-09 * @function :Write GRAM * @parameters :None * @retvalue :None ******************************************************************************/ void LCD_WriteRAM_Prepare(void) { LCD_WR_REG(lcddev.wramcmd); } /***************************************************************************** * @name :void Lcd_WriteData_16Bit(uint16_t Data) * @date :2018-08-09 * @function :Write an 16-bit command to the LCD screen * @parameters :Data:Data to be written * @retvalue :None ******************************************************************************/ void Lcd_WriteData_16Bit(uint16_t Data) { LCD_CS_CLR; LCD_RS_SET; //SPI_WriteByte(SPI2,Data>>8); SPI2_ReadWriteByte(Data>>8); SPI2_ReadWriteByte(Data); LCD_CS_SET; } /***************************************************************************** * @name :void LCD_DrawPoint(uint16_t x,uint16_t y) * @date :2018-08-09 * @function :Write a pixel data at a specified location * @parameters :x:the x coordinate of the pixel y:the y coordinate of the pixel * @retvalue :None ******************************************************************************/ void LCD_DrawPoint(uint16_t x,uint16_t y) { LCD_SetCursor(x,y);//设置光标位置 Lcd_WriteData_16Bit(POINT_COLOR); } /***************************************************************************** * @name :void LCD_Clear(uint16_t Color) * @date :2018-08-09 * @function :Full screen filled LCD screen * @parameters :color:Filled color * @retvalue :None ******************************************************************************/ void LCD_Clear(uint16_t Color) { unsigned int i,m; LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1); LCD_CS_CLR; LCD_RS_SET; for(i=0;i