Bonjour, je suis débutante en microcontrôleur et je vais réaliser un projet à l'aide de pic24f256g110 et C sous Mplab. Mon but est de détecter une température à l'aide d'un capteur de température lm35 et l'afficher sur un LCD. vraiment je suis bloqué j'ai réalisé un code en se basant sur plusieurs codes sur net que j'arrive pas à l comprendre surtout tous ce qui est configuration des registres de Convertisseur analogique numérique et celle de LCD :
Merci d'avanceCode:#include "p24fj256GB110.h" // JTAG/Code Protect/Write Protect/Clip-on Emulation mode //Watchdog Timer/ICD pins select _CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2) // Disable CLK switch and CLK monitor, OSCO or Fosc/2, HS oscillator, // Primary oscillator _CONFIG2(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI) ////////////////////////////////////////////////////////* Digital Thermometer using PIC24F and LM35 ///Internal Oscillator @ 4MHz, MCLR Enabled, PWRT Enabled, WDT OFF Copyright @ Rajendra Bhatt November 8, 2010 */ // LCD module connections // LCD display ports etc #define LCD_RS LATD0_bit; //sbit LCD_EN at LATD1_bit; //sbit LCD_D4 at LATD2_bit; //sbit LCD_D5 at LATD3_bit; //sbit LCD_D6 at LATD4_bit; //sbit LCD_D7 at LATD5_bit; #define LCDdata LATE // data port #define LCDdataEnable TRISE #define RS LATBbits.LATB15 // RS bit in LCDstatus #define RW LATDbits.LATD5 // read/write bit in LCDstatus #define E LATDbits.LATD4 // enable bit in LCDstatus #define Eenable TRISDbits.TRISD4 #define ERSenable TRISDbits.TRISD5 #define RWenable TRISBbits.TRISB15 void lcd_delay() { mSecDelay(2); } // if LCD does not work make this longer // Write a nibble to the LCD // may have to adjust delays to suit the processor and clock void lcdNibble(int n) { int lcd=LCDdata; lcd_delay(); LCDdata=n; lcd_delay(); E=1; // take clock E high lcd_delay(); E=0; lcd_delay(); } // Write a Control Command to the LCD // This is written as two nibbles void lcdCmd(int c) { RS=0; // Take RS pin low for command lcdNibble(c); // Makeup Lower Nibble } // write a data byte to LCD int lcdPutchar(int d) { // printf("%c", d); RS=1; // Take RS pin high for data lcdNibble(d); // Makeup Lower Nibble return 1; } // Initialise the LCD in 4bit Mode void lcdInit() { E=0; // take E low RS=0; // Take RS pin low for command RW=0; // Take RS pin low for command // set RS, RW and E bits as output Eenable =0; ERSenable =0; RWenable =0; LCDdataEnable &= 0x0; // set bits 0-3 output for data lcdNibble(0x3); // This put the LCD into Soft Reset lcdNibble(0x3); lcdNibble(0x3); lcdNibble(0x2); lcd_delay(); // lcdCmd(0x28); // 2 line, 4 bit mode lcdCmd(0x38); // 2 line, 8 bit mode lcd_delay(); lcdCmd(0x6); // increment cursor after each write lcd_delay(); lcdCmd(0x1); // clear display lcd_delay(); lcdCmd(0x2); // home lcd_delay(); lcdCmd(0xF); // turn disply on lcd_delay(); } // End LCD module connections // Define Messages char message0[] = "LCD Initialized"; char message1[] = "Room Temperature"; // String array to store temperature value to display char *tempC = "000.0"; char *tempF = "000.0"; // Variables to store temperature values unsigned int tempinF, tempinC; unsigned long temp_value; void Display_Temperature() { // convert Temp to characters if (tempinC/10000) // 48 is the decimal character code value for displaying 0 on LCD tempC[0] = tempinC/10000 + 48; else tempC[0] = ' '; tempC[1] = (tempinC/1000)%10 + 48; // Extract tens digit tempC[2] = (tempinC/100)%10 + 48; // Extract ones digit // convert temp_fraction to characters tempC[4] = (tempinC/10)%10 + 48; // Extract tens digit // print temperature on LCD Lcd_Out(2, 1, tempC); if (tempinF/10000) tempF[0] = tempinF/10000 + 48; else tempF[0] = ' '; tempF[1] = (tempinF/1000)%10 + 48; // Extract tens digit tempF[2] = (tempinF/100)%10 + 48; tempF[4] = (tempinF/10)%10 + 48; // print temperature on LCD Lcd_Out(2, 10, tempF); } int main (void) { // ANSEL = 0b00000100; // RA2/AN2 is analog input // ADCON0 = 0b01001000; // Connect AN2 to S/H, select Vref=1.19V //CMCON0 = 0x07 ; // Disbale comparators //////////////////////////////////////////Converting One Channel, Manual Sample Start, Manual Conversion Start Code/////////////////////////////////////////////////// int ADCValue; AD1PCFG = 0xFFFB; // AN2 as analog, all other pins are digital AD1CON1 = 0x0000; // SAMP bit = 0 ends sampling and starts converting AD1CHS0 = 0x0002; // Connect AN2 as S/H+ input // in this example AN2 is the input AD1CSSL = 0; AD1CON3 = 0x0002; // Manual Sample, Tad = 3Tcy AD1CON2 = 0; AD1CON1bits.ADON = 1; // turn ADC ON while (1) // repeat continuously { AD1CON1bits.SAMP = 1; // start sampling... Delay(); // Ensure the correct sampling time has elapsed // before starting conversion. AD1CON1bits.SAMP = 0; // start converting while (!AD1CON1bits.DONE){}; // conversion done? ADCValue = ADC1BUF0; // yes then get ADC value } TRISC = 0b00000000; // PORTC All Outputs TRISA = 0b00001110; // PORTA All Outputs, Except RA3 and RA2 lcdInit() Delay(); Lcd_Out(1,1,message1); // Write message1 in 1st row // Print degree character Lcd_Chr(2,6,223); Lcd_Chr(2,15,223); // Different LCD displays have different char code for degree symbol // if you see greek alpha letter try typing 178 instead of 223 Lcd_Chr(2,7,'C'); Lcd_Chr(2,16,'F'); do { temp_value = ADC_Read(2); temp_value = temp_value*1168; tempinC = temp_value/1000; tempinC = tempinC*10; tempinF = 9*tempinC/5 + 3200; Display_Temperature(); Delay_ms(1000); // Temperature sampling at 1 sec interval } while(1); }
-----