static Read74hc165( void )
{
unsigned char i, j ;
unsigned char KeyAddress[3];
unsigned char ReadReturn;
PL = 0 ; //鎖存并行數(shù)據(jù)開始
IN = 1 ; //準(zhǔn)備讀串行數(shù)據(jù)(也起到延時(shí)作用)
PL = 1 ; //鎖存并行數(shù)據(jù)結(jié)束
KeyAddress[0]=0;
KeyAddress[1]=0;
KeyAddress[2]=0;
ReadReturn=0;
for( j = 0 ; j < 3 ; j++ )
{
for( i = 8 ; i >= 1 ; i-- )
{
CLK = 0 ; //時(shí)鐘拉低
if( IN == 0 )break ; //有鍵按下,數(shù)據(jù)為1
CLK = 1 ; //時(shí)鐘拉高
}
KeyAddress[ j ] = i ; //有鍵壓下,則i的取值在1~8之間,無鍵壓下,i = 0
}
if(flag == 0) //第一片優(yōu)先讀取
{
for( j = 0 ; j<3 ; j++ )
{
if( KeyAddress[j] == 0 ) ReadReturn = 0x00 ;
else
{
ReadReturn = KeyAddress[ j ] + j * 8 ;
break ;
}
}
}
else if(flag == 1) //第三片優(yōu)先讀取 ??????
{
for( j = 2 ; j >=0 ; j-- )
{
if( KeyAddress[ j ] == 0 ) ReadReturn = 0 ;
else
{
ReadReturn = KeyAddress[ j ] + j * 8 ;
break ;
}
}
}
return ReadReturn;
}
第一片優(yōu)先讀取是正確的,但是到第三片優(yōu)先讀取的時(shí)候就不正確了??求解????
|