P. 1
An Introduction to Programming the Microchip PIC in CCS C

An Introduction to Programming the Microchip PIC in CCS C

|Views: 90|Likes:
Published by alanjb

More info:

Published by: alanjb on Oct 05, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

11/20/2013

pdf

text

original

The A/D in the 16C7x and 12C67x devices has a resolution of 8 bits. This means
that the voltage being measured can be resolved to one of 255 values. If a 5
volt supply is used, then the measured accuracy is 5/255 = 19.6mV over a 0 to
5 volt range. However, if the reference voltage is reduced to 2.55 volts, the
resolution becomes 10mV but the working range falls to 0 to 2.55 volts.

Other Microchip parts have 10, 11, 12 and 16 bits resolution.

NOTE:

The default for ports having both analog and digital capability is ANALOG.

It is important to note which combination of I/O lines can be used for analog
and digital. The following tables are extracted from the data sheets.

16C72/3

16C74 only

A0, A1

A2

A3

A5

E0

E1

E2

Vref

A

A

A

A

A

A

A

Vdd

A

A

Vref

A

A

A

A

A3

A

D

A

A

D

D

D

Vref

D

D

Vref

A

D

D

D

A3

117

A

A

A

D

D

D

D

Vref

A

A

Vref

D

D

D

D

A3

D

D

D

D

D

D

D

---

16C71, 16C710, 16C711

A0, A1

A2

A3

Vref

A

A

A

Vdd

A

A

Vref

A3

A

D

D

Vdd

D

D

D

---

In C, the setup and operation of the A/D is simplified by ready made library
routines.

set_adc_channel(0-7)

select the channel for a/d conversion

setup_adc(mode)

sets up the analog to digital converter
The modes are as follows:

adc_off, adc_clock_div_2, adc_clock_div_8,
adc_clock_div_32,adc_clock_internal

setup_adc_ports(mix)

will setup the ADC pins to be analog, digital or
combination. The allowed combinations for mix vary
depending on the chip.
The constants all_analog and no_analog are valid
for all chips. Some other example constants:
ra0_ra1_ra2_ra3_analog/a0_ra1_analog_ra3_ref

read_adc()

will read the digital value fro the analog to digital
converter. Calls to setup_adc and set_adc_channel
should be made sometime before this function is
called. This function returns an 8-bit value 00h – FFh
on parts with an 8 bits A/D converter. On parts with
greater than 8 bits A/D the value returned is always a
long with the range 000h – FFFFh.
The range may be fixed regardless of the part to aid
in compatibility across parts by adding on of the
following directives:

#device ADC=8
#device ADC=16

Example

setup_adc(ALL_ANALOG);//sets porta to all analog inputs
set_adc_channel(1);

//points a/d at channel 1

delay_ms(5000);

//waits 5 seconds
value = read_adc();//reads value

118

printf(“A/D value = %2x\n\r”, value);//prints value

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->