View previous topic :: View next topic |
Author |
Message |
IceMetal
Joined: 20 Nov 2008 Posts: 79 Location: white Plains, NY
|
convert the ADC hex data into dec |
Posted: Sun Jan 18, 2009 4:54 am |
|
|
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
|
|
Posted: Sun Jan 18, 2009 7:52 am |
|
|
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
|
|
Posted: Sun Jan 18, 2009 7:58 am |
|
|
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;
|
|
|
|
|