exti.h
#ifndef __EXTI_H
#define __EXTI_H
#include "sys.h"
#include "oled.h"
#include "led.h"
#include "keySigle.h"
#include "delay.h"
extern float kp,ki,kd;
extern float TargetDegree,NowDegree,ve;
extern float TargetPulse,NowPulse;
extern float step;
extern u8 PageFlag;
extern u8 PageFlagChange;
void EXTIX_Init(void);
void oled_showPage1();
void oled_showPage2();
void oled_showPage3();
#endif
exti.c
#include "exti.h"
#include "show.h"
static u8 Page1Key=0;
static u8 Page2Key=0;
static u8 Page3Key=0;
extern u8 PageFlag;
static u8 keyc1=0;
static u8 keyc2=0;
static u8 keyc3=0;
void EXTI0_IRQHandler(void)
{
delay_ms(20);
if(EXTI_GetFlagStatus(EXTI_Line0)!=RESET)
{
LED1=!LED1;
OLED_Clear();
delay_us(30);
switch(PageFlag)
{
case 0:oled_showPage1();break;
case 1:oled_showPage2();break;
case 2: oled_showPage2();break;
}
EXTI_ClearITPendingBit(EXTI_Line0);
}
}
void EXTI9_5_IRQHandler(void)
{
static u8 pagecount=0;
delay_ms(20);
if(EXTI_GetFlagStatus(EXTI_Line5)!=RESET)
{
LED2=!LED2;
switch(Page2Key)
{
case 0:kp=kp+0.01;break;
case 1:ki=ki+0.01;break;
case 2:kd=kd+0.01;break;
case 3:TargetDegree+=0.01;break;
default:break;
}
EXTI_ClearITPendingBit(EXTI_Line5);
}
else if(EXTI_GetFlagStatus(EXTI_Line6)!=RESET)
{
if(KEY0==0)
LED4=!LED4;
else if(KEY4==0)
LED0=!LED0;
switch(Page3Key)
{
case 0:kp=kp-0.01;break;
case 1:ki=ki-0.01;break;
case 2:kd=kd-0.01;break;
case 3:TargetDegree-=0.01;break;
case 4:;break;
default:break;
}
EXTI_ClearITPendingBit(EXTI_Line6);
}
else if(EXTI_GetFlagStatus(EXTI_Line7)!=RESET)
{
LED3=!LED3;
OLED_Clear();
delay_ms(10);
PageFlag++;
if(PageFlag==3)PageFlag=0;
EXTI_ClearITPendingBit(EXTI_Line7);
}
}
void EXTIX_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
KEY_Init();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource6);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOD, EXTI_PinSource7);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource0);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource5);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource6);
EXTI_InitStructure.EXTI_Line = EXTI_Line0 | EXTI_Line6 |EXTI_Line7 | EXTI_Line5 ;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void oled_showPage1()
{
OLED_Clear();
switch(keyc1)
{
case 0:
{
OLED_ShowChar(0,1,'#');
break;
}
case 1:
{
OLED_ShowChar(0,2,'$');
break;
}
case 2:
{
OLED_ShowChar(0,3,'*');
break;
}
}
delay_ms(2);
keyc1++;
if(keyc1==3)keyc1=0;
}
void oled_showPage2()
{
switch(keyc2)
{
case 0:
{
OLED_ShowChar(0,0,'#') ;
oled_show(1);
break;
}
case 1:
{
delay_ms(100);
OLED_ShowChar(0,1,'#') ;
oled_show(1);
break;
}
case 2:
{
OLED_ShowChar(0,2,'#') ;
oled_show(1);
break;
}
case 3:
{
delay_ms(100);
OLED_ShowChar(0,3,'#') ;
oled_show(1);
break;
}
case 4:
{
OLED_ShowChar(1,12,'#') ;
oled_show(1);
break;
}
case 5:
{
OLED_ShowChar(2,12,'#') ;
oled_show(1);
break;
}
default:break;
}
keyc2++;
if(keyc2==6)keyc2=0;
Page2Key=keyc2;
}
void oled_showPage3()
{
switch(keyc3)
{
case 0:
{
delay_ms(100);
OLED_ShowChar(0,0,'#') ;
oled_show(2);
break;
}
case 1:
{
delay_ms(100);
OLED_ShowChar(0,1,'#') ;
oled_show(2);
break;
}
case 2:
{
delay_ms(100);
OLED_ShowChar(0,2,'#') ;
oled_show(2);
break;
}
case 3:
{
delay_ms(100);
OLED_ShowChar(0,3,'#') ;
oled_show(2);
break;
}
case 4:
{
OLED_ShowChar(1,12,'#') ;
oled_show(2);
break;
}
case 5:
{
delay_ms(100);
OLED_ShowChar(2,12,'#') ;
oled_show(2);
break;
}
default:break;
}
keyc3++;
if(keyc3==6)keyc3=0;
Page3Key=keyc3;
}
|