Moderadores: andre_luis, 51, guest2003, Renie
void
adc_read(unsigned char channel)
{
ADCON0 = (channel << 3) + 0xC1; // enable ADC, RC osc.
ADGO = 1;
while(ADGO)
continue; // wait for conversion complete
}
The A/D conversion time per bit is defined as TAD. The
A/D conversion requires a minimum 12 TAD per 10-bit
conversion. The source of the A/D conversion clock is
software selected. The seven possible options for TAD
are:
• 2 TOSC
• 4 TOSC
• 8 TOSC
• 16 TOSC
• 32 TOSC
• 64 TOSC
• Internal A/D module RC oscillator (2-6 µs)
For correct A/D conversions, the A/D conversion clock
(TAD) must be selected to ensure a minimum TAD time
of 1.6 µs.
unsigned int adc_read(unsigned char channel)
{
ADCON0 = (channel << 3) + 0xC1; // enable ADC, RC osc.
ADGO = 1;
while(ADGO)
continue; // wait for conversion complete
return ADRESH*256 + ADRESL;
}
...
...
unsigned int ad[8]
...
...
void le_tudo(void)
{
unsigned char i;
for (i=0;i<8,i++) {ad[i]=adc_read(i);delay(xxx);} //faça 1 teste com e sem delay, talvez a própria iteração sirva como delay.
}
main()
...
...//setups dos ad´s, etc
for (;;)
{
...
le_tudo(); //depois dessa função terás os valores do ad nos globais ad[7]...ad[0]
...
...
}
...
...
Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante