void Init_Dev(void)
{
//Rtc_Init();
Init_key();
Init_Set();
InitLight();
InitAUX();
InitFan();
InitDefrost();
InitComp();
BuzzInit();
GN1621_Dev_Init();
DS1302_IO_Init();
Ds1302_Init();
InitDoor();
uart_init2(9600);
uart_init1(9600);
HotKey_Dispy_Init();
uart_init3(9600);
Adc_Init();
SwitchInit();
CodeText();
TIM3_Mode_Config();
InitAlarm();
}
TIM3_Mode_Config();代码
//配置成PWM输出
void TIM3_Mode_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;//初始化TIM2的时间基数单位
TIM_OCInitTypeDef TIM_OCInitStructure;//初始化TIM2的外设
GPIO_InitTypeDef GPIO_InitStructure;
/*
关掉JTAD调式 PA15作为普通IO口
*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
//由于PA6是复用的所以要设置一下
//GPIO_PinRemapConfig(GPIO_FullRemap_TIM2, ENABLE);
//配置PA16 PWM输出的模式
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//打开TIM3的时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
//TIM2的时间基数单位设置(如计数终止值:999,从0开始 ;计数方式:向上计数)
#if INSIDE_RCC
TIM_TimeBaseStructure.TIM_Prescaler= (2 - 1); //时钟预分频数,时钟频率=64MHZ/(时钟预分频+1) 之后是8M
TIM_TimeBaseStructure.TIM_Period=3200-1; //自动重装载寄存器的值/ 10KHZ
#else
TIM_TimeBaseStructure.TIM_Prescaler= (9 - 1); //时钟预分频数,时钟频率=72MHZ/(时钟预分频+1) 之后是8M
TIM_TimeBaseStructure.TIM_Period=1000-1; //自动重装载寄存器的值/ 8KHZ
#endif
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
//TIM3的外设的设置
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //TIM脉冲宽度调制模式1
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;//这个暂时不知道,stm32固件库里没有搜到。应该是定时器输出声明使能的意思
TIM_OCInitStructure.TIM_Pulse = 500;//设置了待装入捕获比较寄存器的脉冲值
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //TIM输出比较极性高
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);//使能或者失能TIMx在CCR1上的预装载寄存器
TIM_ARRPreloadConfig(TIM3, ENABLE); //使能TIM2重载寄存器ARR
TIM_ClearFlag(TIM3, TIM_FLAG_Update); //清除溢出中断标志
TIM_Cmd(TIM3, ENABLE);//使能TIM2
}
InitAlarm();
代码
void InitAlarm(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE);
/*
关掉JTAD调式 PA15作为普通IO口
*/
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
//GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_ResetBits(GPIOB,GPIO_Pin_9);
}
|