CH452 LOAD DIN DCLK DOUT 和ARM CPU的4個GPIO連接,DOUT 是普通GPIO,不能產(chǎn)生中斷,所以我只能用查詢方式去讀按鍵的鍵值。
#define CH452_DCLK GPIO_B2 #define CH452_DIN GPIO_B3 #define CH452_LOAD GPIO_B4 #define CH452_DOUT GPIO_B5
Init() { CH452_Write(0x403); CH452_Write(CH452_BCD); CH452_Write(CH452_DIG7 | 1); CH452_Write(CH452_DIG6 | 2); CH452_Write(CH452_DIG5 | 3); CH452_Write(CH452_DIG4 | 4); CH452_Write(CH452_DIG3 | 5); CH452_Write(CH452_DIG2 | 6); CH452_Write(CH452_DIG1 | 7); CH452_Write(CH452_DIG0 | 8)
}
void CH452_Write(unsigned short cmd) { unsigned char i; SetGpioVal(CH452_LOAD,0); for(i=0;i!=12;i++) { if(cmd & 1) SetGpioVal(CH452_DIN,1); else SetGpioVal(CH452_DIN,0); // 輸出位數(shù)據(jù) // CH452_DIN=cmd&1; SetGpioVal(CH452_DCLK,0); cmd >>=1; DelayMicroSeconds(DELAY_CLK); SetGpioVal(CH452_DCLK,1); DelayMicroSeconds(DELAY_CLK); } SetGpioVal(CH452_LOAD,1); DelayMicroSeconds(6); }
//************************************************* //輸入按鍵代碼子程序,從CH452讀取 unsigned char CH452_Read( void ) { unsigned char i; unsigned char cmd,keycode; //定義命令字,和數(shù)據(jù)存儲器 cmd=0x07; //讀按鍵的命令字 SetGpioVal(CH452_LOAD,0); for(i=0;i!=4;i++) { if (cmd & 1) SetGpioVal(CH452_DIN,1); else SetGpioVal(CH452_DIN,0); // 輸出位數(shù)據(jù) // CH452_DIN=cmd&1; //送入最低位 SetGpioVal(CH452_DCLK,0); cmd>>=1; DelayMicroSeconds(DELAY_CLK); SetGpioVal(CH452_DCLK,1); DelayMicroSeconds(DELAY_CLK); } SetGpioVal(CH452_LOAD,1); keycode=0; for(i=0;i!=7;i++) { keycode<<=1; if(GetGpioVal(CH452_DOUT))) keycode++; SetGpioVal(CH452_DCLK,0); DelayMicroSeconds(DELAY_CLK); SetGpioVal(CH452_DCLK,1); DelayMicroSeconds(DELAY_CLK); } return(keycode); //反回鍵值 }
主程序通過一個循環(huán)不停的去讀鍵值,讀到的總是0x7f
請大家?guī)兔纯礊槭裁磾?shù)碼管不顯示,按鍵讀到的也總是0x7f