//arlotto 2006 : correction tp formation lp #include #include "xlcd100.h" #include // pour printf #include // pour fonctions adc #include // configuration PICDEM2+ quartz #pragma config OSC = HS #pragma config WDT = OFF #pragma config LVP = OFF #define Led3 PORTBbits.RB3 #define Led2 PORTBbits.RB2 #define Led1 PORTBbits.RB1 #define Led0 PORTBbits.RB0 #define BtnS3 PORTBbits.RB0 #define BtnS2 PORTAbits.RA4 void main(void){ int x , result ; char etat = 0 ; char cpt = 0 ; char cpt_old = 11 ; // valeur impossible pour cpt int result_old = -1 ; long milliVolts ; Led3 = 0 ; TRISB = 0x01 ; OpenXLCD(OPEN_PICDEM_LCD); stdout =_H_USER ; OpenADC(ADC_FOSC_4 & ADC_RIGHT_JUST & ADC_1ANA_0REF , ADC_CH0 & ADC_INT_OFF ); Delay10TCYx(5); // temps d'attente // après le démarrage de l'adc // affichages constants printf("cpt="); gotoXLCD(LCD_LINE_TWO); printf("RA0: , mV"); for( ;; ) { if (BtnS3 == 0 ) { Led1 = 1 ; } else { Led1 = 0 ; } switch(etat) { case 0 : if(!BtnS3 && cpt<10) { etat = 1 ; } else if(!BtnS2 && cpt>0) { etat = 2 ; } break ; case 1 : cpt++; etat = 11 ; break ; case 2 : cpt--; etat = 22 ; break ; case 11 : if(BtnS3) { etat = 0 ; } break ; case 22 : if(BtnS2) { etat = 0 ; } break ; } if ( cpt >= 5 ) { Led2=1 ; } else { Led2 = 0 ; } ConvertADC(); while( BusyADC() ) ; // delais de 12us max result = ReadADC(); // mise à jour lcd if(cpt != cpt_old) { gotoXLCD(LCD_LINE_ONE+4); printf("%2d",cpt); cpt_old = cpt ; } if(result != result_old) { milliVolts = (5000L * result) / 1023L ; gotoXLCD(LCD_LINE_TWO+4); // printf("%4d,%4ld mV",result,milliVolts); // pour afficher mV printf("%4d,%1ld.%03ld V",result,milliVolts/1000L,milliVolts%1000L); result_old = result ; } // clignotement; x++; if (x>=1000){ Led3 = !Led3 ; x=0; } } }