CH452 LOAD DIN DCLK DOUT 和ARM CPU的4个GPIO连接,DOUT 是普通GPIO,不能产生中断,所以我只能用查询方式去读按键的键值。
#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); // 输出位数据 // 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; //定义命令字,和数据存储器 cmd=0x07; //读按键的命令字 SetGpioVal(CH452_LOAD,0); for(i=0;i!=4;i++) { if (cmd & 1) SetGpioVal(CH452_DIN,1); else SetGpioVal(CH452_DIN,0); // 输出位数据 // 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); //反回键值 }
主程序通过一个循环不停的去读键值,读到的总是0x7f
请大家帮忙看看为什么数码管不显示,按键读到的也总是0x7f