加上当转动时间等于转速,转速和时间清0

This commit is contained in:
james 2024-11-07 22:32:40 +08:00
parent 7908b65803
commit a399a2f3de
21 changed files with 4117 additions and 3949 deletions

View File

@ -5,6 +5,7 @@
"main.h": "c",
"spi3.h": "c",
"servo.h": "c",
"usart.h": "c"
"usart.h": "c",
"motor.h": "c"
}
}

6
Inc/motor.h Normal file
View File

@ -0,0 +1,6 @@
#define MOTORCCR(speed) (20000*(speed)/20)
extern uint8_t Motor_Speed;
extern int Motor_time,Motor_tag,Motor_start;
void Motor_reset_ornot(void);

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 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
compiling motor.c...
..\Src\motor.c(16): warning: #1-D: last line of file ends without a newline
}
..\Src\motor.c: 1 warning, 0 errors
linking...
Program Size: Code=19496 RO-data=59236 RW-data=44 ZI-data=2892
Program Size: Code=19648 RO-data=59236 RW-data=60 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

View File

@ -13,6 +13,7 @@
"project\stm32l4xx_hal_msp.o"
"project\servo.o"
"project\key.o"
"project\motor.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

View File

@ -116,7 +116,7 @@ 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)(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)
F (../Src/main.c)(0x672CCDDB)(--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)
@ -163,7 +163,8 @@ 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)(0x672CAFBD)
I (../Inc/key.h)(0x672CBCA2)
I (../Inc/key.h)(0x672CBEA2)
I (../Inc/motor.h)(0x672CCD8A)
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)(0x672CB685)
@ -434,7 +435,7 @@ 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)(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)
F (..\Src\servo.c)(0x672CCDF1)(--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)(0x672CAFBD)
I (../Inc/main.h)(0x672CB685)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h)(0x671507AF)
@ -475,9 +476,50 @@ I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h)(0x671507AF)
I (../Inc/tim.h)(0x672CB995)
I (../Inc/lcd.h)(0x5BF21D0E)
I (../Inc/sys.h)(0x67279973)
I (../Inc/motor.h)(0x672CCD8A)
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)(0x672CBCA2)()
F (..\Inc\key.h)(0x672CBEA2)()
F (..\Src\motor.c)(0x672CCE8A)(--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\motor.o --omf_browse project\motor.crf --depend project\motor.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)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_def.h)(0x671507AF)
I (../Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l4xx.h)(0x671507AF)
I (../Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l475xx.h)(0x671507AF)
I (../Drivers/CMSIS/Include/core_cm4.h)(0x67150760)
I (D:\Keil5\ARM\ARMCC\include\stdint.h)(0x588B8344)
I (../Drivers/CMSIS/Include/cmsis_version.h)(0x67150760)
I (../Drivers/CMSIS/Include/cmsis_compiler.h)(0x67150760)
I (../Drivers/CMSIS/Include/cmsis_armcc.h)(0x67150760)
I (../Drivers/CMSIS/Include/mpu_armv7.h)(0x67150760)
I (../Drivers/CMSIS/Device/ST/STM32L4xx/Include/system_stm32l4xx.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h)(0x671507AF)
I (D:\Keil5\ARM\ARMCC\include\stddef.h)(0x588B8344)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc_ex.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_gpio.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_gpio_ex.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_dma.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_cortex.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_adc.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_ll_adc.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_adc_ex.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_exti.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash_ex.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash_ramfunc.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_pwr.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_pwr_ex.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_spi.h)(0x671507AF)
I (../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_spi_ex.h)(0x671507AF)
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/motor.h)(0x672CCD8A)
I (../Inc/tim.h)(0x672CB995)
F (..\Inc\motor.h)(0x672CCD8A)()
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.

View File

@ -47,3 +47,4 @@ 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
project\main.o: ../Inc/motor.h

Binary file not shown.

BIN
MDK-ARM/Project/motor.crf Normal file

Binary file not shown.

40
MDK-ARM/Project/motor.d Normal file
View File

@ -0,0 +1,40 @@
project\motor.o: ..\Src\motor.c
project\motor.o: ../Inc/main.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h
project\motor.o: ../Inc/stm32l4xx_hal_conf.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_def.h
project\motor.o: ../Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l4xx.h
project\motor.o: ../Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l475xx.h
project\motor.o: ../Drivers/CMSIS/Include/core_cm4.h
project\motor.o: D:\Keil5\ARM\ARMCC\Bin\..\include\stdint.h
project\motor.o: ../Drivers/CMSIS/Include/cmsis_version.h
project\motor.o: ../Drivers/CMSIS/Include/cmsis_compiler.h
project\motor.o: ../Drivers/CMSIS/Include/cmsis_armcc.h
project\motor.o: ../Drivers/CMSIS/Include/mpu_armv7.h
project\motor.o: ../Drivers/CMSIS/Device/ST/STM32L4xx/Include/system_stm32l4xx.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h
project\motor.o: D:\Keil5\ARM\ARMCC\Bin\..\include\stddef.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc_ex.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_gpio.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_gpio_ex.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_dma.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_cortex.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_adc.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_ll_adc.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_adc_ex.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_exti.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash_ex.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash_ramfunc.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_pwr.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_pwr_ex.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_spi.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_spi_ex.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim_ex.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart.h
project\motor.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h
project\motor.o: ../Inc/motor.h
project\motor.o: ../Inc/tim.h

BIN
MDK-ARM/Project/motor.o Normal file

Binary file not shown.

Binary file not shown.

View File

@ -40,3 +40,4 @@ project\servo.o: ../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h
project\servo.o: ../Inc/tim.h
project\servo.o: ../Inc/lcd.h
project\servo.o: ../Inc/sys.h
project\servo.o: ../Inc/motor.h

Binary file not shown.

View File

@ -32,6 +32,7 @@
#include <string.h>
#include "servo.h"
#include "key.h"
#include "motor.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@ -41,7 +42,7 @@
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define MOTORCCR(speed) (20000*(speed)/20)
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
@ -55,7 +56,6 @@
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 */
@ -138,6 +138,8 @@ int main(void)
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);
if(Motor_time>=0)
LCD_ShowxNum(150, 100, Motor_time, 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 */
@ -331,8 +333,14 @@ void Key_get(void)
HAL_Delay(15);
while (HAL_GPIO_ReadPin(KEY_UP_GPIO_Port, KEY_UP_Pin) == KEY_UP_PRESSED);
Motor_Speed = NewCCRValue(Motor_Speed,+1,20);
if(Motor_Speed==1)
{
Motor_time = 0;
Motor_start=1;
}
HAL_Delay(15);
HAL_GPIO_TogglePin(LED_G_GPIO_Port, LED_G_Pin);
Motor_reset_ornot();
__HAL_TIM_SET_COMPARE(&htim15,TIM_CHANNEL_1,MOTORCCR(Motor_Speed));
}
if (HAL_GPIO_ReadPin(KEY_DOWN_GPIO_Port, KEY_DOWN_Pin) == KEY_PRESSED)
@ -342,6 +350,7 @@ void Key_get(void)
Motor_Speed = NewCCRValue(Motor_Speed,-1,20);
HAL_Delay(15);
HAL_GPIO_TogglePin(LED_G_GPIO_Port, LED_G_Pin);
Motor_reset_ornot();
__HAL_TIM_SET_COMPARE(&htim15,TIM_CHANNEL_1,MOTORCCR(Motor_Speed));
}
}

View File

@ -0,0 +1,16 @@
#include "main.h"
#include "motor.h"
#include "tim.h"
uint8_t Motor_Speed = 0;
int Motor_time = -1, Motor_tag = -1, Motor_start = 0;
void Motor_reset_ornot(void)
{
if (Motor_Speed == Motor_time)
{
Motor_Speed = 0;
Motor_time = 0;
Motor_tag = -1;
}
__HAL_TIM_SET_COMPARE(&htim15, TIM_CHANNEL_1, MOTORCCR(Motor_Speed));
}

View File

@ -1,6 +1,7 @@
#include "servo.h"
#include "tim.h"
#include "lcd.h"
#include "motor.h"
int16_t Servo_Speed = 1, Servo_goal = 0, Servo_position = 0;
@ -22,9 +23,19 @@ int Servo_toward(void)
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
static uint8_t times = 0, tt = 0;
static int times = 0;
if (htim == &htim7)
{
if(times==Motor_tag)
{
Motor_time++;
Motor_reset_ornot();
}
if(Motor_start)
{
Motor_tag=times;
Motor_start=0;//清除标志位!!!
}
if (++times == 1000)
{
times = 0;