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);
DispNumber(KC);
dig++;
if(dig == 16)
dig = 0;
while(UN != 0xff)
UN = P2 | 0x0f;
DelayMs(100);
}
}
}
}
void DispNumber(char num)
{
SendCommand(0xC0+dig,1);
switch(num)
{
case 0xee: SendCommand('1',0);break;
case 0xed: SendCommand('2',0);break;
case 0xeb: SendCommand('3',0);break;
case 0xe7: SendCommand('4',0);break;
case 0xde: SendCommand('5',0);break;
case 0xdd: SendCommand('6',0);break;
case 0xdb: SendCommand('7',0);break;
case 0xd7: SendCommand('8',0);break;
case 0xbe: SendCommand('9',0);break;
case 0xbd: SendCommand('*',0);break;
case 0xbb: SendCommand('0',0);break;
case 0xb7: SendCommand('#',0);break;
case 0x7e: SendCommand('A',0);break;
case 0x7d: SendCommand('B',0);break;
case 0x7b: SendCommand('C',0);break;
case 0x77: SendCommand('D',0);break;
}
}
{
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);
DispNumber(KC);
dig++;
if(dig == 16)
dig = 0;
while(UN != 0xff)
UN = P2 | 0x0f;
DelayMs(100);
}
}
}
}
void DispNumber(char num)
{
SendCommand(0xC0+dig,1);
switch(num)
{
case 0xee: SendCommand('1',0);break;
case 0xed: SendCommand('2',0);break;
case 0xeb: SendCommand('3',0);break;
case 0xe7: SendCommand('4',0);break;
case 0xde: SendCommand('5',0);break;
case 0xdd: SendCommand('6',0);break;
case 0xdb: SendCommand('7',0);break;
case 0xd7: SendCommand('8',0);break;
case 0xbe: SendCommand('9',0);break;
case 0xbd: SendCommand('*',0);break;
case 0xbb: SendCommand('0',0);break;
case 0xb7: SendCommand('#',0);break;
case 0x7e: SendCommand('A',0);break;
case 0x7d: SendCommand('B',0);break;
case 0x7b: SendCommand('C',0);break;
case 0x77: SendCommand('D',0);break;
}
}
No comments:
Post a Comment