attention aux differences, en particulier avec les entrees ana
voici une sequence d'init Hardware.. à adapter à ton programme
Code:void Init_Hardware() { // B7 data 14 LCD & ICSP bleu fcé PORTB = 0xFF; ANSELB=0; TRISB =0x80; //.. ATTENTION B7 B6 for ICSP Pickit3 INTCON2bits.RBPU=0; // enable All pull up WPUB=0xFF; // any pin pull up // ATTENTION a l'ordre des canaux ANALOGIQUES !!! ANSELA=0; PORTA = 0xFF; ANSELAbits.ANSA0=1; // RA0 analog input for Temper ext LM335 ANA voir page 154 ANSELAbits.ANSA1=1; // RA1 analog input for Temper int L35DZ ANSELAbits.ANSA2=1; // RA2 analog input for LDR TRISA = 0b11101111 ; // PORTA is RA0,RA1= analog input, RA2,RA3=input RA4,RA5=Digital output PORTC = 0xFF; // set PORTC to $FF ANSELC=0; TRISC = 0b10000000; // all output expect RC7 // ANSELD=0; TRISD=0xFF; TRISDbits.TRISD0=0; // sortie 1 (RFO basic app) TRISDbits.TRISD1=0; // sortie 2 (RFO basic app) TRISDbits.TRISD2=0; // sortie Reset RN41 TRISDbits.TRISD6=0; // D6 UART2 TX --> TRISDbits.TRISD7=1; // D7 <-- RX UART2 // ANSELE=0; PORTE=0x00; TRISE=0x07; // RE0,RE1,RE2 as input RCONbits.IPEN=1 ; // enable priority levels RCONbits.SBOREN=0; // BOR disbled SLRCON=0; // standard rate for PORTA,B,C,D,E }
de meme, ta routine void Init_CAN(void)
n'est pas bonne....
l'init ADC est differente, car plus de possibilités
exemple:
Code:void Init_ADC() { //config lecture ADC 10 bits voir page 297 DS ADCON0bits.ADON=1; // ADC enabled chanel 0 ADCON1bits.PVCFG1=1; // +Vref sur reference 4.096V de FVR Buf2 ADCON1bits.PVCFG0=0; // voir page 305 datasheet ADCON1bits.NVCFG=0; // -Vref = Gnd AVss ADCON2bits.ADFM=1; // right justified ADCON2bits.ACQT2=1; ADCON2bits.ACQT1=1, // 16 TAD ADCON2bits.ACQT0=0; //ADCON2bits.ACQT=5; // 12 TAD //ADCON2bits.ACQT=6; // 16 TAD //ADCON2bits.ACQT=7; //20 TAD //ADCON2bits.ADCS2=1; //ADCON2bits.ADCS1=0; //ADCON2bits.ADCS0=1; // Fosc/16 ADCON2bits.ADCS2=0; ADCON2bits.ADCS1=1; ADCON2bits.ADCS0=0; // Fosc/32 //ADCON2bits.ADCS2=1; //ADCON2bits.ADCS1=1; //ADCON2bits.ADCS0=0; // Fosc/64 VREFCON0bits.FVREN=1; // enabled //VREFCON0bits.FVRS1=1; //VREFCON0bits.FVRS0=1; // 4.096V VREFCON0bits.FVRS=3; //4.096V VREFCON0bits.FVRST=1; // ready to use ??? }
-----