在线时间4854 小时
UID3309825
ST金币0
蝴蝶豆17
注册时间2016-9-4
论坛元老
- 最后登录
- 2020-12-9
|
楼主 |
发表于 2018-5-22 10:50:14
|
显示全部楼层
a0a.1 32b0c
本帖最后由 anywill 于 2018-5-22 14:57 编辑
#include "main.h"
#include "stm32f4xx_hal.h"
/* USER CODE BEGIN Includes */
#include "stdbool.h"
/* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart2;
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE END PFP */
/* USER CODE BEGIN 0 */
bool tempVar=true;
/* USER CODE END 0 */
/**
* @brief The application entry point.
*
* @retval None
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) {
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if (HAL_GPIO_ReadPin (GPIOC,GPIO_PIN_13)&&tempVar)//PC13 default high voltage
{
HAL_Delay(10);//contact stability
if(HAL_GPIO_ReadPin (GPIOC,GPIO_PIN_13))
{
HAL_GPIO_TogglePin (GPIOA,GPIO_PIN_5);
tempVar=false;
}
}
else if(HAL_GPIO_ReadPin (GPIOC,GPIO_PIN_13)==GPIO_PIN_RESET&&tempVar==false )//
{
HAL_Delay(10);//contact stability
if(HAL_GPIO_ReadPin (GPIOC,GPIO_PIN_13)==GPIO_PIN_RESET)
{
tempVar=true;
}
}
/* USER CODE END 3 */
}
}
|
|