
#include "stm32f0xx_hal.h" void SystemClock_Config(void); static void MX_GPIO_Init(void); int main(void) { uint8_t x; HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); while (1) { x=HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13); if(x==0) { HAL_Delay(10); if(x==0) { HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET); } } else { HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET); } } } void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = 16; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12; RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV2; HAL_RCC_OscConfig(&RCC_OscInitStruct); RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1); __SYSCFG_CLK_ENABLE(); } void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; __GPIOC_CLK_ENABLE(); __GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_13; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); } #ifdef USE_FULL_ASSERT void assert_failed(uint8_t* file, uint32_t line) { } #endif |
KEY.zip
下载1.36 KB, 下载次数: 5
cubeæä»¶
版主自重,小心管理员拍死你,推了这么久
下倒是下成功了,不过不会玩,都是我技术烂,技术烂~