unsigned int ADREAD(unsigned char channel){
unsigned char ADL_byte, ADH_byte;
unsigned int ADR;
if(channel.B3 != 0){
channel.B3=0;
ADCON0=0x83 | (channel<<3);
}
else
{ ADCON0=0x81 | (channel<<3);
}
// delay_us(20)
GO_DONE_BIT=1;
while(GO_DONE_BIT);
ADL_byte=ADRESL;
ADH_byte=ADRESH;
ADR=(ADH_byte<<8)| ADL_byte;
return ADR;
}
void main() {
unsigned int ADRES;
unsigned char CHSL;
unsigned short OUTM[3];
unsigned short ph, cap;
unsigned short REFC[3][3];
CMCON=7;
ADCON1=0xB0;
ADCON2=0x30;
OPTION_REG=0xDE;
TRISD=0x00;
PORTD=0x00;
while(1)
{
CHSL=0;
do{
for (ph=0; ph<3; ph++)
{
for (cap=0; cap<3; cap++)
{
ADRES=ADREAD(ph*3+cap);
ADRES=ADRES>>2;
if(ADRES<REFC[ph][cap]) OUTM[ph].cap=0;
else if(ADRES>REFC[ph][cap]) OUTM[ph].cap=0 ;
else OUTM[ph].(cap+2)=1;
CHSL=CHSL+1;
}
}
} while(CHSL<10);
}
}