Syntax Problem with compiler

Status
Not open for further replies.
I

imroun1992

Guest
Hello,

I had already post a thread about I2C Communication & LM75 Thermometer .. After several time, I wrote a program which is used to read temperature :

Code:
#include <LPC43xx.h>                    
#include "LED.h"
#include "KBD.h"
#include "GLCD.h"
#include "I2C.h"
#include "TH_LM75.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#define Font1       1                       
#define Font0       0  	

#define STRINGBUF_LEN   21
char StringBuf[STRINGBUF_LEN];

/*** Prototypes des fonctions ***/

void configuration_lm75(char);
int  acquisition_temperature(void);
void DisplayTemp(void);

/*** Fonction principal ***/
int main(void)
{


    I2C_Init();              
    TH_Init();  
		GLCD_Init();
	
		GLCD_Clear (White);
    GLCD_SetBackColor  (Blue);
    GLCD_SetTextColor  (White);
    GLCD_DisplayString (0, 0, 1, "    Project      ");
    GLCD_DisplayString (1, 0, 1, "  Electronics    ");
    GLCD_SetBackColor  (White);
    GLCD_SetTextColor  (Blue);
    
    

    while(1)
    {
						configuration_lm75(0x00);    
						
						DisplayTemp();
			
						configuration_lm75(0x01);      
        
  
        
    }
}
/* Ecriture des données dans le registre de configuration du LM75 */

void configuration_lm75(char data)
{
    I2C_Start();
    I2C_Write(0x90);        // Slave address + Write
    I2C_Write(0x01);        // Configuration register address
    I2C_Write(data);        // Data to register
    I2C_Stop();
}

/* Lecture de la température */

int acquisition_temperature(void)
{
    int data;
		TH_DATA Temp;
    signed char high, low;
    I2C_Start();
    I2C_Write(0x90);        // Slave address + Write
    I2C_Write(0x00);        // Temperature register address
    I2C_Start();
    I2C_Write(0x90|0x01);   // Slave address + Read
		TH_GetTemp(&Temp);
		
		
    I2C_Stop();

    data = high;
    data *= 10;
    if(low & 0x80)          
        data += 5;
    return data;
}

void DisplayTemp(void)
{
    int temp;

    temp = acquisition_temperature();    // Leer temperatura

    sprintf("\r\n Temp = %d.%d C",&temp/10, abs(temp%10));
}

In the void function DisplayTemp(void) at last line "sprintf...", there is a mistake i don't know what is it, anyone to help me Compiler said :

argument of type "int" is incompatible with parameter of type "const char *restrict"

Anyone to help I include with this post the LCD Screen source files

Kind regards
 

Attachments

  • mcb4300v1-3-schematics.pdf
    599.1 KB · Views: 50
  • source files.zip
    5 KB · Views: 43
  • LCD_source_files.zip
    3.1 KB · Views: 43

I presume you cannot perform the division operation directly over a pointer variable.
Try replace these 2 lines for aimplementation bellow :

Code:
    temp = ( acquisition_temperature() ) /10;    // Leer temperatura
    sprintf("\r\n Temp = %d.%d C",&temp, abs(temp%10));


+++
 

Hello,

There is same problem, your code not working. compiler said same things
 

I don´t know what compiler are you using, but are you sure can use pointer variable ?
I presue correct way is the following :

Code:
sprintf("\r\n Temp = %d.%d C",temp, abs(temp%10));   ////// removed '&' statement before temp variable

+++
 

your code is not working i have the same message, can you see the source file named "TH_LM75 that i had included with this thread
 


Code C - [expand]
1
int sprintf(char *str, const char *format, ...)



https://www.tutorialspoint.com/c_standard_library/c_function_sprintf.htm


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
unsigned char strTemp[8];
 
 
strTemp[0] = temp / 100 + 48;
strTemp[1] = (temp / 10) % 10 + 48;
strTemp[2] = (temp % 10) + 48;
strTemp[3] = '.'
strTemp[4] = abs(temp % 10) + 48;
strTemp[5] = '\0';
 
sprintf("\r\n Temp = %s C", strTemp);




Also try

[

Code C - [expand]
1
2
3
unsigned char myString[20];
 
sprintf(myString, "\r\n Temp = %d.%d C", temp, abs(temp%10));

 
Last edited:

Hello,

i attached uvision project files
 

Attachments

  • uvision project_thermometer_proj.zip
    28.2 KB · Views: 47

doesnt sprintf needs a buffer to save de string? i would try sprintf (buffer,"message",variables);
 

Which file contains the sprintf() function?


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
#pragma hdrstop
#pragma argsused
 
#include <stdio.h>
#include <tchar.h>
#include <math.h>
#include <string.h>
 
int _tmain(int argc, _TCHAR* argv[])
{
    int temp;
    char myString[20];
 
    temp = 2456;
 
    sprintf(myString, "Temp = %d.%d C", temp, abs(temp%10));
    printf("myString contains %s", myString);
 
    scanf("%d", &temp);
 
    return 0;
}

 

Attachments

  • sprintf.rar
    838.2 KB · Views: 41
Last edited:

Hello,

I don't know but i would like to display temperature in LCD screen, can you check the program if all I2C syntax are correct please,

I think sprintf is belong to #include <stdio.h>
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…