unsigned char Key_Scan(void)
{
unsigned char Scan_Code = 0, Read_Code = 0, Key_Value = 0;
unsigned char Key_Temp = 0;
DDRC |= 0x0f;
PORTC &= 0xf0; // Row output Low
DDRD |= 0xf8;
PORTD |= 0xf8; // Column output High
DDRD &= 0x07;
Key_Temp = PIND & 0xf8;
if( Key_Temp != 0xf8 )
{
Delay_Ms(10);
if( Key_Temp != 0xf8 )
{
Scan_Code = 0xfe;
while( Scan_Code != 0xff )
{
PORTC = ( Scan_Code & 0x0f );
Key_Temp = PIND & 0xf8; // 再读具体行
if( Key_Temp != 0xf8 )
{
Read_Code = (Key_Temp & 0xf8) | 0x07;
Key_Value |= ( ~Scan_Code ) + ( ~Read_Code );
}
Scan_Code = ( Scan_Code << 1 ) | 0x01;
}
}
}
PORTC &= 0x0f;
return ( Key_Value );
}