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 support@ccsinfo.com

ADC problem?

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



Joined: 09 Mar 2005
Posts: 6

View user's profile Send private message

ADC problem?
PostPosted: Mon Apr 25, 2005 3:53 am     Reply with quote

hi

i wanna make an ADC code on pic 18f452, 10 bit analog

int x=read_adc();

the problem is that this int value represent 10 bit digit and i wanna send it with the rs232 which is 8 bit ;

how can i access the ADDRESL,ADDRESH of the analog digital convertion result to send each byte alone in the rs232

thanks for help
Ttelmah
Guest







Re: ADC problem?
PostPosted: Mon Apr 25, 2005 4:22 am     Reply with quote

asic1984 wrote:
hi

i wanna make an ADC code on pic 18f452, 10 bit analog

int x=read_adc();

the problem is that this int value represent 10 bit digit and i wanna send it with the rs232 which is 8 bit ;

how can i access the ADDRESL,ADDRESH of the analog digital convertion result to send each byte alone in the rs232

thanks for help

Firstly, what you post will only get the low 8bits of the value, since an 'int' is an 8bit register.
You need to have #device ADC=10, at the top of your code (immediately after loading the 'processor' include file), and use an int16 to hold the value.
Then with:
Code:

int16 x;
x=read_adc();
putc(make8(x,1));
putc(make8(x,0));


Will output the two bytes one after the other. You can reverse the order, by swapping the '1', and the '0' at the end of the make8 instruction.
However you should think moderately 'carefully' about sending this sort of value over the serial (consider sending it in hex instead for example), since any value is possible, and some UART drivers will treat characters like line-feed, carriage-return, and EOS, as having significance. Your receiver will need to ensure the driver is in 'binary' mode, and not applying any such filtering.

Best Wishes
asic1984



Joined: 09 Mar 2005
Posts: 6

View user's profile Send private message

PostPosted: Mon Apr 25, 2005 4:45 am     Reply with quote

Quote:

Will output the two bytes one after the other. You can reverse the order, by swapping the '1', and the '0' at the end of the make8 instruction.
However you should think moderately 'carefully' about sending this sort of value over the serial (consider sending it in hex instead for example), since any value is possible, and some UART drivers will treat characters like line-feed, carriage-return, and EOS, as having significance. Your receiver will need to ensure the driver is in 'binary' mode, and not applying any such filtering.



thanks too much for your reply ,but how can i convert the value that i read to a hex value?
asic1984



Joined: 09 Mar 2005
Posts: 6

View user's profile Send private message

PostPosted: Mon Apr 25, 2005 4:47 am     Reply with quote

Quote:

Will output the two bytes one after the other. You can reverse the order, by swapping the '1', and the '0' at the end of the make8 instruction.
However you should think moderately 'carefully' about sending this sort of value over the serial (consider sending it in hex instead for example), since any value is possible, and some UART drivers will treat characters like line-feed, carriage-return, and EOS, as having significance. Your receiver will need to ensure the driver is in 'binary' mode, and not applying any such filtering.



thanks too much for your reply ,but how can i convert the value that i read to a hex value?
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Mon Apr 25, 2005 7:26 am     Reply with quote

printf(streamname, "%04x", read_adc());

Whoops, yep %04LX would be better. Keeping getting myself confused moving between PIC and PC... And personally I like to see the leading zeros.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!


Last edited by rwyoung on Mon Apr 25, 2005 11:45 am; edited 1 time in total
Ttelmah
Guest







PostPosted: Mon Apr 25, 2005 8:18 am     Reply with quote

You actually need '%4Lx', not '%4x', to treat the value as a 'long'. However given that the top nibble is zero, '%3LX', would send the three significant nibbles.

Best Wishes
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