From 1e2bad9a9e122662efb14b7561ca864984b2c5c1 Mon Sep 17 00:00:00 2001 From: but0n Date: Tue, 27 Sep 2016 15:31:19 +0800 Subject: [PATCH] [MOD]: Fixed BUG, UART Print short data function --- .../Libraries/STM32F10x_StdPeriph_Driver/inc/motor.h | 12 +++++++++--- .../Libraries/STM32F10x_StdPeriph_Driver/src/uart.c | 8 ++++---- src/main.c | 1 - 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc/motor.h b/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc/motor.h index d11ee29..eaed72c 100644 --- a/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc/motor.h +++ b/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc/motor.h @@ -6,9 +6,15 @@ #define MOTOR1 TIM3->CCR2 #define MOTOR2 TIM3->CCR1 -#define MOTOR_MAX 27360 -#define MOTOR_MIN 10080 -#define MOTOR_SETTING() {motor_PWM_Init(28800,5);MOTOR1 = MOTOR_MAX;delay(3000);MOTOR1 = MOTOR_MIN;delay(8000);} +#define MOTOR_MAX (unsigned short)27360 +#define MOTOR_MIN (unsigned short)10080 +#define MOTOR_SETTING() {\ + motor_PWM_Init(28800,5);\ + MOTOR1 = MOTOR_MAX;\ + delay(3000);\ + MOTOR1 = MOTOR_MIN;\ + delay(8000);\ +} void motor_PWM_Init(unsigned short arr, unsigned short psc); //72MHz / (arr + 1)*(psc + 1) diff --git a/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/src/uart.c b/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/src/uart.c index 7d3cdf1..839c724 100644 --- a/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/src/uart.c +++ b/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/src/uart.c @@ -40,10 +40,10 @@ void uart_showData(short k) { uart_sendData(k<0?'-':'+'); if(k<0) k=-k; e = (unsigned char)(k % 10); - d = (unsigned char)(k/10) % 10; - c = (unsigned char)(k/100) % 10; - b = (unsigned char)(k/1000) % 10; - a = (unsigned char)(k/10000); + d = (unsigned char)(k / 10 % 10); + c = (unsigned char)(k / 100 % 10); + b = (unsigned char)(k / 1000 % 10); + a = (unsigned char)(k / 10000); uart_sendData(a+'0'); uart_sendData(b+'0'); diff --git a/src/main.c b/src/main.c index 171b76b..a777379 100644 --- a/src/main.c +++ b/src/main.c @@ -32,7 +32,6 @@ void pid(float setPoint, float d) { short resu = (short)(g_iErro * K_P + g_sumErro * K_I + d * K_D); //PID输出 - if((MOTOR1 + resu) > MOTOR_MAX) MOTOR1 = MOTOR_MAX; else if((MOTOR1 + resu) < MOTOR_MIN)