欢迎来到天天文库
浏览记录
ID:1329008
大小:55.50 KB
页数:7页
时间:2017-11-10
《stm32红外通信模块,源代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Main.c#include"stm32f10x.h"#include"usart1.h"#include"adc.h"#include"Time_test.h"u32flag;u32f=0;volatileu32time=0;volatileu32time1=0;/*ADC1转换的电压值通过MDA方式传到SRAM*/extern__IOuint16_tADC_ConvertedValue;/*局部变量,用于保存转换计算后的电压值*/floatADC_ConvertedValueLocal;/*软件延时*/voidDelay(__IOuint32_tnCount){for(;nCount
2、!=0;nCount--);}intmain(void){SystemInit();/*USART1config*/USART1_Config();/*enableadc1andconfigadc1todmamode*/ADC1_Init();/*TIM2定时配置*/TIM2_NVIC_Configuration();TIM2_Configuration();TIM3_NVIC_Configuration();/*TIM2开始计时*/START_TIME;STOP_TIME3;while(1){}}Time_test.c#include"Time_test.h"voidTIM2_NVIC
3、_Configuration(void){NVIC_InitTypeDefNVIC_InitStructure;NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;NVIC_InitStructure.NVIC_IRQChannelSubPriority=4;NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;N
4、VIC_Init(&NVIC_InitStructure);}voidTIM3_NVIC_Configuration(void){NVIC_InitTypeDefNVIC_InitStructure;NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;NVIC_InitStructure.NVIC_IRQChannelSubPriority=3;NV
5、IC_InitStructure.NVIC_IRQChannelCmd=ENABLE;NVIC_Init(&NVIC_InitStructure);}/*TIM_Period--1000TIM_Prescaler--71-->中断周期为125us*/voidTIM2_Configuration(void){TIM_TimeBaseInitTypeDefTIM_TimeBaseStructure;RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);TIM_DeInit(TIM2);TIM_TimeBaseStructure.TIM_Peri
6、od=125;/*自动重装载寄存器周期的值(计数值),中断间隔125us*//*累计TIM_Period个频率后产生一个更新或者中断*/TIM_TimeBaseStructure.TIM_Prescaler=(56-1);/*时钟预分频数72M/72*/TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;/*采样分频*/TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;/*向上计数模式*/TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructu
7、re);TIM_ClearFlag(TIM2,TIM_FLAG_Update);/*清除溢出中断标志*/TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);TIM_Cmd(TIM2,DISABLE);/*开启时钟*/}voidTIM3_Configuration(u32top){TIM_TimeBaseInitTypeDefTIM_TimeBaseStructure;RCC_APB1PeriphClock
此文档下载收益归作者所有