void DelayMs(int k)
{
unsigned int a;
for(a=0;a<=k;a++);
}
unsigned char DecodeKeyVal(char num)
{
unsigned char keyval=255;
switch(num)
{
case 0xee: keyval = 1;break;
case 0xed: keyval = 2;break;
case 0xeb: keyval = 3;break;
case 0xe7: keyval = 4;break;
case 0xde: keyval = 5;break;
case 0xdd: keyval = 6;break;
case 0xdb: keyval = 7;break;
case 0xd7: keyval = 8;break;
case 0xbe: keyval = 9;break;
case 0xbd: keyval = '*';break;
case 0xbb: keyval = 0;break;
case 0xb7: keyval = '#';break;
case 0x7e: keyval = 'A';break;
case 0x7d: keyval = 'B';break;
case 0x7b: keyval = 'C';break;
case 0x77: keyval = 'D';break;
}
return keyval;
}
void Key_Scan(void)
{
for(i=0;i<4;i++)
{
DelayMs(50);
P2 = ~(0x01<<i);
DelayMs(50);
UN = (P2 | 0x0f);
if(UN != 0xff)
{
DelayMs(50);
UN = (P2 | 0x0f);
if(UN != 0xff)
{
KC = UN & (~(0x01<<i));
DelayMs(50);
KeyBuf[wptr] = DecodeKeyVal(KC);
wptr++;
if(wptr > 25)
wptr=0;
while(UN != 0xff)
UN = P2 | 0x0f;
DelayMs(100);
}
}
}
}
{
unsigned int a;
for(a=0;a<=k;a++);
}
unsigned char DecodeKeyVal(char num)
{
unsigned char keyval=255;
switch(num)
{
case 0xee: keyval = 1;break;
case 0xed: keyval = 2;break;
case 0xeb: keyval = 3;break;
case 0xe7: keyval = 4;break;
case 0xde: keyval = 5;break;
case 0xdd: keyval = 6;break;
case 0xdb: keyval = 7;break;
case 0xd7: keyval = 8;break;
case 0xbe: keyval = 9;break;
case 0xbd: keyval = '*';break;
case 0xbb: keyval = 0;break;
case 0xb7: keyval = '#';break;
case 0x7e: keyval = 'A';break;
case 0x7d: keyval = 'B';break;
case 0x7b: keyval = 'C';break;
case 0x77: keyval = 'D';break;
}
return keyval;
}
void Key_Scan(void)
{
for(i=0;i<4;i++)
{
DelayMs(50);
P2 = ~(0x01<<i);
DelayMs(50);
UN = (P2 | 0x0f);
if(UN != 0xff)
{
DelayMs(50);
UN = (P2 | 0x0f);
if(UN != 0xff)
{
KC = UN & (~(0x01<<i));
DelayMs(50);
KeyBuf[wptr] = DecodeKeyVal(KC);
wptr++;
if(wptr > 25)
wptr=0;
while(UN != 0xff)
UN = P2 | 0x0f;
DelayMs(100);
}
}
}
}