From 30d42fb106aa19aa25e9f380dc06750b8dc84711 Mon Sep 17 00:00:00 2001 From: but0n Date: Thu, 18 Aug 2016 15:49:02 +0800 Subject: [PATCH] [Edited]Coding standards:v: --- .../STM32F10x_StdPeriph_Driver/inc/uart.h | 8 +- .../STM32F10x_StdPeriph_Driver/src/uart.c | 28 +++--- src/main.c | 88 ++++++++++--------- 3 files changed, 64 insertions(+), 60 deletions(-) diff --git a/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc/uart.h b/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc/uart.h index 65ce366..9b33e5f 100644 --- a/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc/uart.h +++ b/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc/uart.h @@ -2,9 +2,9 @@ #ifndef _UART_H #define _UART_H -void initUART(unsigned int pclk2, unsigned int bound); -void sendData_uart(unsigned char data); -void showData(short k); -unsigned char Float2Char(float value); +void uart_init(unsigned int pclk2, unsigned int bound); +void uart_sendData(unsigned char data); +void uart_showData(short k); +unsigned char uart_Float2Char(float value); #endif 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 94b1a5e..02e8dbc 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 @@ -1,7 +1,7 @@ #include "uart.h" #include "stm32f10x.h" -void initUART(unsigned int pclk2, unsigned int bound) { +void uart_init(unsigned int pclk2, unsigned int bound) { float temp; unsigned short mantissa; unsigned short fraction; @@ -25,14 +25,16 @@ void initUART(unsigned int pclk2, unsigned int bound) { USART1->CR1 |= 1<<8; USART1->CR1 |= 1<<5; } -void sendData_uart(unsigned char data) { + +void uart_sendData(unsigned char data) { USART1->DR = data; while((USART1->SR & 0x40) == 0); } -void showData(short k) { + +void uart_showData(short k) { unsigned char a, b, c, d, e; - sendData_uart(k<0?'-':'+'); + uart_sendData(k<0?'-':'+'); if(k<0) k=-k; e = (unsigned char)(k % 10); d = (unsigned char)(k/10) % 10; @@ -40,15 +42,15 @@ void showData(short k) { b = (unsigned char)(k/1000) % 10; a = (unsigned char)(k/10000); - sendData_uart(a+0x30); - sendData_uart(b+0x30); - sendData_uart(c+0x30); - sendData_uart(d+0x30); - sendData_uart(e+0x30); - sendData_uart(' '); + uart_sendData(a+0x30); + uart_sendData(b+0x30); + uart_sendData(c+0x30); + uart_sendData(d+0x30); + uart_sendData(e+0x30); + uart_sendData(' '); } -unsigned char Float2Char(float value) { +unsigned char uart_Float2Char(float value) { unsigned char IntegerPart; float DecimalPart; unsigned char i = 0; @@ -59,7 +61,7 @@ unsigned char Float2Char(float value) { if(value < 0 ) { value = value * -1; - sendData_uart('-'); + uart_sendData('-'); } if(value >= 1) { IntegerPart = (unsigned char)value; @@ -97,7 +99,7 @@ unsigned char Float2Char(float value) { array[i++] = '\0'; for(j = 0; j < i; j ++) { - sendData_uart(array[j]); + uart_sendData(array[j]); } return i; diff --git a/src/main.c b/src/main.c index 03f1d3e..3476e03 100644 --- a/src/main.c +++ b/src/main.c @@ -5,6 +5,7 @@ #include "motor.h" #include "uart.h" +#include "wifi.h" #define Kp 100.0f //比例增益支配率(常量) #define Ki 0.002f //积分增益支配率 @@ -101,42 +102,45 @@ void Comput(SixAxis cache) { int main() { - initLED(); PWM_Init(7200,10); - initUART(72, 115200); + uart_init(72, 115200); MPU_init(); SixAxis sourceData; + wifi_init(); + MOTOR1 = 7190; MOTOR2 = 7190; + delay(3000); + while(1) { MPU6050_getStructData(&sourceData); Comput(sourceData); pid(0, sourceData.gX); - sendData_uart(' '); - sendData_uart('M'); - sendData_uart(':'); + uart_sendData(' '); + uart_sendData('M'); + uart_sendData(':'); - showData(MOTOR1); + uart_showData(MOTOR1); - sendData_uart(' '); - sendData_uart('r'); - sendData_uart(':'); - Float2Char(Roll); + uart_sendData(' '); + uart_sendData('r'); + uart_sendData(':'); + uart_Float2Char(Roll); - sendData_uart(' '); - sendData_uart('D'); - sendData_uart(':'); - Float2Char(sourceData.gX); - sendData_uart(0x0D); - sendData_uart(0x0A); + uart_sendData(' '); + uart_sendData('D'); + uart_sendData(':'); + uart_Float2Char(sourceData.gX); + uart_sendData(0x0D); + uart_sendData(0x0A); } while(1) { @@ -146,41 +150,39 @@ int main() { Comput(sourceData); - sendData_uart('P'); - sendData_uart('i'); - sendData_uart('t'); - sendData_uart('c'); - sendData_uart('h'); - sendData_uart(':'); - sendData_uart(' '); + uart_sendData('P'); + uart_sendData('i'); + uart_sendData('t'); + uart_sendData('c'); + uart_sendData('h'); + uart_sendData(':'); + uart_sendData(' '); - Float2Char(Pitch); - sendData_uart(' '); + uart_Float2Char(Pitch); + uart_sendData(' '); - sendData_uart('R'); - sendData_uart('o'); - sendData_uart('l'); - sendData_uart('l'); - sendData_uart(':'); - sendData_uart(' '); + uart_sendData('R'); + uart_sendData('o'); + uart_sendData('l'); + uart_sendData('l'); + uart_sendData(':'); + uart_sendData(' '); - Float2Char(Roll); - sendData_uart(' '); + uart_Float2Char(Roll); + uart_sendData(' '); - sendData_uart('Y'); - sendData_uart('a'); - sendData_uart('w'); - sendData_uart(':'); - sendData_uart(' '); + uart_sendData('Y'); + uart_sendData('a'); + uart_sendData('w'); + uart_sendData(':'); + uart_sendData(' '); - Float2Char(Yaw); + uart_Float2Char(Yaw); - sendData_uart(0x0D); - sendData_uart(0x0A); + uart_sendData(0x0D); + uart_sendData(0x0A); delay(100); - - } }