#include #include <../_common/LCD2x16_lite.h> #include // sprintf #include #include #include #include // pour fonctions UART #include #include #include #include #include // HARDWARE // Q=10Mhz // ATTENTION alim 3,6V maxi //1 MCLR 4,K +VSS //2 RA0 Analog input //3 RA1 Analog input //4 RA2 //5 RA3 //6 RA4 Output Led rouge //7 RA5 //8 +3,6V //9 RA6 clockIN Quartz 10Mhz 22pF //10 RA7 clockOUT Quartz 10Mhz 22pF //11 RC0 //12 RC1 //13 RC2 //14 RC3 //------- //28 RB7 Data D7 LCD //27 RB6 Data D6 LCD //26 RB5 Data D5 LCD //25 RB4 Data D4 LCD //24 RB3 En LCD //23 RB2 RS LCD //22 RB1 //21 RB0 //20 GND 0V //19 VSS +3,6V //18 RC7 //17 RC6 //16 RC5 //15 RC4 //#define OSCILLATEUR_INTERNE #ifdef OSCILLATEUR_INTERNE #pragma config FOSC = INTIO67, FCMEN = OFF // CONFIG1H #else #pragma config FOSC = HS, IESO=OFF ,FCMEN=OFF, LPT1OSC=OFF #endif #pragma config PWRT=OFF,BOREN=OFF,WDTEN=OFF #pragma config PBADEN=OFF,CCP2MX=PORTC #pragma config MCLRE=ON,STVREN=OFF,LVP=OFF,XINST=OFF,DEBUG=OFF #pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF // CONFIG5L #pragma config CPB = OFF, CPD = OFF // CONFIG5H #pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF // CONFIG6L #pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF // CONFIG6H #pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF // CONFIG7L #pragma config EBTRB = OFF // CONFIG7H #pragma romdata EEP_=0xF00000 #define CLS 12 #define BS 8 #define TAB 9 #define CR 13 #define LF 10 #define Bell 7 #define STX 0x02 #define ETX 0x03 #define ON 0 // logique inverse avec led tiree au +5V #define OFF 1 #define OUT_RS232 Flags.Drapeaux.Lcd=0; #define MAX_LEN 200 #define DureeCycle 10 // 10 x 200mS soit 2sec @10Mhz #define Led_Rouge LATAbits.LATA4 #define Word unsigned int #define Byte unsigned char unsigned int i,j,k; unsigned char tampon[16]; unsigned char CRam[32]; static unsigned char Entree[16]="123456789012345"; unsigned char *valtxt=&Entree[0]; char Texte[64]="PROJET C18 :18F26K2x_LCD2x16.mcp\r"; unsigned char * txt=&Texte[0]; unsigned int EAx; float f1; void Init_ADC(void); void Init_Hardware(void); unsigned int Mesure_ADC(int canal); unsigned int Mesure_ADC(int canal) { unsigned int EA; //ADCON0bits.ADON=1; ADCON0=1 + (canal<<2); // ADON=1 et choix de canal Delay10TCYx( 10 ); // Delay for 100TCY ConvertADC(); // Start conversion while( BusyADC() ); EA = ReadADC(); // Read result return (EA); } // itoa( EAx,tampon); // Put_RS('E');Put_RS('A');Put_RS(canal+48);Put_RS('='); // k=PutStr_RS(tampon); // Tempo(5000L); //} void Init_Hardware() { PORTB = 0xFF; TRISB = 0x00; // All Outputs ANSELH=0; // no analog INTCON2bits.RBPU=0; // enable Pull-up WPUB=0xFF; // all pin with pull up // ATTENTION a l'ordre des canaux ANALOGIQUES !!! ANSEL=0; ANSELbits.ANS0=1; // analog input on Port A voir page 154 ANSELbits.ANS1=1; LATA = 0x00; TRISA = 0b00001111 ; //RA0,RA1=analog input, RA2,RA3=input, RA4,RA5=output PORTA=0; PORTC = 0xFF; // set PORTC to $FF TRISC = 0b10111111; // all input expect RC6 TRISCbits.TRISC0 = 1; TRISCbits.TRISC1 = 1; TRISCbits.TRISC2 = 1; TRISCbits.TRISC3 = 1; TRISCbits.TRISC4 = 1; TRISCbits.TRISC5 = 1; TRISCbits.TRISC6 = 0; // TX - Set as Output UART RS232 and Bootloader TRISCbits.TRISC7 = 1; // RX - Set Receive pin for UART RS232 and Bootloader RCONbits.IPEN=1 ; // enable priority levels RCONbits.SBOREN=0; // BOR disbled SLRCON=0; // standard rate for PORTA,B,C,D,E } void Init_ADC() { //config lecture ADC 10 bits ADCON0bits.ADON=1; // ADC enabled chanel 0 ADCON1bits.VCFG1=0; // +Vref = +5V AVdd ADCON1bits.VCFG0=0; // -Vref = Gnd AVss ADCON2bits.ADFM=1; // right justified ADCON2bits.ACQT2=1; ADCON2bits.ACQT1=1; ADCON2bits.ACQT0=0; // 16 TAD ADCON2bits.ADCS2=1; ADCON2bits.ADCS1=0; ADCON2bits.ADCS0=1; // Fosc/16 } void main(void) { Init_Hardware(); Init_ADC(); Led_Rouge=ON; Delay10KTCYx(250); Led_Rouge=OFF; XLCDInit(); Erase_Ligne(1); XLCDPutRomString(" SALUT "); Delay10KTCYx(250); Erase_Ligne(2); XLCDPut('H'); //write to LCD XLCDPut('E'); XLCDPut('L'); XLCDPut('L'); XLCDPut('L'); XLCDPut('O'); Delay10KTCYx(250); Erase_Ligne(2); XLCDPutRomString("Mesure CH0"); //partie fixe while(1) { Led_Rouge=!Led_Rouge; EAx=Mesure_ADC(0); // * txt=&Texte[0]; k=sprintf(txt,"%04d",EAx); XLCD_pos(2,11); XLCDPutRamString(txt); Delay10KTCYx(150); } }