ST7735和ST7789驱动
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LCD_H
#define __LCD_H #ifdef __cplusplus
extern "C" {
#endif /* Includes ------------------------------------------------------------------*/
#include <stdint.h> /** @addtogroup BSP
* @{
*/ /** @addtogroup Components
* @{
*/ /** @addtogroup LCD
* @{
*/ /** @defgroup LCD_Exported_Types
* @{
*/ /** @defgroup LCD_Driver_structure LCD Driver structure
* @{
*/
typedef struct
{
void (*Init)(void);
uint16_t (*ReadID)(void);
void (*DisplayOn)(void);
void (*DisplayOff)(void);
void (*SetCursor)(uint16_t, uint16_t);
void (*WritePixel)(uint16_t, uint16_t, uint16_t);
uint16_t (*ReadPixel)(uint16_t, uint16_t); /* Optimized operation */
void (*SetDisplayWindow)(uint16_t, uint16_t, uint16_t, uint16_t);
void (*DrawHLine)(uint16_t, uint16_t, uint16_t, uint16_t);
void (*DrawVLine)(uint16_t, uint16_t, uint16_t, uint16_t); uint16_t (*GetLcdPixelWidth)(void);
uint16_t (*GetLcdPixelHeight)(void);
void (*DrawBitmap)(uint16_t, uint16_t, uint8_t*);
void (*DrawRGBImage)(uint16_t, uint16_t, uint16_t, uint16_t, uint8_t*);
}LCD_DrvTypeDef;
/**
* @}
*/ /**
* @}
*/ /**
* @}
*/ /**
* @}
*/ /**
* @}
*/ #ifdef __cplusplus
}
#endif #endif /* __LCD_H */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __st7789v_H
#define __st7789v_H #ifdef __cplusplus
extern "C" {
#endif /* Includes ------------------------------------------------------------------*/
#include "lcd.h" /** @addtogroup BSP
* @{
*/ /** @addtogroup Components
* @{
*/ /** @addtogroup st7789v
* @{
*/ /** @defgroup st7789v_Exported_Types
* @{
*/ /**
* @}
*/ /** @defgroup st7789v_Exported_Constants
* @{
*/ /**
* @brief st7789v Size
*/
#define st7789v_LCD_PIXEL_WIDTH ((uint16_t)128)
#define st7789v_LCD_PIXEL_HEIGHT ((uint16_t)160) /**
* @brief LCD Lines depending on the chosen fonts.
*/
#define LCD_LINE_0 LINE(0)
#define LCD_LINE_1 LINE(1)
#define LCD_LINE_2 LINE(2)
#define LCD_LINE_3 LINE(3)
#define LCD_LINE_4 LINE(4)
#define LCD_LINE_5 LINE(5)
#define LCD_LINE_6 LINE(6)
#define LCD_LINE_7 LINE(7)
#define LCD_LINE_8 LINE(8)
#define LCD_LINE_9 LINE(9)
#define LCD_LINE_10 LINE(10)
#define LCD_LINE_11 LINE(11)
#define LCD_LINE_12 LINE(12)
#define LCD_LINE_13 LINE(13)
#define LCD_LINE_14 LINE(14)
#define LCD_LINE_15 LINE(15)
#define LCD_LINE_16 LINE(16)
#define LCD_LINE_17 LINE(17)
#define LCD_LINE_18 LINE(18)
#define LCD_LINE_19 LINE(19) /**
* @}
*/ /** @defgroup ADAFRUIT_SPI_LCD_Exported_Functions
* @{
*/
void st7789v_Init(void);
uint16_t st7789v_ReadID(void); void st7789v_DisplayOn(void);
void st7789v_DisplayOff(void);
void st7789v_SetCursor(uint16_t Xpos, uint16_t Ypos);
void st7789v_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode);
void st7789v_WriteReg(uint8_t LCDReg, uint8_t LCDRegValue);
uint8_t st7789v_ReadReg(uint8_t LCDReg); void st7789v_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
void st7789v_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length);
void st7789v_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length); uint16_t st7789v_GetLcdPixelWidth(void);
uint16_t st7789v_GetLcdPixelHeight(void);
void st7789v_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp); /* LCD driver structure */
extern LCD_DrvTypeDef st7789v_drv; /* LCD IO functions */
void LCD_IO_Init(void);
void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size);
void LCD_IO_WriteReg(uint8_t Reg);
void LCD_Delay(uint32_t delay);
/**
* @}
*/ #ifdef __cplusplus
}
#endif #endif /* __st7789v_H */ /**
* @}
*/ /**
* @}
*/ /**
* @}
*/
/* Includes ------------------------------------------------------------------*/
#include "st7789v.h" /** @addtogroup BSP
* @{
*/ /** @addtogroup Components
* @{
*/ /** @addtogroup st7789v
* @brief This file provides a set of functions needed to drive the
* st7789v LCD.
* @{
*/ /** @defgroup st7789v_Private_TypesDefinitions
* @{
*/ /**
* @}
*/ /** @defgroup st7789v_Private_Defines
* @{
*/ /**
* @}
*/ /** @defgroup st7789v_Private_Macros
* @{
*/ /**
* @}
*/ /** @defgroup st7789v_Private_Variables
* @{
*/ LCD_DrvTypeDef st7789v_drv =
{
st7789v_Init,
,
st7789v_DisplayOn,
st7789v_DisplayOff,
st7789v_SetCursor,
st7789v_WritePixel,
,
st7789v_SetDisplayWindow,
st7789v_DrawHLine,
st7789v_DrawVLine,
st7789v_GetLcdPixelWidth,
st7789v_GetLcdPixelHeight,
st7789v_DrawBitmap,
}; static uint16_t ArrayRGB[] = {}; /**
* @}
*/ /** @defgroup st7789v_Private_FunctionPrototypes
* @{
*/ /**
* @}
*/ /** @defgroup st7789v_Private_Functions
* @{
*/ /**
* @brief Writes to the selected LCD register.
* @param LCDReg: Address of the selected register.
* @param LCDRegValue: value to write to the selected register.
* @retval None
*/
void st7789v_WriteReg(uint8_t LCDReg, uint8_t LCDRegValue)
{
LCD_IO_WriteReg(LCDReg);
LCD_IO_WriteMultipleData(&LCDRegValue, );
} /**
* @brief Initialize the st7789v LCD Component.
* @param None
* @retval None
*/
void st7789v_Init(void)
{ /* Initialize st7789v low level bus layer -----------------------------------*/
LCD_IO_Init();
/* Out of sleep mode, 0 args, no delay */
st7789v_WriteReg(0x11, 0x00);
/**/ st7789v_WriteReg(0x36, 0x00); st7789v_WriteReg(0x3A, 0x06); st7789v_WriteReg(0xB2, 0x0C);
st7789v_WriteReg(0xB2, 0x0C);
st7789v_WriteReg(0xB2, 0x00);
st7789v_WriteReg(0xB2, 0x33);
st7789v_WriteReg(0xB2, 0x33); st7789v_WriteReg(0xB7, 0x35); //VGH=13.26V, VGL=-10.43V st7789v_WriteReg(0xBB, 0x38); //VCOM st7789v_WriteReg(0xC0, 0x2C); st7789v_WriteReg(0xC2, 0x01); st7789v_WriteReg(0xC3, 0x1A); //VAP //5V st7789v_WriteReg(0xC4, 0x20); st7789v_WriteReg(0xC6, 0x0F); st7789v_WriteReg(0xD0, 0xA4);
st7789v_WriteReg(0xD0, 0xA1); st7789v_WriteReg(0xE0 , 0xD0);
st7789v_WriteReg(0xE0, 0x1E);
st7789v_WriteReg(0xE0, 0x24);
st7789v_WriteReg(0xE0, 0x0A);
st7789v_WriteReg(0xE0 , 0x0A);
st7789v_WriteReg(0xE0 , 0x26);
st7789v_WriteReg(0xE0, 0x44);
st7789v_WriteReg(0xE0, 0x44);
st7789v_WriteReg(0xE0, 0x57);
st7789v_WriteReg(0xE0, 0x29);
st7789v_WriteReg(0xE0 , 0x14);
st7789v_WriteReg(0xE0, 0x14);
st7789v_WriteReg(0xE0 , 0x30);
st7789v_WriteReg(0xE0 , 0x34); st7789v_WriteReg(0xE1, 0xD0);
st7789v_WriteReg(0xE1 , 0x1E);
st7789v_WriteReg(0xE1, 0x23);
st7789v_WriteReg(0xE1 , 0x0A);
st7789v_WriteReg(0xE1, 0x09);
st7789v_WriteReg(0xE1, 0x25);
st7789v_WriteReg(0xE1 , 0x43);
st7789v_WriteReg(0xE1, 0x33);
st7789v_WriteReg(0xE1, 0x56);
st7789v_WriteReg(0xE1 , 0x28);
st7789v_WriteReg(0xE1 , 0x14);
st7789v_WriteReg(0xE1, 0x14);
st7789v_WriteReg(0xE1, 0x2F);
st7789v_WriteReg(0xE1 , 0x34); st7789v_WriteReg(0x29,0x00); st7789v_WriteReg(0x21, 0x00); st7789v_WriteReg(0x2A, 0x00);
st7789v_WriteReg(0x2A , 0x00);
st7789v_WriteReg(0x2A , 0x00);
st7789v_WriteReg(0x2A , 0xEF); st7789v_WriteReg(0x2B, 0x00);
st7789v_WriteReg(0x2B , 0x00);
st7789v_WriteReg(0x2B , 0x00);
st7789v_WriteReg(0x2B , 0xEF);
} /**
* @brief Enables the Display.
* @param None
* @retval None
*/
void st7789v_DisplayOn(void)
{
uint8_t data = ;
LCD_IO_WriteReg(0x13);/* Partial off (Normal): NORON */
LCD_Delay();
LCD_IO_WriteReg(0x29);/* Display on: DISPON */
LCD_Delay();
LCD_IO_WriteReg(0x36);/* Memory data access control: MADCTL */
data = 0xC0;
LCD_IO_WriteMultipleData(&data, );
} /**
* @brief Disables the Display.
* @param None
* @retval None
*/
void st7789v_DisplayOff(void)
{
uint8_t data = ;
LCD_IO_WriteReg(0x13);/* Partial off (Normal): NORON */
LCD_Delay();
LCD_IO_WriteReg(0x28);/* Display off: DISPOFF */
LCD_Delay();
LCD_IO_WriteReg(0x36);/* Memory data access control: MADCTL */
data = 0xC0;
LCD_IO_WriteMultipleData(&data, );
} /**
* @brief Sets Cursor position.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @retval None
*/
void st7789v_SetCursor(uint16_t Xpos, uint16_t Ypos)
{
uint8_t data = ;
LCD_IO_WriteReg(0x2A);/* Column address set: CASET */
data = (Xpos) >> ;
LCD_IO_WriteMultipleData(&data, );
data = (Xpos) & 0xFF;
LCD_IO_WriteMultipleData(&data, );
LCD_IO_WriteReg(0x2B);/* Row address set: RASET */
data = (Ypos) >> ;
LCD_IO_WriteMultipleData(&data, );
data = (Ypos) & 0xFF;
LCD_IO_WriteMultipleData(&data, );
LCD_IO_WriteReg(0x2C);/* Memory write: RAMWR */
} /**
* @brief Writes pixel.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param RGBCode: the RGB pixel color
* @retval None
*/
void st7789v_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode)
{
uint8_t data = ;
if((Xpos >= st7789v_LCD_PIXEL_WIDTH) || (Ypos >= st7789v_LCD_PIXEL_HEIGHT))
{
return;
} /* Set Cursor */
st7789v_SetCursor(Xpos, Ypos); data = RGBCode >> ;
LCD_IO_WriteMultipleData(&data, );
data = RGBCode;
LCD_IO_WriteMultipleData(&data, );
} /**
* @brief Sets a display window
* @param Xpos: specifies the X bottom left position.
* @param Ypos: specifies the Y bottom left position.
* @param Height: display window height.
* @param Width: display window width.
* @retval None
*/
void st7789v_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
{
uint8_t data = ;
/* Column addr set, 4 args, no delay: XSTART = Xpos, XEND = (Xpos + Width - 1) */
LCD_IO_WriteReg(0x2A);/* Column address set: CASET */
data = (Xpos) >> ;
LCD_IO_WriteMultipleData(&data, );
data = (Xpos) & 0xFF;
LCD_IO_WriteMultipleData(&data, );
data = (Xpos + Width - ) >> ;
LCD_IO_WriteMultipleData(&data, );
data = (Xpos + Width - ) & 0xFF;
LCD_IO_WriteMultipleData(&data, );
/* Row addr set, 4 args, no delay: YSTART = Ypos, YEND = (Ypos + Height - 1) */
LCD_IO_WriteReg(0x2B);/* Row address set: RASET */
data = (Ypos) >> ;
LCD_IO_WriteMultipleData(&data, );
data = (Ypos) & 0xFF;
LCD_IO_WriteMultipleData(&data, );
data = (Ypos + Height - ) >> ;
LCD_IO_WriteMultipleData(&data, );
data = (Ypos + Height - ) & 0xFF;
LCD_IO_WriteMultipleData(&data, );
} /**
* @brief Draws horizontal line.
* @param RGBCode: Specifies the RGB color
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: specifies the line length.
* @retval None
*/
void st7789v_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint8_t counter = ; if(Xpos + Length > st7789v_LCD_PIXEL_WIDTH) return; /* Set Cursor */
st7789v_SetCursor(Xpos, Ypos); for(counter = ; counter < Length; counter++)
{
ArrayRGB[counter] = RGBCode;
}
LCD_IO_WriteMultipleData((uint8_t*)&ArrayRGB[], Length * );
} /**
* @brief Draws vertical line.
* @param RGBCode: Specifies the RGB color
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: specifies the line length.
* @retval None
*/
void st7789v_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint8_t counter = ; if(Ypos + Length > st7789v_LCD_PIXEL_HEIGHT) return;
for(counter = ; counter < Length; counter++)
{
st7789v_WritePixel(Xpos, Ypos + counter, RGBCode);
}
} /**
* @brief Gets the LCD pixel Width.
* @param None
* @retval The Lcd Pixel Width
*/
uint16_t st7789v_GetLcdPixelWidth(void)
{
return st7789v_LCD_PIXEL_WIDTH;
} /**
* @brief Gets the LCD pixel Height.
* @param None
* @retval The Lcd Pixel Height
*/
uint16_t st7789v_GetLcdPixelHeight(void)
{
return st7789v_LCD_PIXEL_HEIGHT;
} /**
* @brief Displays a bitmap picture loaded in the internal Flash.
* @param BmpAddress: Bmp picture address in the internal Flash.
* @retval None
*/
void st7789v_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp)
{
uint32_t index = , size = ; /* Read bitmap size */
size = *(volatile uint16_t *) (pbmp + );
size |= (*(volatile uint16_t *) (pbmp + )) << ;
/* Get bitmap data address offset */
index = *(volatile uint16_t *) (pbmp + );
index |= (*(volatile uint16_t *) (pbmp + )) << ;
size = (size - index)/;
pbmp += index; /* Set GRAM write direction and BGR = 0 */
/* Memory access control: MY = 0, MX = 1, MV = 0, ML = 0 */
st7789v_WriteReg(0x36, 0x40);// LCD_REG_54 0x36 /* Memory data access control: MADCTL */ /* Set Cursor */
st7789v_SetCursor(Xpos, Ypos); LCD_IO_WriteMultipleData((uint8_t*)pbmp, size*); /* Set GRAM write direction and BGR = 0 */
/* Memory access control: MY = 1, MX = 1, MV = 0, ML = 0 */
st7789v_WriteReg(0x36, 0xC0);/* Memory data access control: MADCTL */
} /**
* @}
*/ /**
* @}
*/ /**
* @}
*/ /**
* @}
*/
/* Includes ------------------------------------------------------------------*/
#include "st7735.h" /** @addtogroup BSP
* @{
*/ /** @addtogroup Components
* @{
*/ /** @addtogroup ST7735
* @brief This file provides a set of functions needed to drive the
* ST7735 LCD.
* @{
*/ /** @defgroup ST7735_Private_TypesDefinitions
* @{
*/ /**
* @}
*/ /** @defgroup ST7735_Private_Defines
* @{
*/ /**
* @}
*/ /** @defgroup ST7735_Private_Macros
* @{
*/ /**
* @}
*/ /** @defgroup ST7735_Private_Variables
* @{
*/ LCD_DrvTypeDef st7735_drv =
{
st7735_Init,
,
st7735_DisplayOn,
st7735_DisplayOff,
st7735_SetCursor,
st7735_WritePixel,
,
st7735_SetDisplayWindow,
st7735_DrawHLine,
st7735_DrawVLine,
st7735_GetLcdPixelWidth,
st7735_GetLcdPixelHeight,
st7735_DrawBitmap,
}; static uint16_t ArrayRGB[] = {}; /**
* @}
*/ /** @defgroup ST7735_Private_FunctionPrototypes
* @{
*/ /**
* @}
*/ /** @defgroup ST7735_Private_Functions
* @{
*/ /**
* @brief Initialize the ST7735 LCD Component.
* @param None
* @retval None
*/
void st7735_Init(void)
{ /* Initialize ST7735 low level bus layer -----------------------------------*/
LCD_IO_Init(); LCD_HW_RESET(); /* Out of sleep mode*/
LCD_IO_WriteReg(0x11);
LCD_Delay();//120ms
/* Frame rate ctrl - normal mode, 3 args:Rate = fosc/(1x2+40) * (LINE+2C+2D)*/
LCD_IO_WriteReg(0xB1);
LCD_IO_WriteData(0x01);
LCD_IO_WriteData(0x2C);
LCD_IO_WriteData(0x2D);
/* Frame rate control - idle mode, 3 args:Rate = fosc/(1x2+40) * (LINE+2C+2D) */
LCD_IO_WriteReg(0xB2);
LCD_IO_WriteData(0x01);
LCD_IO_WriteData(0x2C);
LCD_IO_WriteData(0x2D);
/* Frame rate ctrl - partial mode, 6 args: Dot inversion mode, Line inversion mode */
LCD_IO_WriteReg(0xB3);
LCD_IO_WriteData(0x01);
LCD_IO_WriteData(0x2C);
LCD_IO_WriteData(0x2D);
LCD_IO_WriteData(0x01);
LCD_IO_WriteData(0x2C);
LCD_IO_WriteData(0x2D);
/* Display inversion ctrl, 1 arg, no delay: No inversion */
st7735_WriteReg(0xB4, 0x07);
/* Power control, 3 args, no delay: -4.6V , AUTO mode */
LCD_IO_WriteReg(0xC0);
LCD_IO_WriteData(0xA2);
LCD_IO_WriteData(0x02);
LCD_IO_WriteData(0x84);
/* Power control, 1 arg, no delay: VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD */
st7735_WriteReg(0xC1, 0xC5);
/* Power control, 2 args, no delay: Opamp current small, Boost frequency */
LCD_IO_WriteReg(0xC2);
LCD_IO_WriteData(0x0A);
LCD_IO_WriteData(0x00);
/* Power control, 2 args, no delay: BCLK/2, Opamp current small & Medium low */
LCD_IO_WriteReg(0xC3);
LCD_IO_WriteData(0x8A);
LCD_IO_WriteData(0x2A);
/* Power control, 2 args, no delay */
LCD_IO_WriteReg(0xC4);
LCD_IO_WriteData(0x8A);
LCD_IO_WriteData(0xEE);
/* Power control, 1 arg, no delay */
st7735_WriteReg(0xC5, 0x0E);
/* Don't invert display, no args, no delay */
LCD_IO_WriteReg(0x20);
/* Set color mode, 1 arg, no delay: 16-bit color */
st7735_WriteReg(0x3A, 0x05);
/* Column addr set, 4 args, no delay: XSTART = 0, XEND = 127 */
LCD_IO_WriteReg(0x2A);
LCD_IO_WriteData(0x00);
LCD_IO_WriteData(0x00);
LCD_IO_WriteData(0x00);
LCD_IO_WriteData(0x7F); /* Row addr set, 4 args, no delay: YSTART = 0, YEND = 159 */
LCD_IO_WriteReg(0x2B);
LCD_IO_WriteData(0x00);
LCD_IO_WriteData(0x00);
LCD_IO_WriteData(0x00);
LCD_IO_WriteData(0x9F); /* Magical unicorn dust, 16 args, no delay */
LCD_IO_WriteReg(0xE0);
LCD_IO_WriteData(0x02);
LCD_IO_WriteData(0x1c);
LCD_IO_WriteData(0x07);
LCD_IO_WriteData(0x12);
LCD_IO_WriteData(0x37);
LCD_IO_WriteData(0x32);
LCD_IO_WriteData(0x29);
LCD_IO_WriteData(0x2d);
LCD_IO_WriteData(0x29);
LCD_IO_WriteData(0x25);
LCD_IO_WriteData(0x2B);
LCD_IO_WriteData(0x39);
LCD_IO_WriteData(0x00);
LCD_IO_WriteData(0x01);
LCD_IO_WriteData(0x03);
LCD_IO_WriteData(0x10);
/* Sparkles and rainbows, 16 args, no delay */
LCD_IO_WriteReg(0xE0);
LCD_IO_WriteData(0x03);
LCD_IO_WriteData(0x1d);
LCD_IO_WriteData(0x07);
LCD_IO_WriteData(0x06);
LCD_IO_WriteData(0x2E);
LCD_IO_WriteData(0x2C);
LCD_IO_WriteData(0x29);
LCD_IO_WriteData(0x2D);
LCD_IO_WriteData(0x2E);
LCD_IO_WriteData(0x2E);
LCD_IO_WriteData(0x37);
LCD_IO_WriteData(0x3F);
LCD_IO_WriteData(0x00);
LCD_IO_WriteData(0x00);
LCD_IO_WriteData(0x02);
LCD_IO_WriteData(0x10);
/* Normal display on, no args, no delay */
st7735_WriteReg(0x13, 0x00);
/* Main screen turn on, no delay */
st7735_WriteReg(0x29, 0x00);
/* Memory access control: MY = 1, MX = 1, MV = 0, ML = 0 */
st7735_WriteReg(0x36, 0xC0);
} /**
* @brief Enables the Display.
* @param None
* @retval None
*/
void st7735_DisplayOn(void)
{
LCD_IO_WriteReg(0x13);
LCD_Delay();
LCD_IO_WriteReg(0x29);
LCD_Delay();
LCD_IO_WriteReg(0x36);
LCD_IO_WriteData(0xC0);
} /**
* @brief Disables the Display.
* @param None
* @retval None
*/
void st7735_DisplayOff(void)
{
LCD_IO_WriteReg(0x13);
LCD_Delay();
LCD_IO_WriteReg(0x28);
LCD_Delay();
LCD_IO_WriteReg(0x36);
LCD_IO_WriteData(0xC0);
} /**
* @brief Sets Cursor position.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @retval None
*/
void st7735_SetCursor(uint16_t Xpos, uint16_t Ypos)
{
LCD_IO_WriteReg(0x2A);
LCD_IO_WriteData((Xpos) >> );
LCD_IO_WriteData((Xpos) & 0xFF);
LCD_IO_WriteReg(0x2B);
LCD_IO_WriteData((Ypos) >> );
LCD_IO_WriteData((Ypos) & 0xFF);
LCD_IO_WriteReg(0x2C);
} /**
* @brief Writes pixel.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param RGBCode: the RGB pixel color
* @retval None
*/
void st7735_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode)
{ if((Xpos >= ST7735_LCD_PIXEL_WIDTH) || (Ypos >= ST7735_LCD_PIXEL_HEIGHT))
{
return;
} /* Set Cursor */
st7735_SetCursor(Xpos, Ypos);
LCD_IO_WriteData(RGBCode >> );
LCD_IO_WriteData(RGBCode); } /**
* @brief Writes to the selected LCD register.
* @param LCDReg: Address of the selected register.
* @param LCDRegValue: value to write to the selected register.
* @retval None
*/
void st7735_WriteReg(uint8_t LCDReg, uint8_t LCDRegValue)
{
LCD_IO_WriteReg(LCDReg);
LCD_IO_WriteData(LCDRegValue);
} /**
* @brief Sets a display window
* @param Xpos: specifies the X bottom left position.
* @param Ypos: specifies the Y bottom left position.
* @param Height: display window height.
* @param Width: display window width.
* @retval None
*/
void st7735_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
{ /* Column addr set, 4 args, no delay: XSTART = Xpos, XEND = (Xpos + Width - 1) */
LCD_IO_WriteReg(0x2A);
LCD_IO_WriteData((Xpos) >> );
LCD_IO_WriteData((Xpos) & 0xFF);
LCD_IO_WriteData((Xpos + Width - ) >> );
LCD_IO_WriteData((Xpos + Width - ) & 0xFF);
/* Row addr set, 4 args, no delay: YSTART = Ypos, YEND = (Ypos + Height - 1) */
LCD_IO_WriteReg(0x2B);
LCD_IO_WriteData((Ypos) >> );
LCD_IO_WriteData((Ypos) & 0xFF );
LCD_IO_WriteData((Ypos + Height - ) >> );
LCD_IO_WriteData((Ypos + Height - ) & 0xFF );
} /**
* @brief Draws horizontal line.
* @param RGBCode: Specifies the RGB color
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: specifies the line length.
* @retval None
*/
void st7735_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint8_t counter = ; if(Xpos + Length > ST7735_LCD_PIXEL_WIDTH) return; /* Set Cursor */
st7735_SetCursor(Xpos, Ypos); for(counter = ; counter < Length; counter++)
{
ArrayRGB[counter] = RGBCode;
}
LCD_IO_WriteMultipleData((uint8_t*)&ArrayRGB[], Length * );
} /**
* @brief Draws vertical line.
* @param RGBCode: Specifies the RGB color
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: specifies the line length.
* @retval None
*/
void st7735_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint8_t counter = ; if(Ypos + Length > ST7735_LCD_PIXEL_HEIGHT) return;
for(counter = ; counter < Length; counter++)
{
st7735_WritePixel(Xpos, Ypos + counter, RGBCode);
}
} /**
* @brief Gets the LCD pixel Width.
* @param None
* @retval The Lcd Pixel Width
*/
uint16_t st7735_GetLcdPixelWidth(void)
{
return ST7735_LCD_PIXEL_WIDTH;
} /**
* @brief Gets the LCD pixel Height.
* @param None
* @retval The Lcd Pixel Height
*/
uint16_t st7735_GetLcdPixelHeight(void)
{
return ST7735_LCD_PIXEL_HEIGHT;
} /**
* @brief Displays a bitmap picture loaded in the internal Flash.
* @param BmpAddress: Bmp picture address in the internal Flash.
* @retval None
*/
void st7735_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp)
{
uint32_t index = , size = ; /* Read bitmap size */
size = *(volatile uint16_t *) (pbmp + );
size |= (*(volatile uint16_t *) (pbmp + )) << ;
/* Get bitmap data address offset */
index = *(volatile uint16_t *) (pbmp + );
index |= (*(volatile uint16_t *) (pbmp + )) << ;
size = (size - index)/;
pbmp += index; /* Set GRAM write direction and BGR = 0 */
/* Memory access control: MY = 0, MX = 1, MV = 0, ML = 0 */
st7735_WriteReg(0x36, 0x40); /* Set Cursor */
st7735_SetCursor(Xpos, Ypos); LCD_IO_WriteMultipleData((uint8_t*)pbmp, size*); /* Set GRAM write direction and BGR = 0 */
/* Memory access control: MY = 1, MX = 1, MV = 0, ML = 0 */
st7735_WriteReg(0x36, 0xC0);
}
#ifndef __ST7735_H
#define __ST7735_H #ifdef __cplusplus
extern "C" {
#endif /* Includes ------------------------------------------------------------------*/
#include "../Common/lcd.h"
#include "stm32f1xx_board.h"
/** @addtogroup BSP
* @{
*/ /** @addtogroup Components
* @{
*/ /** @addtogroup ST7735
* @{
*/ /** @defgroup ST7735_Exported_Types
* @{
*/ /**
* @}
*/ /** @defgroup ST7735_Exported_Constants
* @{
*/ /**
* @brief ST7735 Size
*/
#define ST7735_LCD_PIXEL_WIDTH ((uint16_t)128)
#define ST7735_LCD_PIXEL_HEIGHT ((uint16_t)160) /**
* @brief LCD Lines depending on the chosen fonts.
*/
#define LCD_LINE_0 LINE(0)
#define LCD_LINE_1 LINE(1)
#define LCD_LINE_2 LINE(2)
#define LCD_LINE_3 LINE(3)
#define LCD_LINE_4 LINE(4)
#define LCD_LINE_5 LINE(5)
#define LCD_LINE_6 LINE(6)
#define LCD_LINE_7 LINE(7)
#define LCD_LINE_8 LINE(8)
#define LCD_LINE_9 LINE(9)
#define LCD_LINE_10 LINE(10)
#define LCD_LINE_11 LINE(11)
#define LCD_LINE_12 LINE(12)
#define LCD_LINE_13 LINE(13)
#define LCD_LINE_14 LINE(14)
#define LCD_LINE_15 LINE(15)
#define LCD_LINE_16 LINE(16)
#define LCD_LINE_17 LINE(17)
#define LCD_LINE_18 LINE(18)
#define LCD_LINE_19 LINE(19) /**
* @}
*/ /** @defgroup ADAFRUIT_SPI_LCD_Exported_Functions
* @{
*/
void st7735_Init(void);
uint16_t st7735_ReadID(void); void st7735_DisplayOn(void);
void st7735_DisplayOff(void);
void st7735_SetCursor(uint16_t Xpos, uint16_t Ypos);
void st7735_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode);
void st7735_WriteReg(uint8_t LCDReg, uint8_t LCDRegValue);
uint8_t st7735_ReadReg(uint8_t LCDReg); void st7735_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
void st7735_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length);
void st7735_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length); uint16_t st7735_GetLcdPixelWidth(void);
uint16_t st7735_GetLcdPixelHeight(void);
void st7735_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp); /* LCD driver structure */
extern LCD_DrvTypeDef st7735_drv; /**
* @}
*/ #ifdef __cplusplus
}
#endif #endif /* __ST7735_H */
ST7735和ST7789驱动的更多相关文章
- TFT ST7735的Netduino驱动
好久没写关于netduino的文章了,工作忙是一方面,主要原因还是因为没解决TFT显示的问题,功夫不负有心人,在经过多轮研究后,总算在今天2013年12月15日的晚上9点解决了. 下面先介绍一下我所用 ...
- 联盛德 HLK-W806 (四): 软件SPI和硬件SPI驱动ST7735液晶LCD
目录 联盛德 HLK-W806 (一): Ubuntu20.04下的开发环境配置, 编译和烧录说明 联盛德 HLK-W806 (二): Win10下的开发环境配置, 编译和烧录说明 联盛德 HLK-W ...
- 联盛德 HLK-W806 (九): 软件SPI和硬件SPI驱动ST7789V液晶LCD
目录 联盛德 HLK-W806 (一): Ubuntu20.04下的开发环境配置, 编译和烧录说明 联盛德 HLK-W806 (二): Win10下的开发环境配置, 编译和烧录说明 联盛德 HLK-W ...
- esp8266驱动液晶屏
ESP8266 + 1.44 TFT LCD https://www.joaquim.org/esp8266-wifi-scan/ LCD ILI9341 (320×240). Source Code ...
- 使用Arduino驱动基于ST7533芯片的TFT屏
在合宙通信买了一个1.8寸的TFT屏,驱动芯片是ST7533,本来打算使用Air800直接驱动,但由于其他原因,放弃了.于是尝试使用arduino驱动,为了屏幕刷新速度更快,采用硬件SPI. 硬件连接 ...
- 基于STM32F429的TFT0.96屏幕驱动
1.介绍TFT 2.Cube配置 该屏幕是用SPI通信的,但没有MISO引脚,意思是说该屏幕只能接收数据,但无法读取里面的数据,理论上说四线就能启动,但我弄不出,只能用六线. 在Cube上只要开启六 ...
- STM32驱动LCD实战
前段时间写了<STM32驱动LCD原理>和<STM32的FSMC外设简介>两篇文章,本文将对STM32驱动LCD进行实战应用.LCD是深圳市拓普微科技开发有限公司的LMT028 ...
- 联盛德 HLK-W806 (六): I2C驱动SSD1306 128x64 OLED液晶屏
目录 联盛德 HLK-W806 (一): Ubuntu20.04下的开发环境配置, 编译和烧录说明 联盛德 HLK-W806 (二): Win10下的开发环境配置, 编译和烧录说明 联盛德 HLK-W ...
- 联盛德 HLK-W806 (八): 4线SPI驱动SSD1306/SSD1315 128x64 OLED液晶屏
目录 联盛德 HLK-W806 (一): Ubuntu20.04下的开发环境配置, 编译和烧录说明 联盛德 HLK-W806 (二): Win10下的开发环境配置, 编译和烧录说明 联盛德 HLK-W ...
随机推荐
- 快速排序和二分查找(Go)
package main import ( "fmt" "sync") var waitGroup sync.WaitGroup func main() { d ...
- 题目1.A乘以B
看我没骗你吧 —— 这是一道你可以在10秒内完成的题:给定两个绝对值不超过100的整数A和B,输出A乘以B的值. 1实验代码 #include<stdio.h>int main(void) ...
- 多网卡情况下接收udp组播
多网卡下接收udp组播 往往会接收失败 因为用错了网卡 例如我想要接收2网段 其他电脑出的udp组播 我电脑有有线网和wifi在window下可以这样 route add 230.0.0.1 mas ...
- 如何进行EDM邮件内容的撰写
近两个月没有来博客园更新一下博客文章了,实在惭愧,最近忙于工作,经常加班.下面来说说EDM邮件内容的撰写技巧吧,本文就跟大家交流一下自己一直以来的心得体会. EDM中很重要的一个步骤,就是邮件内容的撰 ...
- C# AxWindowsMediaPlayer
AxWMPLib.AxWindowsMediaPlayer winPlayer = new AxWMPLib.AxWindowsMediaPlayer(); winPlayer.Dock = Dock ...
- Linux 下创建静态库和动态库
1.创建静态链接库 2.创建动态链接库
- 虚拟化 RemoteApp 远程接入 源码 免费
远程接入 RemoteApp 虚拟化 源码 免费 1.终端安装与配置: 此远程接入组件的运行原理与瑞友天翼.异速连.CTBS等市面上常见的远程接入产品一样,是透过Windows的终端服务来实现的,速度 ...
- js 中 json.stringfy()将对象、数组转换成字符串
json.stringfy()将对象.数组转换成字符串 var student = new Object(); student.name = "Lanny"; student.ag ...
- Express中间件body-parser
在http请求种,POST.PUT.PATCH三种请求方法中包含着请求体,也就是所谓的request,在Nodejs原生的http模块中,请求体是要基于流的方式来接受和解析. body-parser是 ...
- Tomcat进程、SFTP服务器
查看Tomcat是否以关闭 ps -ef|grep tomcat port sftp -oPort=60001 root@192.168.0.254