You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.9 KiB
65 lines
1.9 KiB
#include "timer.h" |
|
#include "led.h" |
|
#include "wifi.h" |
|
|
|
extern char smog_value_buf[7]; //存储烟雾浓度值,用于数据传输 |
|
extern char temp_value_buf[7]; //存储温度值 |
|
extern char beam_value_buf[7]; //存储光照强度值 |
|
|
|
|
|
//通用定时器中断初始化 |
|
//这里时钟选择为APB1的2倍,而APB1为36M |
|
//arr:自动重装值。 |
|
//psc:时钟预分频数 |
|
//这里使用的是定时器3! |
|
void TIM3_Int_Init(u16 arr,u16 psc) |
|
{ |
|
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
|
NVIC_InitTypeDef NVIC_InitStructure; |
|
|
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //时钟使能 |
|
|
|
TIM_TimeBaseStructure.TIM_Period = arr; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值 计数到5000为500ms |
|
TIM_TimeBaseStructure.TIM_Prescaler =psc; //设置用来作为TIMx时钟频率除数的预分频值 10Khz的计数频率 |
|
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //设置时钟分割:TDTS = Tck_tim |
|
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM向上计数模式 |
|
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //根据TIM_TimeBaseInitStruct中指定的参数初始化TIMx的时间基数单位 |
|
|
|
TIM_ITConfig( //使能或者失能指定的TIM中断 |
|
TIM3, //TIM2 |
|
TIM_IT_Update , |
|
ENABLE //使能 |
|
); |
|
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3中断 |
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; //先占优先级0级 |
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //从优先级3级 |
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道被使能 |
|
NVIC_Init(&NVIC_InitStructure); //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器 |
|
|
|
TIM_Cmd(TIM3, ENABLE); //使能TIMx外设 |
|
|
|
} |
|
|
|
//每隔300ms发送一次数据 |
|
void TIM3_IRQHandler(void) //TIM3中断 |
|
{ |
|
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //检查指定的TIM中断发生与否:TIM 中断源 |
|
{ |
|
TIM_ClearITPendingBit(TIM3, TIM_IT_Update ); //清除TIMx的中断待处理位:TIM 中断源 |
|
// ESP8266_send_data(temp_value_buf); |
|
// ESP8266_send_data(smog_value_buf); |
|
// ESP8266_send_data(beam_value_buf); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|