#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
char temp;
void gpio_init(void)
{
EALLOW;
GpioCtrlRegs.GPBMUX2.all=0x0000;
GpioCtrlRegs.GPBDIR.bit.GPIO50=1;
GpioCtrlRegs.GPBDIR.bit.GPIO49=1;
GpioCtrlRegs.GPBDIR.bit.GPIO48=1;
GpioCtrlRegs.GPBPUD.bit.GPIO53=1;
GpioCtrlRegs.GPBPUD.bit.GPIO52=1;
GpioCtrlRegs.GPBPUD.bit.GPIO51=1;
GpioCtrlRegs.GPBDIR.bit.GPIO53=0;
GpioCtrlRegs.GPBDIR.bit.GPIO52=0;
GpioCtrlRegs.GPBDIR.bit.GPIO51=0;
GpioCtrlRegs.GPAMUX1.all=0x0000;
GpioCtrlRegs.GPADIR.all=0xffff;
EDIS;
}
void delay(void)
{
long int i,j;
for(i=0;i<20;i++)
for(j=0;j<10;j++);
}
void delay1(void)
{
long int i,j;
for(i=0;i<200;i++)
for(j=0;j<100;j++);
}
void all_on(void)
{
GpioDataRegs.GPBCLEAR.bit.GPIO50=1;
GpioDataRegs.GPBCLEAR.bit.GPIO49=1;
GpioDataRegs.GPBCLEAR.bit.GPIO48=1;
}
char matrix_key(void)
{
all_on();
if(GpioDataRegs.GPBDAT.bit.GPIO53==0)
{
delay1();
if(GpioDataRegs.GPBDAT.bit.GPIO53==0){
GpioDataRegs.GPBSET.bit.GPIO50=1;
delay();
if(GpioDataRegs.GPBDAT.bit.GPIO53==1)
temp=1;
else temp=temp;
all_on();
GpioDataRegs.GPBSET.bit.GPIO48=1;
delay();
if(GpioDataRegs.GPBDAT.bit.GPIO53==1)
temp=2;
else temp=temp;
all_on();
GpioDataRegs.GPBSET.bit.GPIO49=1;
delay();
if(GpioDataRegs.GPBDAT.bit.GPIO53==1)
temp=3;
else temp=temp;
}
}
all_on();
if(GpioDataRegs.GPBDAT.bit.GPIO52==0)
{
delay1();
if(GpioDataRegs.GPBDAT.bit.GPIO52==0){
GpioDataRegs.GPBSET.bit.GPIO50=1;
delay();
if(GpioDataRegs.GPBDAT.bit.GPIO52==1)
temp=4;
else temp=temp;
all_on();
GpioDataRegs.GPBSET.bit.GPIO48=1;
delay();
if(GpioDataRegs.GPBDAT.bit.GPIO52==1)
temp=5;
else temp=temp;
all_on();
GpioDataRegs.GPBSET.bit.GPIO49=1;
delay();
if(GpioDataRegs.GPBDAT.bit.GPIO52==1)
temp=6;
else temp=temp;
}
}
all_on();
if(GpioDataRegs.GPBDAT.bit.GPIO51==0)
{
delay1();
if(GpioDataRegs.GPBDAT.bit.GPIO51==0){
GpioDataRegs.GPBSET.bit.GPIO50=1;
delay();
if(GpioDataRegs.GPBDAT.bit.GPIO51==1)
temp=7;
else temp=temp;
all_on();
GpioDataRegs.GPBSET.bit.GPIO48=1;
delay();
if(GpioDataRegs.GPBDAT.bit.GPIO51==1)
temp=8;
else temp=temp;
all_on();
GpioDataRegs.GPBSET.bit.GPIO49=1;
delay();
if(GpioDataRegs.GPBDAT.bit.GPIO51==1)
temp=9;
else temp=temp;
}
}
return temp;
}
void main(void)
{
gpio_init();
temp=0;
for(;;)
{
// matrix_key();
// GpioDataRegs.GPADAT.all=temp;
// delay();
GpioDataRegs.GPADAT.all=~matrix_key();
}
}