2个按键控制舵机旋转角度、速度
This commit is contained in:
parent
2830892d58
commit
b6a0e98611
|
@ -0,0 +1,2 @@
|
|||
#define KEY_PRESSED GPIO_PIN_RESET
|
||||
#define KEY_NOT_PRESSED GPIO_PIN_SET
|
|
@ -67,6 +67,12 @@ void Error_Handler(void);
|
|||
#define LED_B_GPIO_Port GPIOE
|
||||
#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 PB8_EXTI_Pin GPIO_PIN_8
|
||||
#define PB8_EXTI_GPIO_Port GPIOB
|
||||
#define PB8_EXTI_EXTI_IRQn EXTI9_5_IRQn
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
//Tanslate angle into Capture Compare Register value
|
||||
#define ANGLETOCCR(angle) 2000 * (angle) / 180 + 500
|
||||
|
||||
extern uint8_t Servo_Speed,Servo_goal,Servo_position;
|
||||
extern int16_t Servo_Speed,Servo_goal,Servo_position;
|
||||
|
||||
void Servo_SetAngle(int goal);
|
||||
int Servo_toward(void);
|
||||
|
|
Binary file not shown.
|
@ -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 main.c...
|
||||
../Src/main.c(126): warning: #177-D: variable "ADC_Value" was declared but never referenced
|
||||
uint32_t ADC_Value;
|
||||
../Src/main.c: 1 warning, 0 errors
|
||||
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
|
||||
linking...
|
||||
Program Size: Code=18628 RO-data=59236 RW-data=36 ZI-data=2892
|
||||
Program Size: Code=18972 RO-data=59236 RW-data=40 ZI-data=2896
|
||||
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
|
@ -12,6 +12,7 @@
|
|||
"project\stm32l4xx_it.o"
|
||||
"project\stm32l4xx_hal_msp.o"
|
||||
"project\servo.o"
|
||||
"project\key.o"
|
||||
"project\stm32l4xx_hal_adc.o"
|
||||
"project\stm32l4xx_hal_adc_ex.o"
|
||||
"project\stm32l4xx_hal.o"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,5 @@
|
|||
Dependencies for Project 'Project', Target 'Project': (DO NOT MODIFY !)
|
||||
F (startup_stm32l475xx.s)(0x672C524E)(--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)(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 (..\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)(0x672C5484)(--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)(0x672B2071)
|
||||
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)
|
||||
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)
|
||||
|
@ -162,10 +162,11 @@ 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)(0x672C51E6)
|
||||
F (../Src/gpio.c)(0x672A38B6)(--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)(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/gpio.h)(0x6715E327)
|
||||
I (../Inc/main.h)(0x672B2071)
|
||||
I (../Inc/main.h)(0x672C6B20)
|
||||
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)
|
||||
|
@ -201,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)(0x672B7423)(--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)(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)
|
||||
I (../Inc/adc.h)(0x67284CF2)
|
||||
I (../Inc/main.h)(0x672B2071)
|
||||
I (../Inc/main.h)(0x672C6B20)
|
||||
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)
|
||||
|
@ -241,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)(0x672B2071)
|
||||
I (../Inc/main.h)(0x672C6B20)
|
||||
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)
|
||||
|
@ -279,7 +280,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/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)(0x672B2071)
|
||||
I (../Inc/main.h)(0x672C6B20)
|
||||
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)
|
||||
|
@ -317,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)(0x672B2071)
|
||||
I (../Inc/main.h)(0x672C6B20)
|
||||
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)
|
||||
|
@ -353,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)(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\stm32l4xx_it.o --omf_browse project\stm32l4xx_it.crf --depend project\stm32l4xx_it.d)
|
||||
I (../Inc/main.h)(0x672B2071)
|
||||
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)
|
||||
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,12 +393,12 @@ 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)(0x672C51E6)
|
||||
I (../Inc/servo.h)(0x672C7728)
|
||||
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)(0x672B2071)
|
||||
I (../Inc/main.h)(0x672C6B20)
|
||||
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)
|
||||
|
@ -433,9 +434,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\servo.c)(0x672C52EE)(--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)(0x672C51E6)
|
||||
I (../Inc/main.h)(0x672B2071)
|
||||
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 (../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)
|
||||
|
@ -474,7 +475,9 @@ I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h)(0x671507AF)
|
|||
I (../Inc/tim.h)(0x672C524A)
|
||||
I (../Inc/lcd.h)(0x5BF21D0E)
|
||||
I (../Inc/sys.h)(0x67279973)
|
||||
F (..\Inc\servo.h)(0x672C51E6)()
|
||||
F (..\Inc\servo.h)(0x672C7728)()
|
||||
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 (../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.
|
@ -0,0 +1 @@
|
|||
project\key.o: ..\Src\key.c
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -46,3 +46,4 @@ project\main.o: ../Inc/sys.h
|
|||
project\main.o: D:\Keil5\ARM\ARMCC\Bin\..\include\stdio.h
|
||||
project\main.o: D:\Keil5\ARM\ARMCC\Bin\..\include\string.h
|
||||
project\main.o: ../Inc/servo.h
|
||||
project\main.o: ../Inc/key.h
|
||||
|
|
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.
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
39
Project.ioc
39
Project.ioc
|
@ -31,23 +31,26 @@ Mcu.Name=STM32L475V(C-E-G)Tx
|
|||
Mcu.Package=LQFP100
|
||||
Mcu.Pin0=PH0-OSC_IN (PH0)
|
||||
Mcu.Pin1=PH1-OSC_OUT (PH1)
|
||||
Mcu.Pin10=PC10
|
||||
Mcu.Pin11=PC11
|
||||
Mcu.Pin12=PC12
|
||||
Mcu.Pin13=PB8
|
||||
Mcu.Pin14=PB9
|
||||
Mcu.Pin15=VP_SYS_VS_Systick
|
||||
Mcu.Pin16=VP_TIM7_VS_ClockSourceINT
|
||||
Mcu.Pin17=VP_TIM15_VS_ClockSourceINT
|
||||
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=PA9
|
||||
Mcu.Pin9=PA10
|
||||
Mcu.PinsNb=18
|
||||
Mcu.Pin8=PD8
|
||||
Mcu.Pin9=PD9
|
||||
Mcu.PinsNb=21
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32L475VETx
|
||||
|
@ -97,6 +100,18 @@ PC11.Signal=SPI3_MISO
|
|||
PC12.Mode=Full_Duplex_Master
|
||||
PC12.Signal=SPI3_MOSI
|
||||
PC2.Signal=ADCx_IN3
|
||||
PD10.GPIOParameters=GPIO_Label
|
||||
PD10.GPIO_Label=KEY2
|
||||
PD10.Locked=true
|
||||
PD10.Signal=GPIO_Input
|
||||
PD8.GPIOParameters=GPIO_Label
|
||||
PD8.GPIO_Label=KEY0
|
||||
PD8.Locked=true
|
||||
PD8.Signal=GPIO_Input
|
||||
PD9.GPIOParameters=GPIO_Label
|
||||
PD9.GPIO_Label=KEY1
|
||||
PD9.Locked=true
|
||||
PD9.Signal=GPIO_Input
|
||||
PE7.GPIOParameters=GPIO_PuPd,GPIO_Label
|
||||
PE7.GPIO_Label=LED_R
|
||||
PE7.GPIO_PuPd=GPIO_PULLUP
|
||||
|
@ -146,7 +161,7 @@ ProjectManager.ToolChainLocation=
|
|||
ProjectManager.UAScriptAfterPath=
|
||||
ProjectManager.UAScriptBeforePath=
|
||||
ProjectManager.UnderRoot=false
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_ADC1_Init-ADC1-false-HAL-true,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_SPI3_Init-SPI3-false-HAL-true,6-MX_TIM1_Init-TIM1-false-HAL-true,7-MX_TIM15_Init-TIM15-false-HAL-true
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_ADC1_Init-ADC1-false-HAL-true,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_SPI3_Init-SPI3-false-HAL-true,6-MX_TIM1_Init-TIM1-false-HAL-true,7-MX_TIM15_Init-TIM15-false-HAL-true,8-MX_TIM7_Init-TIM7-false-HAL-true
|
||||
RCC.ADCFreq_Value=12000000
|
||||
RCC.AHBFreq_Value=72000000
|
||||
RCC.APB1Freq_Value=72000000
|
||||
|
|
265
Src/adc.c
265
Src/adc.c
|
@ -1,21 +1,21 @@
|
|||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file adc.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the ADC instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
******************************************************************************
|
||||
* @file adc.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the ADC instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "adc.h"
|
||||
|
@ -30,130 +30,129 @@ 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();
|
||||
}
|
||||
|
||||
/** 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 */
|
||||
|
||||
/* USER CODE END ADC1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
|
||||
{
|
||||
|
||||
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)
|
||||
/** 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();
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/* ADC1 clock enable */
|
||||
__HAL_RCC_ADC_CLK_ENABLE();
|
||||
/** Configure the ADC multi-mode
|
||||
*/
|
||||
multimode.Mode = ADC_MODE_INDEPENDENT;
|
||||
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
__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);
|
||||
/** 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 BEGIN ADC1_MspInit 1 */
|
||||
|
||||
/* USER CODE END ADC1_MspInit 1 */
|
||||
}
|
||||
/* USER CODE END ADC1_Init 2 */
|
||||
}
|
||||
|
||||
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
|
||||
void HAL_ADC_MspInit(ADC_HandleTypeDef *adcHandle)
|
||||
{
|
||||
|
||||
if(adcHandle->Instance==ADC1)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 0 */
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||
if (adcHandle->Instance == ADC1)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_MspInit 0 */
|
||||
|
||||
/* USER CODE END ADC1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_ADC_CLK_DISABLE();
|
||||
/* USER CODE END ADC1_MspInit 0 */
|
||||
|
||||
/**ADC1 GPIO Configuration
|
||||
PC2 ------> ADC1_IN3
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2);
|
||||
/** 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();
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 1 */
|
||||
/* ADC1 clock enable */
|
||||
__HAL_RCC_ADC_CLK_ENABLE();
|
||||
|
||||
/* USER CODE END ADC1_MspDeInit 1 */
|
||||
}
|
||||
__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)
|
||||
{
|
||||
|
||||
if (adcHandle->Instance == ADC1)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 0 */
|
||||
|
||||
/* 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);
|
||||
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END ADC1_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
@ -169,25 +168,23 @@ uint16_t Get_Adc(uint32_t ch)
|
|||
// ADC1_ChanConf.Offset = 0;
|
||||
// HAL_ADC_ConfigChannel(&hadc1, &ADC1_ChanConf); //????
|
||||
|
||||
HAL_ADC_Start(&hadc1); //??ADC
|
||||
HAL_ADC_Start(&hadc1); //??ADC
|
||||
|
||||
if(HAL_ADC_PollForConversion(&hadc1, 10)==HAL_OK)
|
||||
{
|
||||
//????
|
||||
|
||||
return (uint16_t)HAL_ADC_GetValue(&hadc1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}//??????ADC1????????
|
||||
if (HAL_ADC_PollForConversion(&hadc1, 10) == HAL_OK)
|
||||
{
|
||||
return (uint16_t)HAL_ADC_GetValue(&hadc1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
uint16_t Get_Adc_Average(uint32_t ch, uint8_t times)
|
||||
{
|
||||
uint32_t temp_val = 0;
|
||||
uint8_t t;
|
||||
|
||||
for(t = 0; t < times; t++)
|
||||
for (t = 0; t < times; t++)
|
||||
{
|
||||
temp_val += Get_Adc(ch);
|
||||
HAL_Delay(5);
|
||||
|
|
|
@ -49,6 +49,7 @@ void MX_GPIO_Init(void)
|
|||
__HAL_RCC_GPIOC_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 */
|
||||
|
@ -71,6 +72,12 @@ void MX_GPIO_Init(void)
|
|||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PDPin PDPin PDPin */
|
||||
GPIO_InitStruct.Pin = KEY0_Pin|KEY1_Pin|KEY2_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PBPin PBPin */
|
||||
GPIO_InitStruct.Pin = PB8_EXTI_Pin|PB9_EXTI_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
||||
|
|
428
Src/main.c
428
Src/main.c
|
@ -31,6 +31,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "servo.h"
|
||||
#include "key.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
@ -52,8 +53,8 @@
|
|||
|
||||
/* USER CODE BEGIN PV */
|
||||
char rxdata[52];
|
||||
uint16_t rxlen=52;
|
||||
uint8_t LED_B_ON=0,LED1_ON=0,LED2_ON=0,LED3_ON=0;
|
||||
uint16_t rxlen = 52;
|
||||
uint8_t LED_B_ON = 0, LED1_ON = 0, LED2_ON = 0, LED3_ON = 0;
|
||||
|
||||
int cnt = 0;
|
||||
/* USER CODE END PV */
|
||||
|
@ -61,53 +62,12 @@ int cnt = 0;
|
|||
/* Private function prototypes -----------------------------------------------*/
|
||||
void SystemClock_Config(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
int fputc(int ch, FILE *f)
|
||||
{
|
||||
|
||||
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
|
||||
return ch;
|
||||
}
|
||||
int fgetc(FILE *f)
|
||||
{
|
||||
int ch;
|
||||
// while (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE) == RESET);
|
||||
HAL_UART_Receive(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
|
||||
return (ch);
|
||||
}
|
||||
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
|
||||
{
|
||||
printf("rx\r\n");
|
||||
if (huart == &huart1)
|
||||
{
|
||||
rxdata[Size] = '\0';
|
||||
if (strcmp(rxdata, "LED1") == 0)
|
||||
{
|
||||
LED1_ON=!LED1_ON;
|
||||
HAL_GPIO_TogglePin(LED_R_GPIO_Port, LED_R_Pin);
|
||||
}
|
||||
else if (strcmp(rxdata, "LED2") == 0)
|
||||
{
|
||||
LED2_ON=!LED2_ON;
|
||||
HAL_GPIO_TogglePin(LED_G_GPIO_Port, LED_G_Pin);
|
||||
}
|
||||
else if (strcmp(rxdata, "LED3") == 0)
|
||||
{
|
||||
LED_B_ON=!LED_B_ON;
|
||||
LED3_ON=!LED3_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
cnt=0;
|
||||
for(int i=0;i<Size;i++)
|
||||
{
|
||||
cnt*=10;
|
||||
cnt+=rxdata[i]-'0';
|
||||
}
|
||||
Servo_goal=cnt;
|
||||
}
|
||||
HAL_UARTEx_ReceiveToIdle_IT(&huart1, (uint8_t *)rxdata, sizeof(rxdata));
|
||||
}
|
||||
}
|
||||
void Servo_test(void);
|
||||
int fputc(int ch, FILE *f);
|
||||
int fgetc(FILE *f);
|
||||
void Breathing_light(void);
|
||||
void ADC_BEEP(void);
|
||||
void Key_get(void);
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
|
@ -116,202 +76,280 @@ void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
|
|||
/* 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));
|
||||
HAL_ADC_Start(&hadc1);
|
||||
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_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
|
||||
HAL_TIM_PWM_Start(&htim15, TIM_CHANNEL_2);
|
||||
/* 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);
|
||||
printf("Hello!");
|
||||
printf("Hello!");
|
||||
//__HAL_TIM_SET_COMPARE(&htim15,TIM_CHANNEL_2,5);
|
||||
HAL_TIM_Base_Start_IT(&htim7);
|
||||
HAL_TIM_Base_Start_IT(&htim7);
|
||||
while (1)
|
||||
{ //??ADC??
|
||||
// HAL_ADC_PollForConversion(&hadc1, 50); //??????,50???????,???ms
|
||||
// if (HAL_IS_BIT_SET(HAL_ADC_GetState(&hadc1), HAL_ADC_STATE_REG_EOC))
|
||||
// {
|
||||
#ifdef ONE_ADC_BEEP
|
||||
ADC_Value = Get_Adc_Average(ADC_CHANNEL_3, 5); //??AD?
|
||||
LCD_ShowxNum(50, 100, ADC_Value, 4, 16, 0);
|
||||
if (ADC_Value * 3.3 / 4095 > 1.7)
|
||||
{
|
||||
ADC_BEEP();
|
||||
LCD_ShowxNum(50, 50, Servo_Speed, 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 BEGIN 3 */
|
||||
Key_get();
|
||||
// Servo_test();
|
||||
Breathing_light();
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
/** 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;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
void Servo_test(void)
|
||||
{
|
||||
// cnt=(cnt+30)%(180+30);
|
||||
LCD_ShowxNum(50, 200, cnt, 4, 16, 0);
|
||||
LCD_ShowxNum(50, 150, ANGLETOCCR(cnt), 4, 16, 0);
|
||||
Servo_SetAngle(cnt);
|
||||
HAL_GPIO_TogglePin(LED_R_GPIO_Port, LED_R_Pin);
|
||||
}
|
||||
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
|
||||
{
|
||||
printf("rx\r\n");
|
||||
if (huart == &huart1)
|
||||
{
|
||||
rxdata[Size] = '\0';
|
||||
if (strcmp(rxdata, "LED1") == 0)
|
||||
{
|
||||
cnt++;
|
||||
LED1_ON = !LED1_ON;
|
||||
HAL_GPIO_TogglePin(LED_R_GPIO_Port, LED_R_Pin);
|
||||
}
|
||||
else if (strcmp(rxdata, "LED2") == 0)
|
||||
{
|
||||
LED2_ON = !LED2_ON;
|
||||
HAL_GPIO_TogglePin(LED_G_GPIO_Port, LED_G_Pin);
|
||||
}
|
||||
else if (strcmp(rxdata, "LED3") == 0)
|
||||
{
|
||||
LED_B_ON = !LED_B_ON;
|
||||
LED3_ON = !LED3_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
cnt = 0;
|
||||
for (int i = 0; i < Size; i++)
|
||||
{
|
||||
cnt *= 10;
|
||||
cnt += rxdata[i] - '0';
|
||||
}
|
||||
Servo_goal = cnt;
|
||||
}
|
||||
if (cnt == 50)
|
||||
{
|
||||
HAL_GPIO_TogglePin(BEEP_GPIO_Port, BEEP_Pin);
|
||||
HAL_Delay(100);
|
||||
HAL_GPIO_TogglePin(BEEP_GPIO_Port, BEEP_Pin);
|
||||
HAL_Delay(100);
|
||||
HAL_GPIO_TogglePin(BEEP_GPIO_Port, BEEP_Pin);
|
||||
HAL_Delay(100);
|
||||
HAL_GPIO_TogglePin(BEEP_GPIO_Port, BEEP_Pin);
|
||||
HAL_Delay(100);
|
||||
HAL_GPIO_TogglePin(BEEP_GPIO_Port, BEEP_Pin);
|
||||
HAL_Delay(100);
|
||||
HAL_GPIO_TogglePin(BEEP_GPIO_Port, BEEP_Pin);
|
||||
}
|
||||
LCD_ShowxNum(50, 200, cnt, 4, 16, 0);
|
||||
HAL_GPIO_TogglePin(LED_B_GPIO_Port,LED_B_Pin);
|
||||
// }
|
||||
HAL_Delay(100);
|
||||
#endif
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
|
||||
//cnt=(cnt+30)%(180+30);
|
||||
LCD_ShowxNum(50, 200, cnt, 4, 16, 0);
|
||||
LCD_ShowxNum(50, 150, ANGLETOCCR(cnt), 4, 16, 0);
|
||||
// Servo_SetAngle(cnt);
|
||||
HAL_GPIO_TogglePin(LED_R_GPIO_Port, LED_R_Pin);
|
||||
HAL_Delay(1000);
|
||||
if(!LED_B_ON)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for(int i=0;i<=100;i++)
|
||||
{
|
||||
__HAL_TIM_SET_COMPARE(&htim1,TIM_CHANNEL_1,100-i);
|
||||
HAL_Delay(10);
|
||||
}
|
||||
for(int i=0;i<=100;i++)
|
||||
{
|
||||
__HAL_TIM_SET_COMPARE(&htim1,TIM_CHANNEL_1,i);
|
||||
HAL_Delay(10);
|
||||
}
|
||||
//HAL_Delay(500);
|
||||
HAL_UARTEx_ReceiveToIdle_IT(&huart1, (uint8_t *)rxdata, sizeof(rxdata));
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
int fgetc(FILE *f)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
/** 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;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
int ch;
|
||||
// while (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE) == RESET);
|
||||
HAL_UART_Receive(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
|
||||
return (ch);
|
||||
}
|
||||
int fputc(int ch, FILE *f)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
|
||||
return ch;
|
||||
}
|
||||
// LED_B的呼吸灯
|
||||
void Breathing_light(void)
|
||||
{
|
||||
if (!LED_B_ON)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i <= 100; i++)
|
||||
{
|
||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 100 - i);
|
||||
HAL_Delay(10);
|
||||
}
|
||||
for (int i = 0; i <= 100; i++)
|
||||
{
|
||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, i);
|
||||
HAL_Delay(10);
|
||||
}
|
||||
}
|
||||
void ADC_BEEP(void)
|
||||
{
|
||||
#ifdef ONE_ADC_BEEP
|
||||
ADC_Value = Get_Adc_Average(ADC_CHANNEL_3, 5); //??AD?
|
||||
LCD_ShowxNum(50, 100, ADC_Value, 4, 16, 0);
|
||||
if (ADC_Value * 3.3 / 4095 > 1.7)
|
||||
{
|
||||
cnt++;
|
||||
}
|
||||
else
|
||||
{
|
||||
cnt = 0;
|
||||
}
|
||||
if (cnt == 50)
|
||||
{
|
||||
HAL_GPIO_TogglePin(BEEP_GPIO_Port, BEEP_Pin);
|
||||
HAL_Delay(100);
|
||||
HAL_GPIO_TogglePin(BEEP_GPIO_Port, BEEP_Pin);
|
||||
HAL_Delay(100);
|
||||
HAL_GPIO_TogglePin(BEEP_GPIO_Port, BEEP_Pin);
|
||||
HAL_Delay(100);
|
||||
HAL_GPIO_TogglePin(BEEP_GPIO_Port, BEEP_Pin);
|
||||
HAL_Delay(100);
|
||||
HAL_GPIO_TogglePin(BEEP_GPIO_Port, BEEP_Pin);
|
||||
HAL_Delay(100);
|
||||
HAL_GPIO_TogglePin(BEEP_GPIO_Port, BEEP_Pin);
|
||||
}
|
||||
LCD_ShowxNum(50, 200, cnt, 4, 16, 0);
|
||||
HAL_GPIO_TogglePin(LED_B_GPIO_Port, LED_B_Pin);
|
||||
// }
|
||||
HAL_Delay(100);
|
||||
#endif
|
||||
}
|
||||
void Key_get(void)
|
||||
{
|
||||
if (HAL_GPIO_ReadPin(KEY0_GPIO_Port, KEY0_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)
|
||||
;
|
||||
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)
|
||||
{
|
||||
HAL_Delay(15);
|
||||
while (HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == KEY_PRESSED)
|
||||
;
|
||||
Servo_Speed = Servo_Speed % 3 + 1;
|
||||
LCD_ShowxNum(50, 50, Servo_Speed, 4, 16, 0);
|
||||
HAL_Delay(15);
|
||||
}
|
||||
}
|
||||
/* 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 */
|
||||
|
|
29
Src/servo.c
29
Src/servo.c
|
@ -2,7 +2,7 @@
|
|||
#include "tim.h"
|
||||
#include "lcd.h"
|
||||
|
||||
uint8_t Servo_Speed = 1, Servo_goal = 0, Servo_position = 0;
|
||||
int16_t Servo_Speed = 1, Servo_goal = 0, Servo_position = 0;
|
||||
|
||||
void Servo_SetAngle(int goal)
|
||||
{
|
||||
|
@ -13,23 +13,22 @@ void Servo_SetAngle(int goal)
|
|||
// 往哪个方向转
|
||||
int Servo_toward(void)
|
||||
{
|
||||
return Servo_goal > Servo_position;
|
||||
if (Servo_goal > Servo_position)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
static uint8_t times = 0,tt=0;
|
||||
static uint8_t times = 0, tt = 0;
|
||||
if (htim == &htim7)
|
||||
{
|
||||
// if (++times == 250)
|
||||
// {
|
||||
// LCD_ShowxNum(50, 50, ++tt, 4, 16, 0);
|
||||
// times = 0;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
if (++times == 1000)
|
||||
{
|
||||
times = 0;
|
||||
}
|
||||
if (Servo_position == Servo_goal)
|
||||
{
|
||||
return;
|
||||
|
@ -38,11 +37,11 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|||
{
|
||||
Servo_position = Servo_goal;
|
||||
}
|
||||
if (Servo_Speed == 2)
|
||||
if (Servo_Speed == 2 && times % 5 == 0)
|
||||
{
|
||||
Servo_position += Servo_toward() * 9;
|
||||
Servo_position += Servo_toward();
|
||||
}
|
||||
if (Servo_Speed == 3)
|
||||
if (Servo_Speed == 3 && times % 50 == 0)
|
||||
{
|
||||
Servo_position += Servo_toward();
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
extern TIM_HandleTypeDef htim7;
|
||||
extern UART_HandleTypeDef huart1;
|
||||
/* USER CODE BEGIN EV */
|
||||
extern uint8_t Servo_Speed;
|
||||
|
||||
extern uint8_t LED_B_ON,LED1_ON,LED2_ON,LED3_ON;
|
||||
|
||||
/* USER CODE END EV */
|
||||
|
|
Loading…
Reference in New Issue