旋转编码器控制LED明暗,按钮控制电机转速

This commit is contained in:
james 2024-11-07 21:23:17 +08:00
parent b6a0e98611
commit 7908b65803
35 changed files with 5135 additions and 4994 deletions

View File

@ -1,2 +1,5 @@
#define KEY_PRESSED GPIO_PIN_RESET
#define KEY_NOT_PRESSED GPIO_PIN_SET
//WK_UP 是高电平有效,其他三个按键是低电平有效。
#define KEY_UP_PRESSED GPIO_PIN_SET
#define KEY_UP_NOT_PRESSED GPIO_PIN_RESET

View File

@ -57,6 +57,10 @@ void Error_Handler(void);
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
#define KEY_UP_Pin GPIO_PIN_13
#define KEY_UP_GPIO_Port GPIOC
#define BIN1_Pin GPIO_PIN_4
#define BIN1_GPIO_Port GPIOA
#define BEEP_Pin GPIO_PIN_2
#define BEEP_GPIO_Port GPIOB
#define LED_R_Pin GPIO_PIN_7
@ -65,14 +69,18 @@ void Error_Handler(void);
#define LED_G_GPIO_Port GPIOE
#define LED_B_Pin GPIO_PIN_9
#define LED_B_GPIO_Port GPIOE
#define BIN2_Pin GPIO_PIN_11
#define BIN2_GPIO_Port GPIOB
#define PWMB_Pin GPIO_PIN_13
#define PWMB_GPIO_Port GPIOB
#define SERVO_Pin GPIO_PIN_15
#define SERVO_GPIO_Port GPIOB
#define KEY0_Pin GPIO_PIN_8
#define KEY0_GPIO_Port GPIOD
#define KEY1_Pin GPIO_PIN_9
#define KEY1_GPIO_Port GPIOD
#define KEY2_Pin GPIO_PIN_10
#define KEY2_GPIO_Port GPIOD
#define KEY_LEFT_Pin GPIO_PIN_8
#define KEY_LEFT_GPIO_Port GPIOD
#define KEY_DOWN_Pin GPIO_PIN_9
#define KEY_DOWN_GPIO_Port GPIOD
#define KEY_RIGHT_Pin GPIO_PIN_10
#define KEY_RIGHT_GPIO_Port GPIOD
#define PB8_EXTI_Pin GPIO_PIN_8
#define PB8_EXTI_GPIO_Port GPIOB
#define PB8_EXTI_EXTI_IRQn EXTI9_5_IRQn

View File

@ -1,6 +1,6 @@
#include "main.h"
//Tanslate angle into Capture Compare Register value
#define ANGLETOCCR(angle) 2000 * (angle) / 180 + 500
#define ANGLETOCCR(angle) (2000 * (angle) / 180 + 500)
extern int16_t Servo_Speed,Servo_goal,Servo_position;

View File

@ -49,7 +49,7 @@ void MX_TIM15_Init(void);
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
/* USER CODE BEGIN Prototypes */
int NewCCRValue(int now_ccr,int plus,int maxvalue);
/* USER CODE END Prototypes */
#ifdef __cplusplus

Binary file not shown.

View File

@ -27,12 +27,12 @@ Project File Date: 11/07/2024
<h2>Output:</h2>
*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'D:\Keil5\ARM\ARMCC\Bin'
Build target 'Project'
compiling servo.c...
..\Src\servo.c(25): warning: #177-D: variable "tt" was declared but never referenced
static uint8_t times = 0, tt = 0;
..\Src\servo.c: 1 warning, 0 errors
compiling main.c...
../Src/main.c(86): warning: #177-D: variable "ADC_Value" was declared but never referenced
uint32_t ADC_Value;
../Src/main.c: 1 warning, 0 errors
linking...
Program Size: Code=18972 RO-data=59236 RW-data=40 ZI-data=2896
Program Size: Code=19496 RO-data=59236 RW-data=44 ZI-data=2892
FromELF: creating hex file...
"Project\Project.axf" - 0 Error(s), 1 Warning(s).

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
Dependencies for Project 'Project', Target 'Project': (DO NOT MODIFY !)
F (startup_stm32l475xx.s)(0x672C6B22)(--cpu Cortex-M4.fp -g --apcs=interwork --pd "__MICROLIB SETA 1" -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include --pd "__UVISION_VERSION SETA 514" --pd "_RTE_ SETA 1" --pd "STM32L475xx SETA 1" --list startup_stm32l475xx.lst --xref -o project\startup_stm32l475xx.o --depend project\startup_stm32l475xx.d)
F (startup_stm32l475xx.s)(0x672CB687)(--cpu Cortex-M4.fp -g --apcs=interwork --pd "__MICROLIB SETA 1" -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include --pd "__UVISION_VERSION SETA 514" --pd "_RTE_ SETA 1" --pd "STM32L475xx SETA 1" --list startup_stm32l475xx.lst --xref -o project\startup_stm32l475xx.o --depend project\startup_stm32l475xx.d)
F (..\Src\lcd.c)(0x672794C0)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\lcd.o --omf_browse project\lcd.crf --depend project\lcd.d)
I (../Inc/sys.h)(0x67279973)
I (../Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l4xx.h)(0x671507AF)
@ -116,8 +116,8 @@ I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim_ex.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h)(0x671507AF)
F (../Src/main.c)(0x672C77C1)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\main.o --omf_browse project\main.crf --depend project\main.d)
I (../Inc/main.h)(0x672C6B20)
F (../Src/main.c)(0x672CBCC5)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\main.o --omf_browse project\main.crf --depend project\main.d)
I (../Inc/main.h)(0x672CB685)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h)(0x671507AF)
I (../Inc/stm32l4xx_hal_conf.h)(0x67299DDD)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc.h)(0x671507AF)
@ -155,18 +155,18 @@ I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h)(0x671507AF)
I (../Inc/adc.h)(0x67284CF2)
I (../Inc/spi.h)(0x67279574)
I (../Inc/tim.h)(0x672C524A)
I (../Inc/tim.h)(0x672CB995)
I (../Inc/usart.h)(0x67276B93)
I (../Inc/gpio.h)(0x6715E327)
I (../Inc/lcd.h)(0x5BF21D0E)
I (../Inc/sys.h)(0x67279973)
I (D:\Keil5\ARM\ARMCC\include\stdio.h)(0x588B8344)
I (D:\Keil5\ARM\ARMCC\include\string.h)(0x588B8344)
I (../Inc/servo.h)(0x672C7728)
I (../Inc/key.h)(0x672C7132)
F (../Src/gpio.c)(0x672C6B1E)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\gpio.o --omf_browse project\gpio.crf --depend project\gpio.d)
I (../Inc/servo.h)(0x672CAFBD)
I (../Inc/key.h)(0x672CBCA2)
F (../Src/gpio.c)(0x672CB682)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\gpio.o --omf_browse project\gpio.crf --depend project\gpio.d)
I (../Inc/gpio.h)(0x6715E327)
I (../Inc/main.h)(0x672C6B20)
I (../Inc/main.h)(0x672CB685)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h)(0x671507AF)
I (../Inc/stm32l4xx_hal_conf.h)(0x67299DDD)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc.h)(0x671507AF)
@ -202,9 +202,9 @@ I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim_ex.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h)(0x671507AF)
F (../Src/adc.c)(0x672C6DE4)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\adc.o --omf_browse project\adc.crf --depend project\adc.d)
F (../Src/adc.c)(0x672CAB52)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\adc.o --omf_browse project\adc.crf --depend project\adc.d)
I (../Inc/adc.h)(0x67284CF2)
I (../Inc/main.h)(0x672C6B20)
I (../Inc/main.h)(0x672CB685)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h)(0x671507AF)
I (../Inc/stm32l4xx_hal_conf.h)(0x67299DDD)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc.h)(0x671507AF)
@ -242,7 +242,7 @@ I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h)(0x671507AF)
F (../Src/spi.c)(0x67279973)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\spi.o --omf_browse project\spi.crf --depend project\spi.d)
I (../Inc/spi.h)(0x67279574)
I (../Inc/main.h)(0x672C6B20)
I (../Inc/main.h)(0x672CB685)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h)(0x671507AF)
I (../Inc/stm32l4xx_hal_conf.h)(0x67299DDD)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc.h)(0x671507AF)
@ -278,9 +278,9 @@ I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim_ex.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h)(0x671507AF)
F (../Src/tim.c)(0x672C524A)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\tim.o --omf_browse project\tim.crf --depend project\tim.d)
I (../Inc/tim.h)(0x672C524A)
I (../Inc/main.h)(0x672C6B20)
F (../Src/tim.c)(0x672CB991)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\tim.o --omf_browse project\tim.crf --depend project\tim.d)
I (../Inc/tim.h)(0x672CB995)
I (../Inc/main.h)(0x672CB685)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h)(0x671507AF)
I (../Inc/stm32l4xx_hal_conf.h)(0x67299DDD)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc.h)(0x671507AF)
@ -318,7 +318,7 @@ I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h)(0x671507AF)
F (../Src/usart.c)(0x6728AD52)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\usart.o --omf_browse project\usart.crf --depend project\usart.d)
I (../Inc/usart.h)(0x67276B93)
I (../Inc/main.h)(0x672C6B20)
I (../Inc/main.h)(0x672CB685)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h)(0x671507AF)
I (../Inc/stm32l4xx_hal_conf.h)(0x67299DDD)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc.h)(0x671507AF)
@ -354,8 +354,8 @@ I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim_ex.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h)(0x671507AF)
F (../Src/stm32l4xx_it.c)(0x672C7765)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\stm32l4xx_it.o --omf_browse project\stm32l4xx_it.crf --depend project\stm32l4xx_it.d)
I (../Inc/main.h)(0x672C6B20)
F (../Src/stm32l4xx_it.c)(0x672CB9B9)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\stm32l4xx_it.o --omf_browse project\stm32l4xx_it.crf --depend project\stm32l4xx_it.d)
I (../Inc/main.h)(0x672CB685)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h)(0x671507AF)
I (../Inc/stm32l4xx_hal_conf.h)(0x67299DDD)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc.h)(0x671507AF)
@ -392,13 +392,13 @@ I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim_ex.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h)(0x671507AF)
I (../Inc/stm32l4xx_it.h)(0x672C524A)
I (../Inc/tim.h)(0x672C524A)
I (../Inc/servo.h)(0x672C7728)
I (../Inc/tim.h)(0x672CB995)
I (../Inc/servo.h)(0x672CAFBD)
I (../Inc/usart.h)(0x67276B93)
I (D:\Keil5\ARM\ARMCC\include\stdio.h)(0x588B8344)
I (../Inc/gpio.h)(0x6715E327)
F (../Src/stm32l4xx_hal_msp.c)(0x6715E328)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\stm32l4xx_hal_msp.o --omf_browse project\stm32l4xx_hal_msp.crf --depend project\stm32l4xx_hal_msp.d)
I (../Inc/main.h)(0x672C6B20)
I (../Inc/main.h)(0x672CB685)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h)(0x671507AF)
I (../Inc/stm32l4xx_hal_conf.h)(0x67299DDD)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc.h)(0x671507AF)
@ -435,8 +435,8 @@ I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim_ex.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h)(0x671507AF)
F (..\Src\servo.c)(0x672C78EF)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\servo.o --omf_browse project\servo.crf --depend project\servo.d)
I (../Inc/servo.h)(0x672C7728)
I (../Inc/main.h)(0x672C6B20)
I (../Inc/servo.h)(0x672CAFBD)
I (../Inc/main.h)(0x672CB685)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h)(0x671507AF)
I (../Inc/stm32l4xx_hal_conf.h)(0x67299DDD)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc.h)(0x671507AF)
@ -472,12 +472,12 @@ I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim_ex.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h)(0x671507AF)
I (../Inc/tim.h)(0x672C524A)
I (../Inc/tim.h)(0x672CB995)
I (../Inc/lcd.h)(0x5BF21D0E)
I (../Inc/sys.h)(0x67279973)
F (..\Inc\servo.h)(0x672C7728)()
F (..\Inc\servo.h)(0x672CAFBD)()
F (..\Src\key.c)(0x672C6F85)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\key.o --omf_browse project\key.crf --depend project\key.d)
F (..\Inc\key.h)(0x672C7132)()
F (..\Inc\key.h)(0x672CBCA2)()
F (../Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc.c)(0x671507AF)(--c99 -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I../Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I D:\Develop\Stm32Project\Project\MDK-ARM\RTE -I D:\Keil5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include -I D:\Keil5\ARM\PACK\Keil\STM32L4xx_DFP\1.4.0\Device\Include -D__UVISION_VERSION="514" -D_RTE_ -DSTM32L475xx -DUSE_HAL_DRIVER -DSTM32L475xx -o project\stm32l4xx_hal_adc.o --omf_browse project\stm32l4xx_hal_adc.crf --depend project\stm32l4xx_hal_adc.d)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h)(0x671507AF)
I (../Inc/stm32l4xx_hal_conf.h)(0x67299DDD)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -29,28 +29,32 @@ Mcu.IP8=USART1
Mcu.IPNb=9
Mcu.Name=STM32L475V(C-E-G)Tx
Mcu.Package=LQFP100
Mcu.Pin0=PH0-OSC_IN (PH0)
Mcu.Pin1=PH1-OSC_OUT (PH1)
Mcu.Pin10=PD10
Mcu.Pin11=PA9
Mcu.Pin12=PA10
Mcu.Pin13=PC10
Mcu.Pin14=PC11
Mcu.Pin15=PC12
Mcu.Pin16=PB8
Mcu.Pin17=PB9
Mcu.Pin18=VP_SYS_VS_Systick
Mcu.Pin19=VP_TIM7_VS_ClockSourceINT
Mcu.Pin2=PC2
Mcu.Pin20=VP_TIM15_VS_ClockSourceINT
Mcu.Pin3=PB2
Mcu.Pin4=PE7
Mcu.Pin5=PE8
Mcu.Pin6=PE9
Mcu.Pin7=PB15
Mcu.Pin8=PD8
Mcu.Pin9=PD9
Mcu.PinsNb=21
Mcu.Pin0=PC13
Mcu.Pin1=PH0-OSC_IN (PH0)
Mcu.Pin10=PB13
Mcu.Pin11=PB15
Mcu.Pin12=PD8
Mcu.Pin13=PD9
Mcu.Pin14=PD10
Mcu.Pin15=PA9
Mcu.Pin16=PA10
Mcu.Pin17=PC10
Mcu.Pin18=PC11
Mcu.Pin19=PC12
Mcu.Pin2=PH1-OSC_OUT (PH1)
Mcu.Pin20=PB8
Mcu.Pin21=PB9
Mcu.Pin22=VP_SYS_VS_Systick
Mcu.Pin23=VP_TIM7_VS_ClockSourceINT
Mcu.Pin24=VP_TIM15_VS_ClockSourceINT
Mcu.Pin3=PC2
Mcu.Pin4=PA4
Mcu.Pin5=PB2
Mcu.Pin6=PE7
Mcu.Pin7=PE8
Mcu.Pin8=PE9
Mcu.Pin9=PB11
Mcu.PinsNb=25
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32L475VETx
@ -72,8 +76,23 @@ NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
PA10.Mode=Asynchronous
PA10.Signal=USART1_RX
PA4.GPIOParameters=GPIO_PuPd,GPIO_Label
PA4.GPIO_Label=BIN1
PA4.GPIO_PuPd=GPIO_PULLUP
PA4.Locked=true
PA4.Signal=GPIO_Output
PA9.Mode=Asynchronous
PA9.Signal=USART1_TX
PB11.GPIOParameters=GPIO_PuPd,GPIO_Label
PB11.GPIO_Label=BIN2
PB11.GPIO_PuPd=GPIO_PULLDOWN
PB11.Locked=true
PB11.Signal=GPIO_Output
PB13.GPIOParameters=GPIO_Label
PB13.GPIO_Label=PWMB
PB13.Locked=true
PB13.Mode=PWM Generation1 CH1N
PB13.Signal=TIM15_CH1N
PB15.GPIOParameters=GPIO_Label
PB15.GPIO_Label=SERVO
PB15.Locked=true
@ -99,17 +118,21 @@ PC11.Mode=Full_Duplex_Master
PC11.Signal=SPI3_MISO
PC12.Mode=Full_Duplex_Master
PC12.Signal=SPI3_MOSI
PC13.GPIOParameters=GPIO_Label
PC13.GPIO_Label=KEY_UP
PC13.Locked=true
PC13.Signal=GPIO_Input
PC2.Signal=ADCx_IN3
PD10.GPIOParameters=GPIO_Label
PD10.GPIO_Label=KEY2
PD10.GPIO_Label=KEY_RIGHT
PD10.Locked=true
PD10.Signal=GPIO_Input
PD8.GPIOParameters=GPIO_Label
PD8.GPIO_Label=KEY0
PD8.GPIO_Label=KEY_LEFT
PD8.Locked=true
PD8.Signal=GPIO_Input
PD9.GPIOParameters=GPIO_Label
PD9.GPIO_Label=KEY1
PD9.GPIO_Label=KEY_DOWN
PD9.Locked=true
PD9.Signal=GPIO_Input
PE7.GPIOParameters=GPIO_PuPd,GPIO_Label
@ -233,13 +256,13 @@ SPI3.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate
SPI3.Mode=SPI_MODE_MASTER
SPI3.VirtualType=VM_MASTER
TIM1.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1
TIM1.Channel-PWM\ Generation1\ CH1\ CH1N=TIM_CHANNEL_1
TIM1.IPParameters=Channel-PWM Generation1 CH1 CH1N,Channel-PWM Generation1 CH1,Period,Prescaler,Pulse-PWM Generation1 CH1
TIM1.IPParameters=Channel-PWM Generation1 CH1,Period,Prescaler,Pulse-PWM Generation1 CH1
TIM1.Period=100-1
TIM1.Prescaler=720-1
TIM1.Pulse-PWM\ Generation1\ CH1=100
TIM15.Channel-PWM\ Generation1\ CH1N=TIM_CHANNEL_1
TIM15.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
TIM15.IPParameters=Channel-PWM Generation2 CH2,Prescaler,Period,Pulse-PWM Generation2 CH2
TIM15.IPParameters=Channel-PWM Generation2 CH2,Prescaler,Period,Pulse-PWM Generation2 CH2,Channel-PWM Generation1 CH1N
TIM15.Period=20000-1
TIM15.Prescaler=72-1
TIM15.Pulse-PWM\ Generation2\ CH2=500

203
Src/adc.c
View File

@ -30,129 +30,130 @@ ADC_HandleTypeDef hadc1;
void MX_ADC1_Init(void)
{
/* USER CODE BEGIN ADC1_Init 0 */
/* USER CODE BEGIN ADC1_Init 0 */
/* USER CODE END ADC1_Init 0 */
/* USER CODE END ADC1_Init 0 */
ADC_MultiModeTypeDef multimode = {0};
ADC_ChannelConfTypeDef sConfig = {0};
ADC_MultiModeTypeDef multimode = {0};
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC1_Init 1 */
/* USER CODE BEGIN ADC1_Init 1 */
/* USER CODE END ADC1_Init 1 */
/* USER CODE END ADC1_Init 1 */
/** Common config
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV2;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/** Common config
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV2;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/** Configure the ADC multi-mode
*/
multimode.Mode = ADC_MODE_INDEPENDENT;
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
{
Error_Handler();
}
/** Configure the ADC multi-mode
*/
multimode.Mode = ADC_MODE_INDEPENDENT;
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_3;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_3;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */
/* USER CODE END ADC1_Init 2 */
/* USER CODE END ADC1_Init 2 */
}
void HAL_ADC_MspInit(ADC_HandleTypeDef *adcHandle)
void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if (adcHandle->Instance == ADC1)
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(adcHandle->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspInit 0 */
/* USER CODE END ADC1_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_PLLSAI1;
PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_HSE;
PeriphClkInit.PLLSAI1.PLLSAI1M = 1;
PeriphClkInit.PLLSAI1.PLLSAI1N = 9;
PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7;
PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV2;
PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV6;
PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_ADC1CLK;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
/* USER CODE BEGIN ADC1_MspInit 0 */
/* USER CODE END ADC1_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_PLLSAI1;
PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_HSE;
PeriphClkInit.PLLSAI1.PLLSAI1M = 1;
PeriphClkInit.PLLSAI1.PLLSAI1N = 9;
PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7;
PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV2;
PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV6;
PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_ADC1CLK;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/* ADC1 clock enable */
__HAL_RCC_ADC_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
/**ADC1 GPIO Configuration
PC2 ------> ADC1_IN3
*/
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* USER CODE BEGIN ADC1_MspInit 1 */
/* USER CODE END ADC1_MspInit 1 */
Error_Handler();
}
/* ADC1 clock enable */
__HAL_RCC_ADC_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
/**ADC1 GPIO Configuration
PC2 ------> ADC1_IN3
*/
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* USER CODE BEGIN ADC1_MspInit 1 */
/* USER CODE END ADC1_MspInit 1 */
}
}
void HAL_ADC_MspDeInit(ADC_HandleTypeDef *adcHandle)
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
{
if (adcHandle->Instance == ADC1)
{
/* USER CODE BEGIN ADC1_MspDeInit 0 */
if(adcHandle->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspDeInit 0 */
/* USER CODE END ADC1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_ADC_CLK_DISABLE();
/* USER CODE END ADC1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_ADC_CLK_DISABLE();
/**ADC1 GPIO Configuration
PC2 ------> ADC1_IN3
*/
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2);
/**ADC1 GPIO Configuration
PC2 ------> ADC1_IN3
*/
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2);
/* USER CODE BEGIN ADC1_MspDeInit 1 */
/* USER CODE BEGIN ADC1_MspDeInit 1 */
/* USER CODE END ADC1_MspDeInit 1 */
}
/* USER CODE END ADC1_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */

View File

@ -45,19 +45,35 @@ void MX_GPIO_Init(void)
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(BEEP_GPIO_Port, BEEP_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(BIN1_GPIO_Port, BIN1_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, BEEP_Pin|BIN2_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOE, LED_R_Pin|LED_G_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = KEY_UP_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(KEY_UP_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = BIN1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(BIN1_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = BEEP_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
@ -72,8 +88,15 @@ void MX_GPIO_Init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = BIN2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(BIN2_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : PDPin PDPin PDPin */
GPIO_InitStruct.Pin = KEY0_Pin|KEY1_Pin|KEY2_Pin;
GPIO_InitStruct.Pin = KEY_LEFT_Pin|KEY_DOWN_Pin|KEY_RIGHT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

View File

@ -41,7 +41,7 @@
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define MOTORCCR(speed) (20000*(speed)/20)
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
@ -55,7 +55,7 @@
char rxdata[52];
uint16_t rxlen = 52;
uint8_t LED_B_ON = 0, LED1_ON = 0, LED2_ON = 0, LED3_ON = 0;
uint8_t Motor_Speed=0;
int cnt = 0;
/* USER CODE END PV */
@ -76,41 +76,41 @@ void Key_get(void);
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE BEGIN 1 */
uint32_t ADC_Value;
/* USER CODE END 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_USART1_UART_Init();
MX_SPI3_Init();
MX_TIM1_Init();
MX_TIM15_Init();
MX_TIM7_Init();
/* USER CODE BEGIN 2 */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_USART1_UART_Init();
MX_SPI3_Init();
MX_TIM1_Init();
MX_TIM15_Init();
MX_TIM7_Init();
/* USER CODE BEGIN 2 */
LCD_Init();
HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);
HAL_UARTEx_ReceiveToIdle_IT(&huart1, (uint8_t *)rxdata, sizeof(rxdata));
@ -118,13 +118,17 @@ int main(void)
POINT_COLOR = BLUE; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ɫ
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim15, TIM_CHANNEL_2);
/* USER CODE END 2 */
HAL_TIMEx_PWMN_Start(&htim15, TIM_CHANNEL_1);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
HAL_GPIO_WritePin(LED_R_GPIO_Port, LED_R_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(LED_G_GPIO_Port, LED_G_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(LED_B_GPIO_Port, LED_B_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(BIN1_GPIO_Port,BIN1_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(BIN2_GPIO_Port, BIN2_Pin, GPIO_PIN_SET);
printf("Hello!");
//__HAL_TIM_SET_COMPARE(&htim15,TIM_CHANNEL_2,5);
HAL_TIM_Base_Start_IT(&htim7);
@ -132,63 +136,66 @@ int main(void)
{
ADC_BEEP();
LCD_ShowxNum(50, 50, Servo_Speed, 4, 16, 0);
LCD_ShowxNum(150, 50, Motor_Speed, 4, 16, 0);
LCD_ShowxNum(50, 100, HAL_GPIO_ReadPin(PB8_EXTI_GPIO_Port,PB8_EXTI_Pin), 4, 16, 0);
LCD_ShowxNum(50, 200, Servo_goal, 4, 16, 0);
LCD_ShowxNum(50, 150, Servo_position, 4, 16, 0);
/* USER CODE END WHILE */
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
/* USER CODE BEGIN 3 */
Key_get();
// Servo_test();
Breathing_light();
//Breathing_light();
}
/* USER CODE END 3 */
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
{
Error_Handler();
}
/** Configure the main internal regulator output voltage
*/
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
{
Error_Handler();
}
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 1;
RCC_OscInitStruct.PLL.PLLN = 18;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 1;
RCC_OscInitStruct.PLL.PLLN = 18;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
{
Error_Handler();
}
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE BEGIN 4 */
@ -300,56 +307,74 @@ void ADC_BEEP(void)
}
void Key_get(void)
{
if (HAL_GPIO_ReadPin(KEY0_GPIO_Port, KEY0_Pin) == KEY_PRESSED)
if (HAL_GPIO_ReadPin(KEY_LEFT_GPIO_Port, KEY_LEFT_Pin) == KEY_PRESSED)
{
HAL_Delay(15);
LCD_ShowxNum(50, 150, Servo_position, 4, 16, 0);
while (HAL_GPIO_ReadPin(KEY0_GPIO_Port, KEY0_Pin) == KEY_PRESSED)
while (HAL_GPIO_ReadPin(KEY_LEFT_GPIO_Port, KEY_LEFT_Pin) == KEY_PRESSED)
;
Servo_goal = (Servo_goal + 90) % (180 + 90);
LCD_ShowxNum(50, 200, Servo_goal, 4, 16, 0);
HAL_Delay(15);
}
if (HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == KEY_PRESSED)
if (HAL_GPIO_ReadPin(KEY_RIGHT_GPIO_Port, KEY_RIGHT_Pin) == KEY_PRESSED)
{
HAL_Delay(15);
while (HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == KEY_PRESSED)
while (HAL_GPIO_ReadPin(KEY_RIGHT_GPIO_Port, KEY_RIGHT_Pin) == KEY_PRESSED)
;
Servo_Speed = Servo_Speed % 3 + 1;
LCD_ShowxNum(50, 50, Servo_Speed, 4, 16, 0);
HAL_Delay(15);
}
if (HAL_GPIO_ReadPin(KEY_UP_GPIO_Port, KEY_UP_Pin) == KEY_UP_PRESSED)
{
HAL_Delay(15);
while (HAL_GPIO_ReadPin(KEY_UP_GPIO_Port, KEY_UP_Pin) == KEY_UP_PRESSED);
Motor_Speed = NewCCRValue(Motor_Speed,+1,20);
HAL_Delay(15);
HAL_GPIO_TogglePin(LED_G_GPIO_Port, LED_G_Pin);
__HAL_TIM_SET_COMPARE(&htim15,TIM_CHANNEL_1,MOTORCCR(Motor_Speed));
}
if (HAL_GPIO_ReadPin(KEY_DOWN_GPIO_Port, KEY_DOWN_Pin) == KEY_PRESSED)
{
HAL_Delay(15);
while (HAL_GPIO_ReadPin(KEY_DOWN_GPIO_Port, KEY_DOWN_Pin) == KEY_PRESSED);
Motor_Speed = NewCCRValue(Motor_Speed,-1,20);
HAL_Delay(15);
HAL_GPIO_TogglePin(LED_G_GPIO_Port, LED_G_Pin);
__HAL_TIM_SET_COMPARE(&htim15,TIM_CHANNEL_1,MOTORCCR(Motor_Speed));
}
}
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

0
Src/motor.c Normal file
View File

View File

@ -250,38 +250,28 @@ void TIM7_IRQHandler(void)
}
/* USER CODE BEGIN 1 */
uint8_t NewCCRValue(int now_ccr,int plus)
{
if(now_ccr==100&&plus>0)
{
return now_ccr;
}
if(now_ccr==0&&plus<0)
{
return now_ccr;
}
return now_ccr+plus;
}
void SET3CCR(int plus)
{
if(LED3_ON)
{
uint8_t now_ccr=__HAL_TIM_GET_COMPARE(&htim1,TIM_CHANNEL_1);
__HAL_TIM_SET_COMPARE(&htim1,TIM_CHANNEL_1,NewCCRValue(now_ccr,plus));
uint8_t now_ccr=__HAL_TIM_GET_COMPARE(&htim1,TIM_CHANNEL_1);
__HAL_TIM_SET_COMPARE(&htim1,TIM_CHANNEL_1,NewCCRValue(now_ccr,plus,100));
}
// if(LED2_ON)
// {
// uint8_t now_ccr=__HAL_TIM_GET_COMPARE(&htim1,TIM_CHANNEL_1);
// __HAL_TIM_SET_COMPARE(&htim1,TIM_CHANNEL_1,NewCCRValue(now_ccr,plus));
// __HAL_TIM_SET_COMPARE(&htim1,TIM_CHANNEL_1,NewCCRValue(now_ccr,plus,100));
// }
// if(LED1_ON)
// {
// uint8_t now_ccr=__HAL_TIM_GET_COMPARE(&htim1,TIM_CHANNEL_1);
// __HAL_TIM_SET_COMPARE(&htim1,TIM_CHANNEL_1,NewCCRValue(now_ccr,plus));
// __HAL_TIM_SET_COMPARE(&htim1,TIM_CHANNEL_1,NewCCRValue(now_ccr,plus,100));
// }
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin==PB9_EXTI_Pin)
{
if(HAL_GPIO_ReadPin(PB8_EXTI_GPIO_Port,PB8_EXTI_Pin)==RESET)

View File

@ -169,12 +169,17 @@ void MX_TIM15_Init(void)
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 500;
sConfigOC.Pulse = 0;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
if (HAL_TIM_PWM_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
sConfigOC.Pulse = 500;
if (HAL_TIM_PWM_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
{
Error_Handler();
@ -275,14 +280,15 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
__HAL_RCC_GPIOB_CLK_ENABLE();
/**TIM15 GPIO Configuration
PB13 ------> TIM15_CH1N
PB15 ------> TIM15_CH2
*/
GPIO_InitStruct.Pin = SERVO_Pin;
GPIO_InitStruct.Pin = PWMB_Pin|SERVO_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF14_TIM15;
HAL_GPIO_Init(SERVO_GPIO_Port, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* USER CODE BEGIN TIM15_MspPostInit 1 */
@ -338,5 +344,16 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
}
/* USER CODE BEGIN 1 */
int NewCCRValue(int now_ccr,int plus,int maxvalue)
{
if(now_ccr+plus>maxvalue&&plus>0)
{
return now_ccr;
}
if(now_ccr+plus<0&&plus<0)
{
return now_ccr;
}
return now_ccr+plus;
}
/* USER CODE END 1 */