完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
查了很多资料,但是在逻辑分析仪里怎么也没有波形,都快疯了,大家帮忙看看 谢谢。这是程序
#include "STM32f10x.h" #include "rcc_init.h" vu16 CCR1_Val = 40000; vu16 CCR2_Val = 20000; vu16 CCR3_Val = 10000; vu16 CCR4_Val = 5000; void RCC_Configuration(void); void GPIO_Configuration(void); void NVIC_Configuration(void); void TIM_Configuration(void); int main(void) { RCC_Configuration(); NVIC_Configuration(); GPIO_Configuration(); TIM_Configuration(); while (1); } void RCC_Configuration(void) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA , ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 , ENABLE); } void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); } void TIM_Configuration(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2 , &TIM_TimeBaseStructure); TIM_PrescalerConfig(TIM2 , 3199 , TIM_PSCReloadMode_Immediate); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OCInitStructure.TIM_Pulse = CCR1_Val; TIM_OC1Init(TIM2, &TIM_OCInitStructure); TIM_OCInitStructure.TIM_Pulse = CCR2_Val; TIM_OC2Init(TIM2, &TIM_OCInitStructure); TIM_OCInitStructure.TIM_Pulse = CCR3_Val; TIM_OC3Init(TIM2, &TIM_OCInitStructure); TIM_OCInitStructure.TIM_Pulse = CCR4_Val; TIM_OC4Init(TIM2, &TIM_OCInitStructure); TIM_OC1PreloadConfig(TIM2 , TIM_OCPreload_Disable); TIM_OC2PreloadConfig(TIM2 , TIM_OCPreload_Disable); TIM_OC3PreloadConfig(TIM2 , TIM_OCPreload_Disable); TIM_OC4PreloadConfig(TIM2 , TIM_OCPreload_Disable); TIM_ITConfig(TIM2 , TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 | TIM_IT_CC4 , ENABLE); TIM_Cmd(TIM2 , ENABLE); } void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } 这是中断程序 void TIM2_IRQHandler(void) { u16 capture = 0; if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET) { TIM_ClearITPendingBit(TIM2, TIM_IT_CC1 ); capture = TIM_GetCapture1(TIM2); TIM_SetCompare1(TIM2, capture + CCR1_Val ); } if (TIM_GetITStatus(TIM2, TIM_IT_CC2) != RESET) { TIM_ClearITPendingBit(TIM2, TIM_IT_CC2); capture = TIM_GetCapture2(TIM2); TIM_SetCompare2(TIM2, capture + CCR2_Val); } if (TIM_GetITStatus(TIM2, TIM_IT_CC3) != RESET) { TIM_ClearITPendingBit(TIM2, TIM_IT_CC3); capture = TIM_GetCapture3(TIM2); TIM_SetCompare3(TIM2, capture + CCR3_Val); } if (TIM_GetITStatus(TIM2, TIM_IT_CC4) != RESET) { TIM_ClearITPendingBit(TIM2, TIM_IT_CC4); capture = TIM_GetCapture4(TIM2); TIM_SetCompare4(TIM2, capture + CCR4_Val); } } |
|
相关推荐
2个回答
|
|
先谢谢大家了, 真是愁死人了。
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
如何用OpenCV的相机捕捉视频进行人脸检测--基于米尔NXP i.MX93开发板
594 浏览 0 评论
《DNK210使用指南 -CanMV版 V1.0》第四十章 YOLO2人手检测实验
449 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-网络编程示例之开发板测试
395 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-网络编程示例之网络socket程序编程
895 浏览 0 评论
飞凌嵌入式-ELFBOARD-RGB LCD屏接口的PCB设计要点
895 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11728 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-17 03:21 , Processed in 0.552273 second(s), Total 83, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号