141 lines
5.0 KiB
C
141 lines
5.0 KiB
C
#include "main.h"
|
|
#include "stm32f4xx_exti.h"
|
|
|
|
char Key_Cal_Flag = 0; // 重新配网
|
|
char key_opm_flg = 0; // 光功校准
|
|
|
|
// GPIO初始化
|
|
/*******************************************************************************/
|
|
void GPIO_Set_Init(void)
|
|
{
|
|
GPIOA_Init();
|
|
GPIOB_Init();
|
|
GPIOC_Init();
|
|
}
|
|
|
|
// GPIOA初始化
|
|
/*******************************************************************************/
|
|
void GPIOA_Init(void)
|
|
{
|
|
}
|
|
// GPIOB初始化
|
|
// LED_B-PB0--下拉灯亮--上拉输出
|
|
// LED_G-PB1--下拉灯亮--上拉输出
|
|
// LED_R-PB2--下拉灯亮--上拉输出
|
|
// OP1_A-PB8--组合有效--上拉输出
|
|
// OP1_B-PB9--组合有效--上拉输出
|
|
/*******************************************************************************/
|
|
void GPIOB_Init(void)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); //使能GPIOB时钟
|
|
|
|
//初始化设置
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //普通输出模式
|
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽输出
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; // 100MHz
|
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
|
|
GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化
|
|
|
|
GPIO_SetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2); //设置高,灯灭
|
|
}
|
|
// GPIOC初始化
|
|
// Dis_1310-PC1--上拉有效--上拉输出
|
|
// HOLD-PC4--上拉有效--上拉输出
|
|
/*******************************************************************************/
|
|
void GPIOC_Init(void)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); //使能GPIOC时钟
|
|
|
|
//初始化设置
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_4;
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //普通输出模式
|
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽输出
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; // 100MHz
|
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
|
|
GPIO_Init(GPIOC, &GPIO_InitStructure); //初始化
|
|
|
|
GPIO_SetBits(GPIOC, GPIO_Pin_1 | GPIO_Pin_4);
|
|
}
|
|
void WIFI_Reset(void)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); //使能GPIOB时钟
|
|
|
|
//初始化设置
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //普通输出模式
|
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽输出
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; // 100MHz
|
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
|
|
GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化
|
|
|
|
WIFI_RESET = 0;
|
|
delay_ms(50);
|
|
WIFI_RESET = 1;
|
|
delay_ms(50);
|
|
WIFI_RESET = 0;
|
|
delay_ms(50);
|
|
WIFI_RESET = 1;
|
|
delay_ms(50);
|
|
}
|
|
// 中断初始化
|
|
// KEY_CAL-PB10--按下置低--无上下拉输入
|
|
// KEY_WPS-PB11--按下置低--无上下拉输入
|
|
/*******************************************************************************/
|
|
void EXTI_Set_Init(void)
|
|
{
|
|
// EXTI_InitTypeDef EXTI_InitStruct;
|
|
// NVIC_InitTypeDef NVIC_InitStructure;
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); //使能SYSCFG时钟
|
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); //使能GPIOB时钟
|
|
// SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource10); // PB10,KEY_CAL连接中断线10
|
|
// SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource11); // PB11,KEY_WPS连接中断线11
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; // KEY1 KEY0 对应引脚
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //普通输入模式
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; // 100M
|
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //不上拉
|
|
GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化PB10,PB11
|
|
|
|
// EXTI_InitStruct.EXTI_Line = EXTI_Line10;
|
|
// EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling; // KEY_CAL下降沿触发
|
|
// EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt; //中断模式
|
|
// EXTI_InitStruct.EXTI_LineCmd = ENABLE;
|
|
// EXTI_Init(&EXTI_InitStruct);
|
|
|
|
// EXTI_InitStruct.EXTI_Line = EXTI_Line11;
|
|
// EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling; // KEY_WPS下降沿触发
|
|
// EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt; //中断模式
|
|
// EXTI_InitStruct.EXTI_LineCmd = ENABLE;
|
|
// EXTI_Init(&EXTI_InitStruct);
|
|
|
|
// NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //外部中断4
|
|
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x03; //抢占优先级3
|
|
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; // 响应优先级2
|
|
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断
|
|
// NVIC_Init(&NVIC_InitStructure); //配置NVIC
|
|
}
|
|
|
|
//中断服务函数
|
|
void EXTI15_10_IRQHandler(void)
|
|
{
|
|
if (EXTI_GetITStatus(EXTI_Line10) != RESET)
|
|
{
|
|
Key_Cal_Flag = 1;
|
|
EXTI_ClearITPendingBit(EXTI_Line10);
|
|
}
|
|
if (EXTI_GetITStatus(EXTI_Line11) != RESET)
|
|
{
|
|
key_opm_flg = 1;
|
|
EXTI_ClearITPendingBit(EXTI_Line11);
|
|
}
|
|
}
|