Francesc Guest
|
A/D from 16F873 |
Posted: Wed Feb 18, 2004 7:22 am |
|
|
We are beginners with a PIC microcontrollers, but is very strange, we try to read 4 ports analogs from 16F873, but the readings not are corrects.
We modify our code , because had a lot mistakes, another time we try to enter differents voltages, and ever the readings not are correct.Here a sample:
We use to modify the inlet voltage a 2K variable resistance.We place a new one 16F873.
0,0 V..0000 bit
1,0 V..0190 bit
2,0 V..0177 bit
3,0 V..0121 bit
4,0 v..0079 bit
4,5 v..0181 bit
5,0 v..1023 BIT
We include an small part of our code to try found the error.
The compiler version is 2.732 #10544.
Please, help me..
#include <16f873.h>
#device ADC=10
#fuses xt,nowdt,put,nolvp
#use delay(clock=4000000)
#use RS232(BAUD=9600,BITS=8,XMIT=PIN_C6,RCV=PIN_C7)
#bit ADFM_BIT=0x9F.7
#bit PCFG3_BIT=0X9F.3
#bit PCFG2_BIT=0X9F.2
#bit PCFG1_BIT=0X9F.1
#bit PCFG0_BIT=0X9F.0
LONG T,K1,K2,K3,K4,K;
main()
{
//SETUP_ADC_PORTS(A_ANALOG);
SETUP_ADC(ADC_CLOCK_DIV_8);
ADFM_BIT=1;
PCFG3_BIT=0;
PCFG2_BIT=0;
PCFG1_BIT=0;
PCFG0_BIT=0;
ADFM_BIT=1;
while(1)
{
SET_ADC_CHANNEL(0);
delay_ms(10);
T=READ_ADC();
SET_ADC_CHANNEL(1);
delay_ms(10);
T=READ_ADC();
SET_ADC_CHANNEL(2);
delay_ms(10);
T=READ_ADC();
SET_ADC_CHANNEL(4);
delay_ms(10);
T=READ_ADC();
void display();
}
} |
|