姓名:艾志奇 日期:2018.07.27
今日学习任务 | 1、复习昨天内容 2、实现4个按键分别控制4个彩灯亮灭 |
今日任务完成情况 | 均完成 |
今日开发问题汇总 | 无 |
今日未解决问题 | 如何将蜂鸣加入红灯中而且使得红灯闪烁 |
今日开发收获 | 了解掌握了如何使用固件函数库 |
自我评价 | 良好 |
其他 | |
作业 这里给出key文件代码,led部分与之类似,多用三个结构体完成
#include "bsp_key.h"
void Key_Exti_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure0;
EXTI_InitTypeDef EXTI_InitStructure0;
NVIC_InitTypeDef NVIC_InitStructure0;//3
GPIO_InitTypeDef GPIO_InitStructure1;
EXTI_InitTypeDef EXTI_InitStructure1;
NVIC_InitTypeDef NVIC_InitStructure1;//3
GPIO_InitTypeDef GPIO_InitStructure2;
EXTI_InitTypeDef EXTI_InitStructure2;
NVIC_InitTypeDef NVIC_InitStructure2;//3
GPIO_InitTypeDef GPIO_InitStructure3;
EXTI_InitTypeDef EXTI_InitStructure3;
NVIC_InitTypeDef NVIC_InitStructure3;//3
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE);//2
GPIO_InitStructure0.GPIO_Mode = GPIO_Mode_IN;//ÊäÈ븡¿Õģʽ
GPIO_InitStructure0.GPIO_Pin = GPIO_Pin_0;//pc13¼ü2¿ØÖÆ
GPIO_Init(GPIOA,&GPIO_InitStructure0);//
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0);//½¨Á¢pA0ºÍÖжÏÁªÏµPA
EXTI_InitStructure0.EXTI_Line = EXTI_Line0;
EXTI_InitStructure0.EXTI_Mode = EXTI_Mode_Interrupt;//ÖжÏģʽ
EXTI_InitStructure0.EXTI_Trigger = EXTI_Trigger_Falling;//´¥·¢·½Ê½Ï½µÑØ
EXTI_InitStructure0.EXTI_LineCmd = ENABLE;//
EXTI_Init(&EXTI_InitStructure0);//
//ÓÅÏȼ¶ÅäÖÃ
NVIC_InitStructure0.NVIC_IRQChannel = EXTI0_IRQn;//Ö»ÓÐ0,1£¬2£¬3£¬4£¬5-9,10-15
NVIC_InitStructure0.NVIC_IRQChannelPreemptionPriority = 0x0f;
NVIC_InitStructure0.NVIC_IRQChannelSubPriority = 0x0f;
NVIC_InitStructure0.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure0);//
GPIO_InitStructure1.GPIO_Mode = GPIO_Mode_IN;//ÊäÈ븡¿Õģʽ
GPIO_InitStructure1.GPIO_Pin = GPIO_Pin_13;//pc13¼ü2¿ØÖÆ
GPIO_Init(GPIOC,&GPIO_InitStructure1);//
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC,EXTI_PinSource13);//½¨Á¢pc13ºÍÖжÏÁªÏµPA
EXTI_InitStructure1.EXTI_Line = EXTI_Line13;
EXTI_InitStructure1.EXTI_Mode = EXTI_Mode_Interrupt;//ÖжÏģʽ
EXTI_InitStructure1.EXTI_Trigger = EXTI_Trigger_Falling;//´¥·¢·½Ê½Ï½µÑØ
EXTI_InitStructure1.EXTI_LineCmd = ENABLE;//
EXTI_Init(&EXTI_InitStructure1);//
//ÓÅÏȼ¶ÅäÖÃ
NVIC_InitStructure1.NVIC_IRQChannel = EXTI15_10_IRQn;//Ö»ÓÐ1£¬2£¬3£¬4£¬5-9,10-15
NVIC_InitStructure1.NVIC_IRQChannelPreemptionPriority = 0x0f;
NVIC_InitStructure1.NVIC_IRQChannelSubPriority = 0x0f;
NVIC_InitStructure1.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure1);//
//
GPIO_InitStructure2.GPIO_Mode = GPIO_Mode_IN;//ÊäÈ븡¿Õģʽ
GPIO_InitStructure2.GPIO_Pin = GPIO_Pin_2;//pA2¼ü3¿ØÖÆ
GPIO_Init(GPIOA,&GPIO_InitStructure2);//
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource2);//½¨Á¢pA2ºÍÖжÏÁªÏµPA
EXTI_InitStructure2.EXTI_Line = EXTI_Line2;
EXTI_InitStructure2.EXTI_Mode = EXTI_Mode_Interrupt;//ÖжÏģʽ
EXTI_InitStructure2.EXTI_Trigger = EXTI_Trigger_Falling;//´¥·¢·½Ê½Ï½µÑØ
EXTI_InitStructure2.EXTI_LineCmd = ENABLE;//
EXTI_Init(&EXTI_InitStructure2);//
//ÓÅÏȼ¶ÅäÖÃ
NVIC_InitStructure2.NVIC_IRQChannel = EXTI2_IRQn;//Ö»ÓÐ0,1£¬2£¬3£¬4£¬5-9,10-15
NVIC_InitStructure2.NVIC_IRQChannelPreemptionPriority = 0x0f;
NVIC_InitStructure2.NVIC_IRQChannelSubPriority = 0x0f;
NVIC_InitStructure2.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure2);//
GPIO_InitStructure3.GPIO_Mode = GPIO_Mode_IN;//ÊäÈ븡¿Õģʽ
GPIO_InitStructure3.GPIO_Pin = GPIO_Pin_5;//pc13¼ü2¿ØÖÆ
GPIO_Init(GPIOB,&GPIO_InitStructure3);//
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB,EXTI_PinSource5);//½¨Á¢pA0ºÍÖжÏÁªÏµPA
EXTI_InitStructure3.EXTI_Line = EXTI_Line5;
EXTI_InitStructure3.EXTI_Mode = EXTI_Mode_Interrupt;//ÖжÏģʽ
EXTI_InitStructure3.EXTI_Trigger = EXTI_Trigger_Falling;//´¥·¢·½Ê½Ï½µÑØ
EXTI_InitStructure3.EXTI_LineCmd = ENABLE;//
EXTI_Init(&EXTI_InitStructure3);//
//ÓÅÏȼ¶ÅäÖÃ
NVIC_InitStructure3.NVIC_IRQChannel = EXTI9_5_IRQn;//Ö»ÓÐ0,1£¬2£¬3£¬4£¬5-9,10-15
NVIC_InitStructure3.NVIC_IRQChannelPreemptionPriority = 0x0f;
NVIC_InitStructure3.NVIC_IRQChannelSubPriority = 0x0f;
NVIC_InitStructure3.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure3);//
}
void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line0)==SET)//·¢Éú¸Ä±ä½øÈë
{
GPIO_ToggleBits(GPIOC,GPIO_Pin_1);
printf("Pa0ÖжÏ\n");
EXTI_ClearITPendingBit(EXTI_Line0);
}
}
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line13)==SET)//·¢Éú¸Ä±ä½øÈë
{
GPIO_ToggleBits(GPIOC,GPIO_Pin_2);
printf("PC13ÖжÏ\n");
EXTI_ClearITPendingBit(EXTI_Line13);
}
}
void EXTI2_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line2)==SET)//·¢Éú¸Ä±ä½øÈë
{
GPIO_ToggleBits(GPIOC,GPIO_Pin_3);
printf("Pa2ÖжÏ\n");
EXTI_ClearITPendingBit(EXTI_Line2);
}
}
void EXTI9_5_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line5)==SET)//·¢Éú¸Ä±ä½øÈë
{
GPIO_ToggleBits(GPIOC,GPIO_Pin_4);
printf("PB5ÖжÏ\n");
EXTI_ClearITPendingBit(EXTI_Line5);
}
}