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

Setting up ADC

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







Setting up ADC
PostPosted: Thu Feb 22, 2007 7:16 am     Reply with quote

Hi,

i'm trying to write a program to run setup my adc and i'm getting problems and i do not know the reason why. Anyone can help me? Thanks!

Code:
#include <16F877.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=2000000)
#use rs232(baud=9600, xmit = PIN_C6, rcv = PIN_C7)

int16 value;

void main() {
   setup_adc_ports(RA0_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);
   delay_ms(2000);
   set_adc_channel(0);

   while(1)
   {
      value=read_adc(); //read the ADC
     printf("%LX \n\r", value);
     delay_ms(1000);
   }
}



Output from hyperterminal:
rrrrr>>>>><<<<>>>>[/code]
Ttelmah
Guest







PostPosted: Thu Feb 22, 2007 9:39 am     Reply with quote

How is the serial connected to the PC?. What happens if you do a 'test' print like:

printf("Test message\n\r");

There is nothing obviously wrong with the code, so I'd suspect a hardware problem with the serial connection.

Best Wishes
buiz



Joined: 21 Feb 2007
Posts: 4

View user's profile Send private message

PostPosted: Thu Feb 22, 2007 9:48 am     Reply with quote

Hello!



#include <16F877.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=2000000) // crystal 2000000? or 20000000? look at this detail!!!
#use rs232(baud=9600, xmit = PIN_C6, rcv = PIN_C7)

int16 value;

void main() {
setup_ADC_ports (an0); // (an0) it configures door an0
setup_adc(ADC_CLOCK_INTERNAL);
delay_ms(2000);
set_adc_channel(0);

while(1)
{
value=read_adc(); //read the ADC
printf("%LX \n\r", value);
delay_ms(1000);
}
}



Ok!


Last edited by buiz on Thu Feb 22, 2007 11:36 am; edited 2 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 22, 2007 11:20 am     Reply with quote

Quote:

Output from hyperterminal:
rrrrr>>>>><<<<>>>>

#include <16F877.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=2000000)
#use rs232(baud=9600, xmit = PIN_C6, rcv = PIN_C7)

Look closely at the line in bold. Then look at the numbers on your
crystal.
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