初级会员
- 积分
- 141
- 金钱
- 141
- 注册时间
- 2013-3-6
- 在线时间
- 25 小时
|
发表于 2017-7-23 15:52:49
|
显示全部楼层
我调是调好的,但是感应距离调不了,隔了一层亚克力板后感应就不行了,望各位帮忙下:
下面是参考别人的代码能用的:
void mpr121_init(void)
{
// Section A
// This group controls filtering when data is > baseline.
write_i2c(touch_shield,MHD_R, 0x01);
write_i2c(touch_shield,NHD_R, 0x01);
write_i2c(touch_shield,NCL_R, 0x00);
write_i2c(touch_shield,FDL_R, 0x00);
// Section B
// This group controls filtering when data is < baseline.
write_i2c(touch_shield,MHD_F, 0x01);
write_i2c(touch_shield,NHD_F, 0x01);
write_i2c(touch_shield,NCL_F, 0xFF);
write_i2c(touch_shield,FDL_F, 0x02);
// Section C
// This group sets touch and release thresholds for each electrode
write_i2c(touch_shield,ELE0_T, TOU_THRESH);
write_i2c(touch_shield,ELE0_R, REL_THRESH);
write_i2c(touch_shield,ELE1_T, TOU_THRESH);
write_i2c(touch_shield,ELE1_R, REL_THRESH);
write_i2c(touch_shield,ELE2_T, TOU_THRESH);
write_i2c(touch_shield,ELE2_R, REL_THRESH);
write_i2c(touch_shield,ELE3_T, TOU_THRESH);
write_i2c(touch_shield,ELE3_R, REL_THRESH);
write_i2c(touch_shield,ELE4_T, TOU_THRESH);
write_i2c(touch_shield,ELE4_R, REL_THRESH);
write_i2c(touch_shield,ELE5_T, TOU_THRESH);
write_i2c(touch_shield,ELE5_R, REL_THRESH);
write_i2c(touch_shield,ELE6_T, TOU_THRESH);
write_i2c(touch_shield,ELE6_R, REL_THRESH);
write_i2c(touch_shield,ELE7_T, TOU_THRESH);
write_i2c(touch_shield,ELE7_R, REL_THRESH);
write_i2c(touch_shield,ELE8_T, TOU_THRESH);
write_i2c(touch_shield,ELE8_R, REL_THRESH);
write_i2c(touch_shield,ELE9_T, TOU_THRESH);
write_i2c(touch_shield,ELE9_R, REL_THRESH);
write_i2c(touch_shield,ELE10_T, TOU_THRESH);
write_i2c(touch_shield,ELE10_R, REL_THRESH);
write_i2c(touch_shield,ELE11_T, TOU_THRESH);
write_i2c(touch_shield,ELE11_R, REL_THRESH);
//----------------------------------------
write_i2c(touch_shield,0x10, 0xff); //控制电流1uA~63uA, 0x10
write_i2c(touch_shield,0x24, 0xff); //控制时间0.5uS~32uS, 0x24
//-----------------------------------------
// Section D
// Set the Filter Configuration
// Set ESI2
write_i2c(touch_shield,FIL_CFG, 0x04);
// Section E
// Electrode Configuration
// Enable 6 Electrodes and set to run mode
// Set ELE_CFG to 0x00 to return to standby mode
write_i2c(touch_shield,ELE_CFG, 0x0C); // Enables all 12 Electrodes
//write_i2c(touch_shield,ELE_CFG, 0x06); // Enable first 6 electrodes
// Section F
// Enable Auto Config and auto Reconfig
/* write_i2c(touch_shield,ATO_CFG0, 0x0B);
write_i2c(touch_shield,ATO_CFGU, 0xC9); // USL = (Vdd-0.7)/vdd*256 = 0xC9 @3.3V write_i2c(touch_shield,ATO_CFGL, 0x82); // LSL = 0.65*USL = 0x82 @3.3V
write_i2c(touch_shield,ATO_CFGT, 0xB5);*/ // Target = 0.9*USL = 0xB5 @3.3V
}
u8 get_key()
{
u8 count=0;
u8 i=0;
u16 dat=0;
u16 num;
dat=read_i2c(touch_shield,0x01)<<8;
num=read_i2c(touch_shield,0x00);
dat=dat| num;
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 -1;
}
|
|