Datasheet
2012 Microchip Technology Inc. DS30575A-page 515
PIC18F97J94 FAMILY
EXAMPLE 26-1: SETUP FOR CTMU CALIBRATION ROUTINES
#include "p18cxxx.h"
/**************************************************************************/
/*Setup CTMU *****************************************************************/
/**************************************************************************/
void setup(void)
{ //CTMUCON - CTMU Control register
CTMUCON = 0x00; //make sure CTMU is disabled
CTMUCON3 = 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
//CTMUCON1 - CTMU Current Control Register
CTMUCON1 = 0x01; //0.55uA, Nominal - No Adjustment
/**************************************************************************/
//Setup AD converter;
/**************************************************************************/
TRISBbits.TRISB0=0;
TRISAbits.TRISA2=1; //set channel 2 as an input
ANCON1bits.ANSEL2=1; // Configured AN2 as an analog channel
ADCON1Hbits.FORM=0b00; // Result format 1= Right justified
ADCON1Lbits.SSRC=0b0111;
ADCON3Hbits.SAMC=0b00111; // Acquisition time 7 = 20TAD 2 = 4TAD 1=2TAD
ADCON3Lbits.ADCS=0x3F; // Clock conversion bits 6= FOSC/64 2=FOSC/32
// ADCON1
ADCON2Hbits.PVCFG=0b00; // Vref+ = AVdd
ADCON2Hbits.NVCFG0=0; // Vref- = AVss
ADCHS0Lbits.CHONA=0b000;
ADCHS0Lbits.CHOSA=0b00010; // Select ADC channel
ADCON1Hbits.ADON=1; // Turn on ADC
}