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.

66 lines
1.9 KiB

3 years ago
#include "timer.h"
#include "led.h"
#include "wifi.h"
extern char smog_value_buf[7]; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ũ<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD>
extern char temp_value_buf[7]; //<EFBFBD><EFBFBD><EFBFBD>ֵ
extern char beam_value_buf[7]; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><EFBFBD>ֵ
//ͨ<EFBFBD>ö<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>жϳ<EFBFBD>ʼ<EFBFBD><EFBFBD>
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>ΪAPB1<EFBFBD><EFBFBD>2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>APB1Ϊ36M
//arr<EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD>װֵ<EFBFBD><EFBFBD>
//psc<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD><EFBFBD>Ƕ<EFBFBD>ʱ<EFBFBD><EFBFBD>3!
void TIM3_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //ʱ<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>
TIM_TimeBaseStructure.TIM_Period = arr; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD>ؼĴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ֵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5000Ϊ500ms
TIM_TimeBaseStructure.TIM_Prescaler =psc; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪTIMxʱ<EFBFBD><EFBFBD>Ƶ<EFBFBD>ʳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>Ƶֵ 10Khz<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ӷָ<EFBFBD>:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM<EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><EFBFBD><EFBFBD>ģʽ
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>TIM_TimeBaseInitStruct<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>TIMx<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
TIM_ITConfig( //ʹ<EFBFBD>ܻ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>TIM<EFBFBD>ж<EFBFBD>
TIM3, //TIM2
TIM_IT_Update ,
ENABLE //ʹ<EFBFBD><EFBFBD>
);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3<EFBFBD>ж<EFBFBD>
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; //<EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>0<EFBFBD><EFBFBD>
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3<EFBFBD><EFBFBD>
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>
NVIC_Init(&NVIC_InitStructure); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>NVIC_InitStruct<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>NVIC<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
TIM_Cmd(TIM3, ENABLE); //ʹ<EFBFBD><EFBFBD>TIMx<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
//ÿ<EFBFBD><EFBFBD>300ms<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void TIM3_IRQHandler(void) //TIM3<EFBFBD>ж<EFBFBD>
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>TIM<EFBFBD>жϷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:TIM <EFBFBD>ж<EFBFBD>Դ
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update ); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>TIMx<EFBFBD><EFBFBD><EFBFBD>жϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ:TIM <EFBFBD>ж<EFBFBD>Դ
// ESP8266_send_data(temp_value_buf);
// ESP8266_send_data(smog_value_buf);
// ESP8266_send_data(beam_value_buf);
}
}