From 92db314c8492f816724c2dd00d27fc10c872e895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=90=83=E6=B2=B9=E7=82=B8=E9=B8=A1?= <1425962791@qq.com> Date: Thu, 9 Oct 2025 19:55:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0LCD=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E7=BF=BB=E8=BD=AC=E7=9A=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Power_Pico/BSP/LCD/lcd.c | 11 ----------- Power_Pico/BSP/LCD/lcd_init.c | 36 +++++++++++++++++++++++++++++++---- Power_Pico/BSP/LCD/lcd_init.h | 12 +++--------- Power_Pico/Core/Src/main.c | 2 +- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/Power_Pico/BSP/LCD/lcd.c b/Power_Pico/BSP/LCD/lcd.c index d2b4426..fd528d7 100644 --- a/Power_Pico/BSP/LCD/lcd.c +++ b/Power_Pico/BSP/LCD/lcd.c @@ -4,17 +4,6 @@ #include "spi.h" #include "cmsis_os.h" -#if USE_HORIZONTAL == 0 - #define OFFSET_Y 0 - #define OFFSET_X 0 -#elif USE_HORIZONTAL == 1 - #define OFFSET_Y 80 - #define OFFSET_X 0 -#else - #define OFFSET_Y 0 - #define OFFSET_X 0 -#endif - extern osSemaphoreId_t DMA_SemaphoreHandle; /****************************************************************************** 函数说明:在指定区域填充颜色 diff --git a/Power_Pico/BSP/LCD/lcd_init.c b/Power_Pico/BSP/LCD/lcd_init.c index fad125a..e914f76 100644 --- a/Power_Pico/BSP/LCD/lcd_init.c +++ b/Power_Pico/BSP/LCD/lcd_init.c @@ -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); diff --git a/Power_Pico/BSP/LCD/lcd_init.h b/Power_Pico/BSP/LCD/lcd_init.h index 047ed6c..88117bc 100644 --- a/Power_Pico/BSP/LCD/lcd_init.h +++ b/Power_Pico/BSP/LCD/lcd_init.h @@ -3,19 +3,13 @@ #include "sys.h" -#define USE_HORIZONTAL 1 //ÉèÖúáÆÁ»òÕßÊúÆÁÏÔʾ 0»ò1ΪÊúÆÁ 2»ò3ΪºáÆÁ +extern uint8_t LCD_ROTATION; +extern uint8_t OFFSET_X; +extern uint8_t OFFSET_Y; - -#if USE_HORIZONTAL==0||USE_HORIZONTAL==1 #define LCD_W 240 #define LCD_H 240 -#else -#define LCD_W 240 -#define LCD_H 240 -#endif - - //-----------------LCD¶Ë¿Ú¶¨Òå---------------- #define SCLK_PORT GPIOB #define SCLK_PIN GPIO_PIN_13 diff --git a/Power_Pico/Core/Src/main.c b/Power_Pico/Core/Src/main.c index b6f0bde..8912c73 100644 --- a/Power_Pico/Core/Src/main.c +++ b/Power_Pico/Core/Src/main.c @@ -75,7 +75,7 @@ int main(void) /* USER CODE BEGIN 1 */ //this must set same as keil setting - SCB->VTOR = 0x00000000U; + SCB->VTOR = FLASH_BASE + 0x00000000; /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/