2线 CH452 驱动3*4键盘,送数码管显示的程序,为什么读取按键值一直都是0呢
#define CH452_GET_KEY 0x07FF
sbit CH452_CLK =P2^5;
sbit CH452_DIN =P2^6;
sbit CH452_LOAD =P2^7;
void CH452_Write(uint cmd)
{
uchar i;
CH452_LOAD=0;
for(i=0;i<12;i++)
{
CH452_DIN=cmd&0x0001;
CH452_CLK=0;
cmd>>=1;
CH452_CLK=1;
}
CH452_LOAD=1;
DELAY_6US();
}
uchar CH452_ReadKey(void)
{
unsigned char i;//,Key_Num=0 ;
CH452_Write(CH452_GET_KEY);
for(i=0;i<7;i++)
{
CH452_CLK=1;
Key_Num<<=1;
if(CH452_DIN) Key_Num++;
CH452_CLK=0;
}
return Key_Num;
} |