609| 8
|
定时器中断实验 |
[/free][hide=3,money]用的是正点原子mini开发板stm32f103RCT6
************main函数************** #include "led.h" #include "usart.h" #include "exti.h" #include "key.h" #include "delay.h" #include "sys.h" int main(void) { delay_init(); LED_Init(); KEY_Init(); My_EXTIX_Init(); USART1_Init(9600); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //ÖжÏÓÅÏȼ¶·Ö×é ·Ö2×é My_TIM3_Init(4999,7199);//Tout=((4999+1)*(7199+1))/72M=500ms while(1) { LED0=!LED0; delay_ms(100);//ÏÖÏó£ºLED0ÉÁ˸½Ï¿ì¼ä¸ô100ms£¬LED1ÉÁ˸½ÏÂý¼ä¸ô500ms } } ********time.c************ #include "time.h" #include "led.h" void My_TIM3_Init(u16 arr,u16 psc) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;//ÏòÉϼÆÊýģʽ TIM_TimeBaseStructure.TIM_Period=arr; TIM_TimeBaseStructure.TIM_Prescaler=psc; TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure); TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);//ÔÊÐí¸üÐÂÖÐ¶Ï NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;//ÇÀÕ¼ÓÅÏȼ¶ NVIC_InitStructure.NVIC_IRQChannelSubPriority=3;//×ÓÓÅÏȼ¶ NVIC_Init(&NVIC_InitStructure); TIM_Cmd(TIM3,ENABLE);//ʹÄܶ¨Ê±Æ÷3 } void TIM3_IRQHandler(void) { if(TIM_GetITStatus(TIM3,TIM_IT_Update!=RESET)) { TIM_ClearITPendingBit(TIM3, TIM_IT_Update); LED1=!LED1; } } *********time.h*********** #ifndef _time_H #define _time_H #include "sys.h" void My_TIM3_Init(u16 arr,u16 psc); void TIM3_IRQHandler(void); #endif [/hide][free]
购买主题
本主题需向作者支付 3 枚金币 才能浏览
《《《 点击这里展开全文 》》》 | |
发表于 2020-12-17 07:39:56
|
显示全部楼层
| |
发表于 2020-12-17 08:14:35
|
显示全部楼层
| |
发表于 2020-12-17 08:29:41
|
显示全部楼层
| |
发表于 2020-12-17 08:46:40
|
显示全部楼层
| |
发表于 2020-12-17 08:51:16
|
显示全部楼层
| |
发表于 2020-12-17 08:52:46
|
显示全部楼层
| |
发表于 2020-12-17 08:57:22
|
显示全部楼层
| |
发表于 2020-12-17 09:39:03
|
显示全部楼层
| |