我在使用计时器生成脉冲序列时,想在Keil微视觉5中改变代码中的频率:- int main(void)
- {
- /* USER CODE BEGIN 1 */
- uint16_t Prescaler=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();
- MX_TIM1_Init();
- /* USER CODE BEGIN 2 */
- HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
- /* USER CODE END 2 */
- /* Infinite loop */
- /* USER CODE BEGIN WHILE */
- while (1)
- {
- htim1.Instance->PSC = Prescaler;
- Prescaler+=1;
- if(Prescaler>80) Prescaler=1;
- HAL_Delay(500);
- /* USER CODE END WHILE */
- /* USER CODE BEGIN 3 */
- }
- /* USER CODE END 3 */
- }
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>