|
try it
#include <p18cxxx.h>
#include <adc.h>
#pragma config OSC=HS
#pragma config PWRT=OFF
#pragma config BOREN=OFF, BORV=1
#pragma config WDT=OFF
#pragma config CCP2MX=PORTC
#pragma config STVREN=OFF, LVP=OFF, DEBUG=OFF
#pragma config CPD=OFF
void InitializeAD(void);
void main(void)
{
TRISD=0; // Set PORTD for LED output
InitializeAD( ); // Initial A/D module
while(1)
{
ConvertADC(); // Convert A/D
while(BusyADC( )); // Waiting A/D until done
PORTD=ADRESH; // Put A/D result on LEDs
}
}
//************************************************
//* PIC18F4520 ADC Peripheral Library 耴摸 *
//* V5 , ㄏノ OpenADC() 璶把σ *
//* Function: InitializeAD *
//* - Fosc/32 clock source *
//* - Left justified *
//* - 1 analog channels, 0 references *
//* - Channel 0 *
//* - Disable A/D interrupt *
//************************************************
void InitializeAD(void)
{
OpenADC( ADC_FOSC_32
& ADC_LEFT_JUST
& ADC_4_TAD,
ADC_CH0
& ADC_INT_OFF
& ADC_REF_VDD_VSS,
ADC_1ANA);
}
|
|