1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| #include <p18f4520.h>
#include <adc.h>
void main(void)
{
TRISA=1; // PORTA en Entrée
PORTA=1; // PORTA a 1
ADCON0bits.ADON = 1 ; // A/D convert ON
ADCON0bits.CHS0 = 0 ; // Choisir la voie a convertir => AN0
ADCON0bits.CHS1 = 0 ; // Choisir la voie a convertir => AN0
ADCON0bits.CHS2 = 0 ; // Choisir la voie a convertir => AN0
ADCON0bits.CHS3 = 0 ; // Choisir la voie a convertir => AN0
ADCON1bits.PCFG0 = 1 ; // Configuration des ports A/D = AN1 et AN0
ADCON1bits.PCFG1 = 0 ; // Configuration des ports A/D = AN1 et AN0
ADCON1bits.PCFG2 = 1 ; // Configuration des ports A/D = AN1 et AN0
ADCON1bits.PCFG3 = 1 ; // Configuration des ports A/D = AN1 et AN0
ADCON1bits.VCFG0 = 0 ; // references de tension a utiliser par le CAN => Vref+ = Vdd
ADCON1bits.VCFG1 = 0 ; // references de tension a utiliser par le CAN => Vref- = Vss
ADCON2bits.ADCS0 = 0 ; // configurer horloge selection
ADCON2bits.ADCS1 = 0 ; // configurer horloge selection
ADCON2bits.ADCS2 = 1 ; // configurer horloge selection
ADCON2bits.ACQT0 = 0 ; // configurer un temps d'acquisition
ADCON2bits.ACQT1 = 0 ; // configurer un temps d'acquisition
ADCON2bits.ACQT2 = 0 ; // configurer un temps d'acquisition
ADCON2bits.ADFM = 1 ; // justification a droite
ADRESH=0x00 ; // Mise à zero du registre ADRESH
ADCON0bits.GO_DONE = 1; // A/D conversion in progress (Start Of Conversion)
while(ADCON0bits.GO_DONE); // Attente de l'EOC
{
ADCON0bits.GO_DONE=0; // EOC
X=ADRESH;
X<<=8;
X|=ADRESL;
} |
Partager