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

convert the ADC hex data into dec

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



Joined: 20 Nov 2008
Posts: 79
Location: white Plains, NY

View user's profile Send private message Yahoo Messenger

convert the ADC hex data into dec
PostPosted: Sun Jan 18, 2009 4:54 am     Reply with quote

you probably talked about this before but I couldnt find it in the forum, how you conver the hex data from the ADC into dec numbers,,, instead of ff I want to get 255

Code:
#include <16F887.h>             
#FUSES NOWDT               
#FUSES NOMCLR
#FUSES NOCPD
#FUSES NOBROWNOUT            
#FUSES XT 
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

/////////////////////////////////////////////////////////////////////////////////

void main() {

int pot_board;

setup_adc( ADC_CLOCK_INTERNAL );         //sets up the adc
setup_adc_ports( ALL_ANALOG );

   while(true) {

   set_adc_channel(0);            // data from port A0 ( pot from board )
   delay_us(50);
   pot_board=read_adc();

   printf("%2x\r", pot_board);

}
}
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sun Jan 18, 2009 7:52 am     Reply with quote

The format of the numbers is all in how you print them. You use the statement
Code:
printf("%2x\r", pot_board);
Look at the other options for printf.
_________________
The search for better is endless. Instead simply find very good and get the job done.
PICman



Joined: 02 Nov 2007
Posts: 26

View user's profile Send private message

PostPosted: Sun Jan 18, 2009 7:58 am     Reply with quote

Change your:

printf("%2x\r", pot_board);

by:

printf("%2d\r", pot_board);

And if you want to have separate variables for the 100's, 10's and units, try this code:

Code:



int8 dec_2,dec_1,dec_0;

dec_2=pot_board/100;
dec_1=(pot_board/10)%10;
dec_0=pot_board%10;


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