中级会员
 
- 积分
- 385
- 金钱
- 385
- 注册时间
- 2011-11-21
- 在线时间
- 32 小时
|
1金钱
static u8 read_mpr121_reg(u8 device, u8 addr) {
u8 dat;
IIC_Init();
IIC_Start();
IIC_Send_Byte(device);
IIC_Wait_Ack();
IIC_Send_Byte(addr);
IIC_Wait_Ack();
IIC_Start();
IIC_Send_Byte(device + 0x01);
IIC_Wait_Ack();
//dat=read_byte();
//IIC_NAck(0);
dat = IIC_Read_Byte(0);
IIC_NAck();
IIC_Stop();
return dat;
}
/**
* ¶áè¡μ±Ç°μÄ°′¼ü
* @return 0xff μ±Ç°Ã»óD°′¼ü°′ÏÂ
* 0~11 μ±Ç°±»°′ÏÂμÄkeyÖμ
*/
static u8 get_key() {
u8 count = 0;
u8 i = 0;
u32 dat;
dat = read_mpr121_reg(touch_shield, 0x01) << 8;
dat = dat | read_mpr121_reg(touch_shield, 0x00);
for (i = 0; i < 12; i++) {
if ((dat & (1 << i))) {
count++;
}
}
i = 0;
if(count == 1) {
while((dat & (1 << i)) == 0) {
i++;
}
return i;
}
return 0xff;
}
以上是mpr121处理程序的一部分,红色的两行程序我不是很明白,不知道他是怎么获取按键值得,请教各位了
|
最佳答案
查看完整内容[请看2#楼]
红色部分是获取按键值的高8位和低8位仪器拼接成一个32位的数据,然后再对拼接的32为数据进行位判断,看哪一位为1,则返回位的计数值。
|