增加LCD动态翻转的函数

This commit is contained in:
不吃油炸鸡
2025-10-09 19:55:18 +08:00
parent 9527dd21ce
commit 92db314c84
4 changed files with 36 additions and 25 deletions

View File

@@ -2,6 +2,10 @@
#include "spi.h"
#include "tim.h"
uint8_t LCD_ROTATION = 0; // 0, 90, 180, 270
uint8_t OFFSET_X = 0;
uint8_t OFFSET_Y = 0;
/******************************************************************************
函数说明LCD端口初始化
入口数据:无
@@ -175,6 +179,33 @@ void LCD_ST7789_SleepOut(void)
HAL_Delay(100);
}
/******************************************************************************
函数说明:设置屏幕旋转方向
入口数据rotation 0, 90, 180, 270
返回值: 无
******************************************************************************/
void LCD_SetRotation(uint8_t rotation) {
LCD_WR_REG(0x36); // Memory Data Access Control
switch(rotation) {
case 0:
OFFSET_Y = 0;
LCD_WR_DATA8(0x00);
break;
case 180:
OFFSET_Y = 80;
LCD_WR_DATA8(0xC0);
break;
case 90:
LCD_WR_DATA8(0x70);
break;
case 270:
LCD_WR_DATA8(0xA0);
break;
default:
LCD_WR_DATA8(0x00);
break;
}
}
/******************************************************************************
函数说明LCD初始化
@@ -194,10 +225,7 @@ void LCD_Init(void)
LCD_WR_REG(0x11);
HAL_Delay(120);
LCD_WR_REG(0x36);
if(USE_HORIZONTAL==0)LCD_WR_DATA8(0x00);
else if(USE_HORIZONTAL==1)LCD_WR_DATA8(0xC0);
else if(USE_HORIZONTAL==2)LCD_WR_DATA8(0x70);
else LCD_WR_DATA8(0xA0);
LCD_SetRotation(LCD_ROTATION);
LCD_WR_REG(0x3A);
LCD_WR_DATA8(0x05);