English
Language : 

PIC18F87K22 Datasheet, PDF (390/548 Pages) Microchip Technology – 64/80-Pin, High-Performance, 1-Mbit Enhanced Flash Microcontrollers with 12-Bit A/D and nanoWatt XLP Technology
PIC18F87K22 FAMILY
EXAMPLE 27-1: SETUP FOR CTMU CALIBRATION ROUTINES
#include "p18cxxx.h"
/**************************************************************************/
/*Setup CTMU *****************************************************************/
/**************************************************************************/
void setup(void)
{ //CTMUCON - CTMU Control register
CTMUCONH = 0x00;
//make sure CTMU is disabled
CTMUCONL = 0X90;
//CTMU continues to run when emulator is stopped,CTMU continues
//to run in idle mode,Time Generation mode disabled, Edges are blocked
//No edge sequence order, Analog current source not grounded, trigger
//output disabled, Edge2 polarity = positive level, Edge2 source =
//source 0, Edge1 polarity = positive level, Edge1 source = source 0,
// Set Edge status bits to zero
//CTMUICON - CTMU Current Control Register
CTMUICON = 0x01;
//0.55uA, Nominal - No Adjustment
/**************************************************************************/
//Setup AD converter;
/**************************************************************************/
TRISA=0x04;
//set channel 2 as an input
// Configured AN2 as an analog channel
// ANCON0
ANCON0 = 0X04;
// ANCON1
ANCON1 = 0XE0;
// ADCON2
ADCON2bits.ADFM=1;
ADCON2bits.ACQT=1;
ADCON2bits.ADCS=2;
// Resulst format 1= Right justified
// Acquition time 7 = 20TAD 2 = 4TAD 1=2TAD
// Clock conversion bits 6= FOSC/64 2=FOSC/32
// ADCON0
ADCON1bits.VCFG0 =0;
ADCON0bits.VCFG1 =0;
ADCON0bits.VCFG = 0;
ADCON0bits.CHS=2;
// Vref+ = AVdd
// Vref+ = AVdd
// Vref- = AVss
// Select ADC channel
ADCON0bits.ADON=1;
// Turn on ADC
}
DS39960B-page 390
Preliminary
 2010 Microchip Technology Inc.