Hi Ichan,
switch(index) {
case 0: TRISIO0 = 0; GPIO0 = 0; TRISIO0 = 1; ADCON0 = 0b10000001; break; // AN0
case 1: TRISIO1 = 0; GPIO1 = 0; TRISIO1 = 1; ADCON0 = 0b10000101; break; // AN1
case 2: TRISIO2 = 0; GPIO2 = 0; TRISIO2 = 1; ADCON0 = 0b10001001; break; // AN2
default: break;
}
Explain this sequence to me please: TRISIO0 = 0; GPIO0 = 0; TRISIO0 = 1. Why did you started by making the pin output? Is it some way to make sure you discharged the capacitor plate in real HW? Or just for the sake of experimenting with Proteus, because you used a 10pF capacitor instead of the plate? Should I then leave it as is when implemented on real HW?
Could you please give me a quick description for this snippet, it will be easier for me to follow the code:
adc[index] = ((ADRESH << 8 ) + ADRESL);
adc[index] = adc[index]*16;
TRISIO = 0b11000000;
GPIO &= 0b11100000;
if (warmup > 0) {warmup--; avg[index] = adc[index];}
if (adc[index] < (avg[index] - (avg[index] >> 6))) {
if (dbc[index] == DBCMAX) {
button = index; result = 1;
} else if (dbc[index] < DBCMAX) dbc[index]++;
} else if (adc[index] > (avg[index] - (avg[index] >> 8))) {
if (dbc[index] == 0) {
button = 0xFF; result = 0;
} else if (dbc[index] > 0) dbc[index]--;
}
if (result == 0) {
avgindex++;
if (avgindex == AVGDELAY) {
avg[index] = avg[index] + (int)(adc[index] - avg[index])/16;
avgindex = 0;
}
}
if (++index >= BUTTONS) index = 0;