English
Language : 

PIC18F23K22 Datasheet, PDF (321/492 Pages) Microchip Technology – 28/40/44-Pin, Low-Power, High-Performance Microcontrollers with nanoWatt XLP Technology
PIC18(L)F2X/4XK22
EXAMPLE 19-1: SETUP FOR CTMU CALIBRATION ROUTINES
#include "p18cxxx.h"
/**************************************************************************/
/*Setup CTMU *****************************************************************/
/**************************************************************************/
void setup(void)
{ //CTMUCONH/1 - CTMU Control registers
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,
//CTMUICON - CTMU Current Control Register
CTMUICON = 0x01; //0.55uA, Nominal - No Adjustment
/**************************************************************************/
//Setup AD converter;
/**************************************************************************/
TRISA=0x04;
//set channel 2 as an input
// Configure AN2 as an analog channel
ANSELAbits.ANSA2=1;
TRISAbits.TRISA2=1;
// ADCON2
ADCON2bits.ADFM=1;
ADCON2bits.ACQT=1;
ADCON2bits.ADCS=2;
// Results format 1= Right justified
// Acquition time 7 = 20TAD 2 = 4TAD 1=2TAD
// Clock conversion bits 6= FOSC/64 2=FOSC/32
// ADCON1
ADCON1bits.PVCFG0 =0;
ADCON1bits.NVCFG1 =0;
// ADCON0
ADCON0bits.CHS=2;
ADCON0bits.ADON=1;
}
// Vref+ = AVdd
// Vref- = AVss
// Select ADC channel
// Turn on ADC
 2010 Microchip Technology Inc.
Preliminary
DS41412B-page 321