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

16c771

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







16c771
PostPosted: Fri Jul 22, 2005 1:56 pm     Reply with quote

I am having trouble using the ADC on the 16C771. This is a 12 bit adc, but for some reason it is only giving me an 8 bit value. I am thinking that I have to set it up to be 12 bit instead of 8, but the header file that I have does not include anything. Any help on this would be appreciated.

Collison
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 22, 2005 2:12 pm     Reply with quote

Post your version of the compiler.
Collison
Guest







version
PostPosted: Fri Jul 22, 2005 2:20 pm     Reply with quote

MPLAB IDE 5.70.40 or
MPLAB ICE Universal Emulator v2.60.40
Collison
Guest







Sorry, wrong version
PostPosted: Fri Jul 22, 2005 2:28 pm     Reply with quote

The version that I have is v 2.705

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 22, 2005 3:55 pm     Reply with quote

Quote:
I am having trouble using the ADC on the 16C771. This is a 12 bit
adc, but for some reason it is only giving me an 8 bit value.


The "#device adc=12" directive doesn't work with your version of
the compiler, so I had to write a routine to read the 12-bit result.
See the code below.
I didn't put in the lines of code to setup the adc port, or to setup
the ADC, or to select the A/D channel, because I don't know what
pin you're using or what your PIC crystal frequency is.
I'll leave that code to you.

Code:
#include "c:\picc\examples\16C771.h"
#fuses XT,NOWDT,NOPROTECT,PUT,BROWNOUT //,NOLVP
#use delay(clock=4000000)
//===================================
#byte ADCON0 = 0x1F
#byte ADCON1 = 0x9F
#byte ADRESL = 0x9E
#byte ADRESH = 0x1E

#bit ADFM_BIT = ADCON1.7
#bit GO_BIT = ADCON0.2
#define BytePtr(var, offset) (char *)(&var + offset)

long read_adc_12_bits(void)
{
long retval;

ADFM_BIT = 1; // Right justify the A/D result
GO_BIT = 1; // Start the A/D conversion

while(GO_BIT); // Wait until conversion is done

*Byteptr(retval,0) = ADRESL; // Get LSB of result
*Byteptr(retval,1) = ADRESH; // Get MSB of result

return(retval);
}

//=================================
void main()
{
long result;

// Put in code here to setup the adc port,
// setup the ADC, and to select the A/D channel.

result = read_adc_12_bits();

while(1);
}
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