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

Help me with ADC output Please ??????

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







Help me with ADC output Please ??????
PostPosted: Wed Feb 19, 2003 7:59 am     Reply with quote

I have a 10 bit ADC setup on a 16F876, the output goes form
0-1024 depending on Vref, this much I get. the problem is that I want to sen out 0006 if the adc reads 6 but at the moment I am sending 6. Can anyone advise me on how to do this. I have tried

printf("Sensor 1 reads \%4ld",sensor1);

but this doesn't seem to work??
Help me Please

#include <16f876.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,PUT
#device ADC=10
#use Delay(Clock=4000000)
#use rs232(baud=19200,xmit=pin_c6,rcv=pin_c7,parity=n,bits=8)

void main(void)
{
long sensor1,sensor2,sensor3,sensor4;

setup_adc(adc_clock_div_8);
setup_adc_ports(all_analog);

while(1)
{


set_adc_channel(0);
delay_us(25);
sensor1 = read_adc();
printf("Sensor 1 reads \%ld",sensor1);
set_adc_channel(1);
delay_us(25);
sensor2 = read_adc();
printf("Sensor 2 reads \%ld",sensor2);
set_adc_channel(4);
delay_us(25);
printf("Sensor 3 reads \%ld",sensor3);
set_adc_channel(3);
delay_us(25);
sensor4 = read_adc();
printf("Sensor 4 reads \%ld",sensor4);
delay_ms(500);

}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 11870
Eric Minbiole
Guest







Re: Help me with ADC output Please ??????
PostPosted: Wed Feb 19, 2003 8:59 am     Reply with quote

:=I have a 10 bit ADC setup on a 16F876, the output goes form
:=0-1024 depending on Vref, this much I get. the problem is that I want to sen out 0006 if the adc reads 6 but at the moment I am sending 6. Can anyone advise me on how to do this. I have tried
:=
:=printf("Sensor 1 reads \%4ld",sensor1);

Try

printf("Sensor 1 reads \%04lu",sensor1);

instead. The 0 tells printf to include leading zeros. The lu (instead of ld) is for unsigned integers.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11876
R.J.Hamlett
Guest







Re: Help me with ADC output Please ??????
PostPosted: Wed Feb 19, 2003 9:09 am     Reply with quote

:=I have a 10 bit ADC setup on a 16F876, the output goes form
:=0-1024 depending on Vref, this much I get. the problem is that I want to sen out 0006 if the adc reads 6 but at the moment I am sending 6. Can anyone advise me on how to do this. I have tried
:=
:=printf("Sensor 1 reads \%4ld",sensor1);
:=
:=but this doesn't seem to work??
This was fixed only a few compiler versions ago. If you have an older compiler (with the problem), then you have to 'bodge' the solution, by printing the output to a string, and then adding the required leading zeros. So:

printf("Sensor 1 reads ");
sprintf(opstring,"\%ld",sensor1);
count=strlen(opstring);
while (count++<4) putc('0');
printf("\%s",opstring);

Obviously you have to have an integer 'count', and a suitable string 'opstring' declared.

Easiest thing really is to get a latter compiler.

Best Wishes

:=Help me Please
:=
:=#include <16f876.h>
:=#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,PUT
:=#device ADC=10
:=#use Delay(Clock=4000000)
:=#use rs232(baud=19200,xmit=pin_c6,rcv=pin_c7,parity=n,bits=8)
:=
:=void main(void)
:={
:= long sensor1,sensor2,sensor3,sensor4;
:=
:= setup_adc(adc_clock_div_8);
:= setup_adc_ports(all_analog);
:=
:= while(1)
:= {
:=
:=
:= set_adc_channel(0);
:= delay_us(25);
:= sensor1 = read_adc();
:= printf("Sensor 1 reads \%ld",sensor1);
:= set_adc_channel(1);
:= delay_us(25);
:= sensor2 = read_adc();
:= printf("Sensor 2 reads \%ld",sensor2);
:= set_adc_channel(4);
:= delay_us(25);
:= printf("Sensor 3 reads \%ld",sensor3);
:= set_adc_channel(3);
:= delay_us(25);
:= sensor4 = read_adc();
:= printf("Sensor 4 reads \%ld",sensor4);
:= delay_ms(500);
:=
:= }
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 11877
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