![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Collison Guest
|
16c771 |
Posted: Fri Jul 22, 2005 1:56 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 22, 2005 2:12 pm |
|
|
Post your version of the compiler. |
|
![](templates/subSilver/images/spacer.gif) |
Collison Guest
|
version |
Posted: Fri Jul 22, 2005 2:20 pm |
|
|
MPLAB IDE 5.70.40 or
MPLAB ICE Universal Emulator v2.60.40 |
|
![](templates/subSilver/images/spacer.gif) |
Collison Guest
|
Sorry, wrong version |
Posted: Fri Jul 22, 2005 2:28 pm |
|
|
The version that I have is v 2.705
Thanks |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 22, 2005 3:55 pm |
|
|
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);
} |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|