#include "main.h"
#include "stm32f0xx_hal.h"
/* USER CODE BEGIN Includes */
int i=0;
/* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/
TIM_HandleTypeDef htim3;
UART_HandleTypeDef huart1;
/* 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_USART1_UART_Init(void);
static void MX_TIM3_Init(void);
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE END PFP */
/* USER CODE BEGIN 0 */
//Öжϴ¦Àí
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_1|GPIO_PIN_2);
}
//¶¨Ê±Æ÷×ÔÔöº¯Êý
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
i++;
}
/* 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_USART1_UART_Init();
MX_TIM3_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim3);
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
/*uint8_t data = 0;
HAL_UART_Receive(&huart1, &data, 1, 0);
if(data == 'l')
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2, GPIO_PIN_RESET);
HAL_UART_Transmit(&huart1, &data, 1, 0);
}
else if(data == 'h')
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2, GPIO_PIN_SET);
HAL_UART_Transmit(&huart1, &data, 1, 0);
} */
int j;
for(j=100;j>=50;j--)
{
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_3, j);
HAL_Delay(15);
}
for(j=50;j<=100;j++)
{
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_3, j);
HAL_Delay(15);
}
}
/* USER CODE END 3 */
}
上一篇:STM32总结一 STM32三种点亮LED灯方式的不同之处
下一篇:stm32 PUSH 按键控制LED闪烁
推荐阅读最新更新时间:2024-03-16 16:27