完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
新手求助。
STM32F103C8T6最小系统板,使用stmubeide编写程序,系统时钟配置72M,配置了一个GPIO用来控制LED灯。用了三种方式进行延时(1.for 循环 2.hal 延时函数 3.定时器 延时)控制led亮灭,无论哪种方式,从示波器上看,0.425秒以内程序还能正常运行,一到0.425秒,程序就从头开始开始执行了。 就配置了时钟,GPIO和定时器1,其余没有配置。 不知是哪里出了问题,请教各位大神! 以下是main.c 内容: / USER CODE BEGIN Header //**
include "main.h" / Private includes ----------------------------------------------------------// USER CODE BEGIN Includes / / USER CODE END Includes / / Private typedef -----------------------------------------------------------// USER CODE BEGIN PTD / / USER CODE END PTD / / Private define ------------------------------------------------------------// USER CODE BEGIN PD / / USER CODE END PD / / Private macro -------------------------------------------------------------// USER CODE BEGIN PM / / USER CODE END PM / / Private variables ---------------------------------------------------------/TIM_HandleTypeDef htim1; / USER CODE BEGIN PV / / USER CODE END PV / / Private function prototypes -----------------------------------------------/void SystemClock_Config(void);static void MX_GPIO_Init(void);static void MX_TIM1_Init(void);/ USER CODE BEGIN PFP / / USER CODE END PFP / / Private user code ---------------------------------------------------------// USER CODE BEGIN 0 / / USER CODE END 0 / /**
/ 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_TIM1_Init();/ USER CODE BEGIN 2 / void HAL_Delay_us(uint16_t us){uint16_t counter = 0;HAL_TIM_SetAutoreload( htim1, us); //设置定时器自动加载值HAL_TIM_SetCounter( htim1, counter); //设置定时器初始值HAL_TIM_Base_Start( htim1); //启动定时器 while(counter != us) //直到定时器计数从0计数到us结束循环,刚好是所需要的时间{counter = __HAL_TIM_GetCounter( htim1); // 获取定时器当前计数}HAL_TIM_Base_Stop( htim1); // 停止定时器} void HAL_Delay_ms(uint16_t ms){for (int i = 0; i < ms; i++)HAL_Delay_us(1000);} void delay(int ms){for(int i = 0; i < ms; i++)for(int j = 0; j < 1000; j++);} / USER CODE END 2 / / Infinite loop // USER CODE BEGIN WHILE /int a = 0;while (1){// HAL_Delay(100); // delay(1000);//// a %= 3;//// switch(a++)// {// case 0 : HAL_GPIO_TogglePin(LED1_GPIO_Port,LED1_Pin); break;// case 1 : HAL_GPIO_TogglePin(LED2_GPIO_Port,LED2_Pin); break;// case 2 : HAL_GPIO_TogglePin(LED3_GPIO_Port,LED3_Pin); break;// default: break;// }HAL_Delay_ms(300);// a += 1;// a++;// if (a == 3)// {// a = 0;// }HAL_GPIO_TogglePin(LED1_GPIO_Port,LED1_Pin);HAL_GPIO_TogglePin(LED2_GPIO_Port,LED2_Pin);HAL_GPIO_TogglePin(LED3_GPIO_Port,LED3_Pin);// HAL_Delay(300);// HAL_GPIO_WritePin(LED1_GPIO_Port,LED1_Pin , GPIO_PIN_SET);// HAL_GPIO_WritePin(LED2_GPIO_Port,LED2_Pin , GPIO_PIN_SET);// HAL_GPIO_WritePin(LED3_GPIO_Port,LED3_Pin , GPIO_PIN_SET);// HAL_Delay(300);// HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);// HAL_GPIO_WritePin(LED2_GPIO_Port,LED2_Pin , GPIO_PIN_SET);// HAL_GPIO_WritePin(LED3_GPIO_Port,LED3_Pin , GPIO_PIN_SET); / USER CODE END WHILE / / USER CODE BEGIN 3 /}/ USER CODE END 3 /} /**
if (HAL_RCC_ClockConfig( RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK){Error_Handler();}} /**
/ USER CODE END TIM1_Init 0 / TIM_ClockConfigTypeDef sClockSourceConfig = {0};TIM_MasterConfigTypeDef sMasterConfig = {0}; / USER CODE BEGIN TIM1_Init 1 / / USER CODE END TIM1_Init 1 /htim1.Instance = TIM1;htim1.Init.Prescaler = 71;htim1.Init.CounterMode = TIM_COUNTERMODE_UP;htim1.Init.Period = 0;htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;htim1.Init.RepetitionCounter = 0;htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;if (HAL_TIM_Base_Init( htim1) != HAL_OK){Error_Handler();}sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;if (HAL_TIM_ConfigClockSource( htim1, sClockSourceConfig) != HAL_OK){Error_Handler();}sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;if (HAL_TIMEx_MasterConfigSynchronization( htim1, sMasterConfig) != HAL_OK){Error_Handler();}/ USER CODE BEGIN TIM1_Init 2 / / USER CODE END TIM1_Init 2 / } /**
/Configure GPIO pin Output Level /HAL_GPIO_WritePin(GPIOA, LED2_Pin|LED3_Pin, GPIO_PIN_RESET); /Configure GPIO pin Output Level /HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET); /Configure GPIO pins : LED2_Pin LED3_Pin /GPIO_InitStruct.Pin = LED2_Pin|LED3_Pin;GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;HAL_GPIO_Init(GPIOA, GPIO_InitStruct); /Configure GPIO pin : LED1_Pin /GPIO_InitStruct.Pin = LED1_Pin;GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;HAL_GPIO_Init(LED1_GPIO_Port, GPIO_InitStruct); / USER CODE BEGIN MX_GPIO_Init_2 // USER CODE END MX_GPIO_Init_2 /} / USER CODE BEGIN 4 / / USER CODE END 4 / /**
/**
|
|
相关推荐
1个回答
|
|
看不到main()主函数和主函数内的while();这样运行一次当然就跑飞了。
|
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1786 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1622 浏览 1 评论
1089 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
730 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1680 浏览 2 评论
1942浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
739浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
576浏览 3评论
599浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
561浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-25 19:29 , Processed in 0.843879 second(s), Total 79, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号