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

ADC 12bits

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



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

ADC 12bits
PostPosted: Mon Oct 19, 2009 9:33 am     Reply with quote

Hi, I'm trying to use the 12-bit ADC of 18F4458, the result I want to put in two registers, as I do to separate the ADC result into two bytes?

Code:
#include <18F4458.h>
#device adc=12
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#byte ADRESL = 0xFC3
#byte ADRESH = 0xFC4

//=================================
void main()
{
int16 value;
int8 Buffer_ADC[2];

setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
delay_us(15);

while(1)
  { 
   value = read_adc();                         
   Buffer_ADC[0] = valueL??;      // MSB                 
   Buffer_ADC[1] = valueH??;      // LSB
 
    //printf("%lu \n\r", value);
    delay_ms(500);
  }
}
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Mon Oct 19, 2009 9:38 am     Reply with quote

Code:

Buffer_ADC[0] = make8(value, 0);
Buffer_ADC[1] = make8(value, 1);

_________________
David
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Tue Oct 20, 2009 7:31 am     Reply with quote

Thank you..
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