u8 conmmend_start[]= {0x7e,0x03,0x01,0x02,0xef}; //2¥·Å
u8 conmmend_pause[]= {0x7e,0x03,0x02,0x01,0xef}; //ÔYí£
u8 conmmend_music_down[]= {0x7e,0x03,0x03,0x00,0xef}; //ÏÂò»Çú
u8 conmmend_music_up[]= {0x7e,0x03,0x04,0x07,0xef}; //éÏò»Çú
u8 M_Type; //Ä£ê½Ñ¡Ôñ±êÖ¾
u8 PWM_numb;
u8 cnt=0;
void EXTIX_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
KEY_Init(); // °′¼ü¶Ë¿ú3õê¼»ˉ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //ê1Äü¸′óÃ1|Äüê±Öó
//GPIOA.7 ÖD¶ÏÏßòÔ¼°ÖD¶Ï3õê¼»ˉÅäÖà ϽμÑØ′¥·¢
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource7);
EXTI_InitStructure.EXTI_Line=EXTI_Line7; //KEY2
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure); //¸ù¾YEXTI_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèEXTI¼Ä′æÆ÷
//GPIO¡£8 ÖD¶ÏÏßòÔ¼°ÖD¶Ï3õê¼»ˉÅäÖà ϽμÑØ′¥·¢ //KEY1
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource9);
EXTI_InitStructure.EXTI_Line=EXTI_Line9;
EXTI_Init(&EXTI_InitStructure); //¸ù¾YEXTI_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèEXTI¼Ä′æÆ÷
//GPIOA.11 ÖD¶ÏÏßòÔ¼°ÖD¶Ï3õê¼»ˉÅäÖà ϽμÑØ′¥·¢ //KEY0
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource11);
EXTI_InitStructure.EXTI_Line=EXTI_Line11;
EXTI_Init(&EXTI_InitStructure); //¸ù¾YEXTI_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèEXTI¼Ä′æÆ÷
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //ê1Äü°′¼üKEY2ËùÔúμÄía2¿ÖD¶Ïí¨μà
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x03; //ÇàÕ¼óÅÏ輶2£¬
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03; //×óóÅÏ輶3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1Äüía2¿ÖD¶Ïí¨μà
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //ê1Äü°′¼üKEY1ËùÔúμÄía2¿ÖD¶Ïí¨μà
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x03; //ÇàÕ¼óÅÏ輶2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //×óóÅÏ輶2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1Äüía2¿ÖD¶Ïí¨μà
NVIC_Init(&NVIC_InitStructure); //¸ù¾YNVIC_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèNVIC¼Ä′æÆ÷
}
//ía2¿ÖD¶Ï7 8·tÎñ3ìDò
void EXTI9_5_IRQHandler()
{
u8 t;
if(M_Type==MODE_GRAPIC)
{
delay_ms(10);//Ïû¶¶
if(KEY0==0) //PA7°′Ï ±£Ö¤PWM_numbÔú0μ½6Ö®¼ä±ä»ˉ
{
LED1=0;
LED4=1;
PWM_numb++;
if(PWM_numb>=7)PWM_numb=0;
}
if(KEY1==0) //PA9°′ÏÂ
{
LED1=1;
LED4=0;
PWM_numb++;
if(PWM_numb==0)PWM_numb=6;
}
}
if(M_Type==MODE_MUSIC)
{
delay_ms(10);//Ïû¶¶
if(KEY0==0) //PA7°′ÏÂ
{
LED2=0;
for(t=0;t<5;t++)
{
USART_SendData(USART1, conmmend_music_down[t]);//Ïò′®¿ú1·¢Ëíêy¾Y0x7e,0x03,0x03,0x00,0xef
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//μè′y·¢Ëí½áêø
}
}
if(KEY1==0) //PA8°′ÏÂ
{
LED2=1;
for(t=0;t<5;t++)
{
USART_SendData(USART1, conmmend_music_up[t]);//Ïò′®¿ú1·¢Ëíêy¾Y0x7e,0x03,0x03,0x00,0xef
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//μè′y·¢Ëí½áêø
}
}
}
EXTI_ClearITPendingBit(EXTI_Line7); //Çå3yLINE7éÏμÄÖD¶Ï±ê־λ
EXTI_ClearITPendingBit(EXTI_Line8); //Çå3yLINE8éÏμÄÖD¶Ï±ê־λ
}
//ía2¿ÖD¶Ï7 8·tÎñ3ìDò
void EXTI15_10_IRQHandler()
{
u8 t;
delay_ms(10);//Ïû¶¶
if(KEY2==0) //PA8°′ÏÂ
{
LED3=~LED3;
if(LED3==0)
{
M_Type=MODE_GRAPIC; //ÇD»»Öá×Ô¶¨òåÑYê¾Ä£ê½£¬2¢í£Ö12¥·ÅòôàÖ
LED8=1;
for(t=0;t<5;t++)
{
USART_SendData(USART1, conmmend_pause[t]);//Ïò′®¿ú1·¢Ëíêy¾Y0x7e,0x03,0x02,0x01,0xef
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//μè′y·¢Ëí½áêø
}
}
if(LED3==1)
{
M_Type=MODE_MUSIC; //ÇD»»ÖáòôàÖģ꽣¬2¢2¥·ÅòôàÖ
LED8=0;
for(t=0;t<5;t++)
{
USART_SendData(USART1, conmmend_start[t]);//Ïò′®¿ú1·¢Ëíêy¾Y0x7e,0x03,0x01,0x02,0xef
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//μè′y·¢Ëí½áêø
}
}
}
EXTI_ClearITPendingBit(EXTI_Line11); //Çå3yLINE0éÏμÄÖD¶Ï±ê־λ
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>