#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
//端口宏定义
#define key5 GpioDataRegs.GPADAT.bit.GPIO4
#define key6 GpioDataRegs.GPADAT.bit.GPIO5
#define key7 GpioDataRegs.GPADAT.bit.GPIO6
#define key8 GpioDataRegs.GPADAT.bit.GPIO7
//定义全局变量
unsigned short flag1=0,flag2=0,flag3=0,flag4=0;
//声明函数
void scan_key(void);
void manage_key1(void);
void manage_key2(void);
void manage_key3(void);
void manage_key4(void);
void Gpio_select(void);
//主函数
void main(void)
{
InitSysCtrl();
DINT;
Gpio_select() ;
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
InitPieVectTable();
InitXintf();
key5=0;
key6=0;
key7=0;
key8=0;
while(1)
{
if((key5==1)|(key6==1)|(key7==1)|(key8==1))
scan_key();
}
}
//按键查询
void scan_key()
{
unsigned int i;
for(i=0;i<10000;i++){};//去抖动
if(key5==1)
{
manage_key1();
}
else if(key6==1)
{
manage_key2();
}
else if(key7==1)
{
manage_key3();
}
else if(key8==1)
{
manage_key4();
}
}
void manage_key1()
{
flag1=3;
key5=0;
}
void manage_key2()
{
flag2=6;
key6=0;
}
void manage_key3()
{
flag3=9;
key7=0;
}
void manage_key4()
{
flag4=0;
key8=0;
}
void Gpio_select(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.all=0x0000;
GpioCtrlRegs.GPADIR.all=0xf000; //GPIO PORTs as output
GpioCtrlRegs.GPAQSEL1.all= 0x0000; // Set GPIO input qualifier values
EDIS;
}
四个按键,flag1~4分别对应,每次按下相应按键后,flag的值加1,但是现在的问题是初始以后flag的值就不是0,而且按下按键后也不加1. |