ings
Member level 4
- Joined
- Sep 8, 2014
- Messages
- 78
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 988
Hello, I am a beginner in PIC and in my project I want to detect the temperture of a room with an LM35 sensor and a PIC24F. and finally, I want to display the temperature value on an LCD. I tried with this code that I'm sure that contains many errors. In fact my problem is with the configuraion of ADC registers and also that of LCD. Here is my code that I can not understand:
My code is a mixture of several of the codes on the net it shows me these errors:
Thank you in advance
Code C - [expand] 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 #include "p24fxxxx.h" #include "adcDrv1.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 sbit LCD_RS at RC4_bit; sbit LCD_EN at RC5_bit; sbit LCD_D4 at RC0_bit; sbit LCD_D5 at RC1_bit; sbit LCD_D6 at RC2_bit; sbit LCD_D7 at RC3_bit; sbit LCD_RS_Direction at TRISC4_bit; sbit LCD_EN_Direction at TRISC5_bit; sbit LCD_D4_Direction at TRISC0_bit; sbit LCD_D5_Direction at TRISC1_bit; sbit LCD_D6_Direction at TRISC2_bit; sbit LCD_D7_Direction at TRISC3_bit; // 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 int ADCValue; AD1PCFG = 0xFFFB; // AN2 as analog, all other pins are digital AD1CON1 = 0x0000; // SAMP bit = 0 ends sampling and starts converting AD1CHS = 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 Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // CLEAR display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,1,message0); Delay_ms(1000); 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); }
My code is a mixture of several of the codes on the net it shows me these errors:
Please help meTMR3ADC.c:19: error: syntax error before 'at'
TMR3ADC.c:19: warning: type defaults to 'int' in declaration of 'RC4_bit'
TMR3ADC.c:19: warning: data definition has no type or storage class
TMR3ADC.c:20: error: syntax error before 'LCD_EN'
TMR3ADC.c:20: warning: type defaults to 'int' in declaration of 'RC5_bit'
TMR3ADC.c:20: warning: data definition has no type or storage class
TMR3ADC.c:21: error: syntax error before 'LCD_D4'
TMR3ADC.c:21: warning: type defaults to 'int' in declaration of 'RC0_bit'
TMR3ADC.c:21: warning: data definition has no type or storage class
TMR3ADC.c:22: error: syntax error before 'LCD_D5'
TMR3ADC.c:22: warning: type defaults to 'int' in declaration of 'RC1_bit'
TMR3ADC.c:22: warning: data definition has no type or storage class
TMR3ADC.c:23: error: syntax error before 'LCD_D6'
TMR3ADC.c:23: warning: type defaults to 'int' in declaration of 'RC2_bit'
TMR3ADC.c:23: warning: data definition has no type or storage class
TMR3ADC.c:24: error: syntax error before 'LCD_D7'
TMR3ADC.c:24: warning: type defaults to 'int' in declaration of 'RC3_bit'
TMR3ADC.c:24: warning: data definition has no type or storage class
TMR3ADC.c:25: error: syntax error before 'LCD_RS_Direction'
TMR3ADC.c:25: warning: type defaults to 'int' in declaration of 'TRISC4_bit'
TMR3ADC.c:25: warning: data definition has no type or storage class
TMR3ADC.c:26: error: syntax error before 'LCD_EN_Direction'
TMR3ADC.c:26: warning: type defaults to 'int' in declaration of 'TRISC5_bit'
TMR3ADC.c:26: warning: data definition has no type or storage class
TMR3ADC.c:27: error: syntax error before 'LCD_D4_Direction'
TMR3ADC.c:27: warning: type defaults to 'int' in declaration of 'TRISC0_bit'
TMR3ADC.c:27: warning: data definition has no type or storage class
TMR3ADC.c:28: error: syntax error before 'LCD_D5_Direction'
TMR3ADC.c:28: warning: type defaults to 'int' in declaration of 'TRISC1_bit'
TMR3ADC.c:28: warning: data definition has no type or storage class
TMR3ADC.c:29: error: syntax error before 'LCD_D6_Direction'
TMR3ADC.c:29: warning: type defaults to 'int' in declaration of 'TRISC2_bit'
TMR3ADC.c:29: warning: data definition has no type or storage class
TMR3ADC.c:30: error: syntax error before 'LCD_D7_Direction'
TMR3ADC.c:30: warning: type defaults to 'int' in declaration of 'TRISC3_bit'
TMR3ADC.c:30: warning: data definition has no type or storage class
TMR3ADC.c: In function 'Display_Temperature':
TMR3ADC.c:60: warning: implicit declaration of function 'Lcd_Out'
TMR3ADC.c: In function 'main':
TMR3ADC.c:91: warning: implicit declaration of function 'Delay'
TMR3ADC.c:101: warning: implicit declaration of function 'Lcd_Init'
TMR3ADC.c:102: warning: implicit declaration of function 'Lcd_Cmd'
TMR3ADC.c:102: error: '_LCD_CLEAR' undeclared (first use in this function)
TMR3ADC.c:102: error: (Each undeclared identifier is reported only once
TMR3ADC.c:102: error: for each function it appears in.)
TMR3ADC.c:103: error: '_LCD_CURSOR_OFF' undeclared (first use in this function)
TMR3ADC.c:105: warning: implicit declaration of function 'Delay_ms'
TMR3ADC.c:108: warning: implicit declaration of function 'Lcd_Chr'
TMR3ADC.c:115: warning: implicit declaration of function 'ADC_Read'
Thank you in advance
Last edited by a moderator: