CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

A/D from 16F873

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Francesc
Guest







A/D from 16F873
PostPosted: Wed Feb 18, 2004 7:22 am     Reply with quote

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();
}
}
Al



Joined: 13 Nov 2003
Posts: 28
Location: Belfast

View user's profile Send private message

PostPosted: Wed Feb 18, 2004 8:48 am     Reply with quote

Try including these lines

setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);
setup_adc_ports( RA0_RA1_RA3_RA4_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL);

ensure your are connected to the right ports
_________________
Alan Murray
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group