Posté 13 novembre 2007 - 01:48
Salut,
Il faut que tu crées une table de conversion.
Exemple avec une conversion 8 bits :
// rangeTable is a 128-entry table that converts the 8-bit A/D value
// to the corresponding range in cm.
//==============================================================
const unsigned char TableIR[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 80, 76, 72, 68, 65, 62, 59, 57, 54, 52, 50, 48, 47,
45, 44, 42, 41, 40, 38, 37, 36, 35, 34, 33, 33, 32, 31, 30, 30,
29, 28, 28, 27, 26, 26, 25, 25, 24, 24, 23, 23, 23, 22, 22, 21,
21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 18, 17, 17, 17, 17,
16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14,
13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 11,
11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10};
...
ADCON1=0;
ADCON0=0x81; // IR_av_D
DelayUs(50);
ADGO=1;
while(ADGO) continue;
Res_IR_av_D1=ADRESH;
distance=TableIR[Res_IR_av_D1];