|
|
#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>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>λ |
|
|
|
|
|
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>TIM<EFBFBD>жϷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:TIM <EFBFBD>ж<EFBFBD>Դ |
|
|
{ |
|
|
TIM_ClearITPendingBit(TIM3, TIM_IT_Update ); //<EFBFBD><EFBFBD><EFBFBD>TIMx<EFBFBD><EFBFBD><EFBFBD>жϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ:TIM <EFBFBD>ж<EFBFBD>Դ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
* @description: Pwm |
|
|
* @param {u16} arr |
|
|
* @param {u16} psc |
|
|
* @return {*} |
|
|
*/ |
|
|
void TIM3_PWM_Init(u16 arr,u16 psc) |
|
|
{ |
|
|
GPIO_InitTypeDef GPIO_InitStructure; |
|
|
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
|
|
TIM_OCInitTypeDef TIM_OCInitStructure; |
|
|
|
|
|
|
|
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //ʹÄܶ¨Ê±Æ÷3ʱÖÓ |
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); //ʹÄÜGPIOÍâÉèºÍAFIO¸´Óù¦ÄÜÄ£¿éʱÖÓ |
|
|
|
|
|
GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3, ENABLE); //Timer3²¿·ÖÖØÓ³Éä TIM3_CH2->PB5 |
|
|
|
|
|
//ÉèÖøÃÒý½ÅΪ¸´ÓÃÊä³ö¹¦ÄÜ,Êä³öTIM3 CH2µÄPWMÂö³å²¨ÐÎ GPIOB.5 |
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //TIM_CH2 |
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸´ÓÃÍÆÍìÊä³ö |
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
|
|
GPIO_Init(GPIOB, &GPIO_InitStructure);//³õʼ»¯GPIO |
|
|
|
|
|
//³õʼ»¯TIM3 |
|
|
TIM_TimeBaseStructure.TIM_Period = arr; //ÉèÖÃÔÚÏÂÒ»¸ö¸üÐÂʼþ×°Èë»î¶¯µÄ×Ô¶¯ÖØ×°ÔؼĴæÆ÷ÖÜÆÚµÄÖµ |
|
|
TIM_TimeBaseStructure.TIM_Prescaler =psc; //ÉèÖÃÓÃÀ´×÷ΪTIMxʱÖÓƵÂʳýÊýµÄÔ¤·ÖƵֵ |
|
|
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //ÉèÖÃʱÖÓ·Ö¸î:TDTS = Tck_tim |
|
|
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIMÏòÉϼÆÊýģʽ |
|
|
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //¸ù¾ÝTIM_TimeBaseInitStructÖÐÖ¸¶¨µÄ²ÎÊý³õʼ»¯TIMxµÄʱ¼ä»ùÊýµ¥Î» |
|
|
|
|
|
//³õʼ»¯TIM3 Channel2 PWMģʽ |
|
|
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //Ñ¡Ôñ¶¨Ê±Æ÷ģʽ:TIMÂö³å¿í¶Èµ÷ÖÆģʽ2 |
|
|
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±È½ÏÊä³öʹÄÜ |
|
|
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //Êä³ö¼«ÐÔ:TIMÊä³ö±È½Ï¼«ÐÔ¸ß |
|
|
TIM_OC2Init(TIM3, &TIM_OCInitStructure); //¸ù¾ÝTÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèTIM3 OC2 |
|
|
|
|
|
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable); //ʹÄÜTIM3ÔÚCCR2ÉϵÄԤװÔؼĴæÆ÷ |
|
|
|
|
|
TIM_Cmd(TIM3, ENABLE); //ʹÄÜTIM3 |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|