DSP中的键盘控制程序的算法
DSP中的键盘控制程序的算法,基于TI公司的5509这款DSP芯片
clude "scancode.h"
#define REGISTERCLKMD (*(unsigned int *)0x58)
ioport unsigned int port8000;
ioport unsigned int port8001;
ioport unsigned int port8002;
ioport unsigned int port8005;
ioport unsigned int port8007;
void Delay(unsigned int nTime); // 延时子程序
void RefreshLEDArray(); // 刷新显示
void SetLEDArray(int nNumber); // 修改显示内容
char ConvertScanToChar(unsigned char cScanCode); // 将键盘扫描码转换为字符
unsigned int nScreenBuffer[1024];
unsigned char ledbuf[8],ledx[8];
unsigned char ledkey[10][8]=
{
{0x00,0x00,0x7C,0x82,0x82,0x82,0x7C,0x00},
{0x00,0x00,0x00,0x84,0xFE,0x80,0x00,0x00}, //1
{0x00,0x00,0x84,0xC2,0xA2,0x92,0x8C,0x00}, //2
{0x00,0x00,0x44,0x92,0x92,0x92,0x6C,0x00},
{0x00,0x00,0x30,0x28,0x24,0xFE,0x20,0x00},
{0x00,0x00,0x4E,0x92,0x92,0x92,0x62,0x00},
{0x00,0x00,0x7C,0x92,0x92,0x92,0x64,0x00},
{0x00,0x00,0x02,0xC2,0x32,0x0A,0x06,0x00},
{0x00,0x00,0x6C,0x92,0x92,0x92,0x6C,0x00},
{0x00,0x00,0x4C,0x92,0x92,0x92,0x7C,0x00}
};
unsigned int uPort8000;
main()
{
int nCount,nCursorCount;
unsigned int nScanCode,nKeyCode;
unsigned char cKey;
REGISTERCLKMD=0;
port8000=0; // 初始化ICETEK-CTR
port8000=0x80;
port8000=0;
port8007=0; // 关闭东西方向的交通灯
port8007=0x40; // 关闭南北方向的交通灯
uPort8000=port8002; // 清键盘缓冲区
for ( nCount=0;nCount<8;nCount++ )
{
ledbuf[nCount]=0x0ff; // 显示为空白
ledx[nCount]=(nCount<<4); // 生成显示列控制字
}
RefreshLEDArray();
nCount=nCursorCount=0;
for (;;)
{
nScanCode=port8001;
nScanCode&=0x0ff;
uPort8000=port8002;
if ( nScanCode!=0 && nScanCode!=0x0ff )
{
if ( nScanCode==SCANCODE_Enter ) break;
else
{
cKey=ConvertScanToChar(nScanCode);
if ( cKey!=0 )
{
nKeyCode=cKey-'0';
SetLEDArray(nKeyCode);
}
}
}
Delay(16);
nCursorCount++; nCursorCount%=4;
if ( nCursorCount==0 ) ledbuf[7]^=0x80;
}
for ( nCount=0;nCount<8;nCount++ )
{
ledbuf[nCount]=0x0ff; // 显示为空白
ledx[nCount]=(nCount<<4); // 生成显示列控制字
}
RefreshLEDArray();
exit(0);
}
void Delay(unsigned int nDelay)
{
int ii,jj,kk=0;
for ( ii=0;ii{
for ( jj=0;jj<64;jj++ )
{
RefreshLEDArray();
kk++;
}
}
}
void RefreshLEDArray()
{
int i;
for ( i=0;i<8;i++ )
{
port8000=ledx;
port8005=ledbuf;
}
}
void SetLEDArray(int nNumber)
{
int i;
for ( i=0;i<8;i++ )
ledbuf=~ledkey[nNumber][7-i];
}
char ConvertScanToChar(unsigned char cScanCode)
{
char cReturn;
cReturn=0;
switch ( cScanCode )
{
case SCANCODE_0: cReturn='0'; break;
case SCANCODE_1: cReturn='1'; break;
case SCANCODE_2: cReturn='2'; break;
case SCANCODE_3: cReturn='3'; break;
case SCANCODE_4: cReturn='4'; break;
case SCANCODE_5: cReturn='5'; break;
case SCANCODE_6: cReturn='6'; break;
case SCANCODE_7: cReturn='7'; break;
case SCANCODE_8: cReturn='8'; break;
case SCANCODE_9: cReturn='9'; break;
}
return cReturn;
}