- /*****************************************************************************
- * Copyright (c) 2019, Nations Technologies Inc.
- *
- * All rights reserved.
- * ****************************************************************************
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the disclaimer below.
- *
- * Nations' name may not be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
- * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * ****************************************************************************/
- /**
- * [url=home.php?mod=space&uid=288409]@file[/url] main.c
- * [url=home.php?mod=space&uid=187600]@author[/url] Nations
- * [url=home.php?mod=space&uid=895143]@version[/url] v1.0.0
- *
- * [url=home.php?mod=space&uid=17282]@CopyRight[/url] Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
- */
- #include <stdio.h>
- #include "main.h"
- /** @addtogroup N32G45X_StdPeriph_Examples
- * @{
- */
- /** @addtogroup USART_Printf
- * @{
- */
- typedef enum
- {
- FAILED = 0,
- PASSED = !FAILED
- } TestStatus;
- #define countof(a) (sizeof(a) / sizeof(*(a)))
- USART_InitType USART_InitStructure;
- void RCC_Configuration(void);
- void GPIO_Configuration(void);
- TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength);
- uint8_t get_1byte(void);
- void stop(void)
- {
- GPIOE->PBC = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_2|GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_5;
- }
- void up(void)
- {
- GPIOE->PBSC = GPIO_PIN_10;
- GPIOE->PBC = GPIO_PIN_12;
-
- GPIOE->PBSC = GPIO_PIN_11;
- GPIOE->PBC = GPIO_PIN_13;
- GPIOE->PBSC = GPIO_PIN_2;
- GPIOE->PBC = GPIO_PIN_4;
- GPIOE->PBSC = GPIO_PIN_3;
- GPIOE->PBC = GPIO_PIN_5;
- }
- void down(void)
- {
- GPIOE->PBC = GPIO_PIN_10;
- GPIOE->PBSC = GPIO_PIN_12;
-
- GPIOE->PBC = GPIO_PIN_11;
- GPIOE->PBSC = GPIO_PIN_13;
- GPIOE->PBC = GPIO_PIN_2;
- GPIOE->PBSC = GPIO_PIN_4;
- GPIOE->PBC = GPIO_PIN_3;
- GPIOE->PBSC = GPIO_PIN_5;
- }
- void left(void)
- {
- GPIOE->PBSC = GPIO_PIN_10;
- GPIOE->PBC = GPIO_PIN_12;
-
- GPIOE->PBC = GPIO_PIN_11;
- GPIOE->PBC = GPIO_PIN_13;
- }
- void right(void)
- {
- GPIOE->PBC = GPIO_PIN_10;
- GPIOE->PBC = GPIO_PIN_12;
-
- GPIOE->PBSC = GPIO_PIN_11;
- GPIOE->PBC = GPIO_PIN_13;
- }
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] Main program
- */
- int main(void)
- {
- uint8_t x;
- uint8_t cmd[15];
- unsigned int i=0;
- /* System Clocks Configuration */
- RCC_Configuration();
- /* Configure the GPIO ports */
- GPIO_Configuration();
- /* USARTy and USARTz configuration ------------------------------------------------------*/
- USART_InitStructure.BaudRate = 9600;
- USART_InitStructure.WordLength = USART_WL_8B;
- USART_InitStructure.StopBits = USART_STPB_1;
- USART_InitStructure.Parity = USART_PE_NO;
- USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE;
- USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX;
- /* Configure USARTx */
- USART_Init(USARTx, &USART_InitStructure);
- /* Enable the USARTx */
- USART_Enable(USARTx, ENABLE);
- printf("Hello MyCar\n");
-
-
-
-
- while (1)
- {
- while(get_1byte()=='{')
- {
- cmd[0] = '{';
- for(i=1;i<15;i++)
- cmd[i] = get_1byte();
- if(cmd[14]=='}')
- {
- x=cmd[12];
- switch(x)
- {
- case 'U':
- up();
- printf("UP\n");
- break;
- case 'D':
- down();
- printf("DOWN\n");
- break;
- case 'L':
- left();
- printf("LEFT\n");
- break;
- case 'R':
- right();
- printf("RIGHT\n");
- break;
- case 'S':
- stop();
- printf("STOP\n");
- break;
- }
- }
- }
- }
- }
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] Configures the different system clocks.
- */
- void RCC_Configuration(void)
- {
- /* Enable GPIO clock */
- GPIO_APBxClkCmd(USARTx_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE);
- /* Enable USARTy and USARTz Clock */
- USART_APBxClkCmd(USARTx_CLK, ENABLE);
- }
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] Configures the different GPIO ports.
- */
- void GPIO_Configuration(void)
- {
- GPIO_InitType GPIO_InitStructure;
- /* Configure USARTx Tx as alternate function push-pull */
- GPIO_InitStructure.Pin = USARTx_TxPin;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure);
- /* Configure USARTx Rx as input floating */
- GPIO_InitStructure.Pin = USARTx_RxPin;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure);
-
- /*
- 对使用的IO进行初始化
- */
- RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOE, ENABLE);
- GPIO_InitStructure.Pin = GPIO_PIN_10|GPIO_PIN_12|GPIO_PIN_11|GPIO_PIN_13|GPIO_PIN_2|GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_5;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitPeripheral(GPIOE, &GPIO_InitStructure);
- }
- /**
- * @brief Compares two buffers.
- * @param pBuffer1, pBuffer2: buffers to be compared.
- * @param BufferLength buffer's length
- * [url=home.php?mod=space&uid=266161]@return[/url] PASSED: pBuffer1 identical to pBuffer2
- * FAILED: pBuffer1 differs from pBuffer2
- */
- TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength)
- {
- while (BufferLength--)
- {
- if (*pBuffer1 != *pBuffer2)
- {
- return FAILED;
- }
- pBuffer1++;
- pBuffer2++;
- }
- return PASSED;
- }
- uint8_t get_1byte(void)
- {
- uint8_t ch;
- while (USART_GetFlagStatus(USARTx, USART_FLAG_RXDNE) == RESET)
- {
- }
- ch = (USART_ReceiveData(USARTx)&0xFF);
- // printf("%c",ch);
- return ch;
- }
- /* retarget the C library printf function to the USART */
- int fputc(int ch, FILE* f)
- {
- USART_SendData(USARTx, (uint8_t)ch);
- while (USART_GetFlagStatus(USARTx, USART_FLAG_TXDE) == RESET)
- ;
- return (ch);
- }
- #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
- */
- void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line)
- {
- /* 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) */
- /* Infinite loop */
- while (1)
- {
- }
- }
- #endif
- /**
- * @}
- */
- /**
- * @}
- */
MyCar_Printf.zip
(1.26 MB, 下载次数: 13)
B站视频链接,因为手机又要拍照,又要遥控,所以比较尴尬。
https://www.bilibili.com/video/BV1i44y1M7LR/
手机端软件是我自己编写的,已经开源,请到上位机板块查找,这里提供编译好的
MyCar.zip
(550.45 KB, 下载次数: 10)
四驱纸糊车,蓝牙遥控。