完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
为什么一加入tim7的时钟使能程序就跑不了了。。。
下面是外设配置相关代码: #include void BSP_Init() { RCC_Configuration(); LED_Configuration(); Voice_Configuration(); KEY_Configuration(); TIM7_Configuration(); Buzz_Configuration(); TIM6_Configuration(); USART_GPIO_Configuration(); USART_Config(USART1, 9600); USART_Config(USART2, 9600); USART_Config(USART3, 9600); USART_Config(UART4, 115200); USART_Config(UART5, 9600); NVIC_Configuration(); } /************************************************************************************* Function: //RCC_Configuration Description: //配置外设和GPIO口时钟 Calls: //None Called By: //main Input: //None Output: //None Return: //None *************************************************************************************/ static void RCC_Configuration(void) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7 | RCC_APB1Periph_TIM6 | RCC_APB1Periph_USART2 | RCC_APB1Periph_USART3 | RCC_APB1Periph_UART4 | RCC_APB1Periph_UART5, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_USART1, ENABLE); } /******************************************************************************* * Function Name : LED_Configuration * Description : Configure LED Pin * Input : None * Output : None * Return : None * Attention : None *******************************************************************************/ static void LED_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB , ENABLE); /** * LED1 -> PB0 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); } /************************************************************************************* Function: //NVIC_Configuration Description: //配置中断向量表 Calls: //None Called By: //main Input: //None Output: //None Return: //None *************************************************************************************/ static void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn | USART2_IRQn | USART3_IRQn | UART4_IRQn | UART5_IRQn | TIM6_IRQn | TIM7_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } /************************************************************************************* Function: //KEY_Configuration Description: //配置控制按键的IO口 Calls: //None Called By: //None Input: //None Output: //None Return: //None *************************************************************************************/ static void KEY_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //按键5 /*配置成上拉电阻输入模式*/ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //按键4 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //按键3 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; //按键2 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //按键1 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOE, &GPIO_InitStructure); } /************************************************************************************* Function: //TIM7_Configuration Description: //配置基本定时器7 Calls: //None Called By: //None Input: //None Output: //None Return: //None *************************************************************************************/ static void TIM7_Configuration(void) { TIM_TimeBaseInitTypeDef TIM_TimBaseStructure; TIM_TimBaseStructure.TIM_Period = 3000; TIM_TimBaseStructure.TIM_Prescaler = 1100; TIM_TimBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM7, &TIM_TimBaseStructure); TIM_ClearFlag(TIM7, TIM_FLAG_Update); TIM_ITConfig(TIM7, TIM_IT_Update, ENABLE); TIM_Cmd(TIM7, ENABLE); } /************************************************************************** Function: //Buzz_Configuration Description: //蜂鸣器连接的IO引脚配置函数 Calls: //None Called By: //main Input: //None Output: //None Return: //None ***************************************************************************/ static void Buzz_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; /*选择要控制的GPIOA1引脚*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; /*设置引脚模式为通用推挽输出*/ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; /*设置引脚速率为50MHz */ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /*调用库函数,初始化GPIOA*/ GPIO_Init(GPIOA, &GPIO_InitStructure); } /************************************************************************** Function: //TIM6_Configuration Description: //基本定时器Tim6的配置函数 Calls: //None Called By: //main Input: //None Output: //None Return: //None ***************************************************************************/ static void TIM6_Configuration(void) { TIM_TimeBaseInitTypeDef TIM_TimBaseStructure; /*设置计数器溢出大小,每3000+1个数产生一个更新事件*/ TIM_TimBaseStructure.TIM_Period = 3000; /*预分频系数为1100+1,计数器时钟为72MHz/1101*/ TIM_TimBaseStructure.TIM_Prescaler = 1100; /*设置时钟分割,TIM_CKD_DIV1=0不分割*/ TIM_TimBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; /*设置计数器模式为向上计数模式*/ TIM_TimBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; /*调用库函数,初始化TIM6*/ TIM_TimeBaseInit(TIM6, &TIM_TimBaseStructure); /*清除标志位*/ TIM_ClearFlag(TIM6, TIM_FLAG_Update); /*使能中断*/ TIM_ITConfig(TIM6, TIM_IT_Update, ENABLE); /*使能计数器*/ TIM_Cmd(TIM6, ENABLE); } 下面是主函数相关代码: /* Includes ------------------------------------------------------------------*/ #include /* Private variables ---------------------------------------------------------*/ static OS_STK App_TaskStartStk[APP_TASK_START_STK_SIZE]; /* Private function prototypes -----------------------------------------------*/ static void App_TaskStart (void *p_arg); /* ********************************************************************************************************* * main() * * Description : This is the standard entry point for C code. It is assumed that your code will call * main() once you have performed all necessary initialization. * * Argument(s) : none. * * Return(s) : none. ********************************************************************************************************* */ INT32S main (void) { CPU_INT08U os_err; os_err = os_err; /* prevent warning... */ /* Note: 由于使用UCOS, 在OS运行之前运行,注意别使能任何中断. */ CPU_IntDis(); /* Disable all ints until we are ready to accept them. */ OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel". */ os_err = OSTaskCreateExt((void (*)(void *)) App_TaskStart, /* Create the start task. */ (void * ) 0, (OS_STK * )&App_TaskStartStk[APP_TASK_START_STK_SIZE - 1], (INT8U ) APP_TASK_START_PRIO, (INT16U ) APP_TASK_START_PRIO, (OS_STK * )&App_TaskStartStk[0], (INT32U ) APP_TASK_START_STK_SIZE, (void * )0, (INT16U )(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK)); #if OS_TASK_NAME_EN > 0 OSTaskNameSet(APP_TASK_START_PRIO, (CPU_INT08U *)"Start Task", &os_err); #endif OSStart(); /* Start multitasking (i.e. give control to uC/OS-II). */ return (0); } /* ********************************************************************************************************* * App_TaskStart() * * Description : The startup task. The uC/OS-II ticker should only be initialize once multitasking starts. * * Argument(s) : p_arg Argument passed to 'App_TaskStart()' by 'OSTaskCreate()'. * * Return(s) : none. * * Caller(s) : This is a task. * * Note(s) : none. ********************************************************************************************************* */ static void App_TaskStart (void *p_arg) { (void)p_arg; /*************** Init hardware ***************/ BSP_Init(); OS_CPU_SysTickInit(); /* Initialize the SysTick. */ #if (OS_TASK_STAT_EN > 0) OSStatInit(); /* Determine CPU capacity. */ #endif App_TaskCreate(); /* Create application tasks. */ for(;;) { OSTimeDlyHMSM(0, 1, 0, 0); /* Delay One minute */ } } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %drn", file, line) */ /* Infinite loop */ while (1) { } } #endif /********************************************************************************************************* END FILE *********************************************************************************************************/ |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
UCOSII中断中添加OSSemPost(Sem);程序无法运行
5010 浏览 1 评论
在BC5.0上编译uC/OS-II出现"eeror writing object file",怎样处理???
3224 浏览 1 评论
598浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-26 19:25 , Processed in 0.486052 second(s), Total 82, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号