CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Question on Flexible "I2C" LCD driver (PCF8574T)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cbarberis



Joined: 01 Oct 2003
Posts: 172
Location: Punta Gorda, Florida USA

View user's profile Send private message Send e-mail

Question on Flexible "I2C" LCD driver (PCF8574T)
PostPosted: Sun Jul 05, 2020 10:05 am     Reply with quote

Flexible "I2C" LCD driver (PCF8574T) by Hugo Silva:
http://www.ccsinfo.com/forum/viewtopic.php?t=54063

For some reason I thought this nice piece of code just translated PCM Programmer's Flexible LCD directly to the I2C stream but apparently it is different and although it works fine it does not support the floats so if I send a printf(lcd_putc" float value = %f", float var); it gives me an error telling me it only supports characters. Is there anyway around this to show floats?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 06, 2020 10:13 am     Reply with quote

It's because you got impatient and did this:
Quote:
printf(lcd_putc" float value = %f", float var);

CCS generally doesn't support declaring variables in mid-code.
They do somewhat, but you're pushing it. Don't do this.

If you do it the normal old way, then it compiles:
Code:
float var;

printf(lcd_putc, "float value = %f", var );
cbarberis



Joined: 01 Oct 2003
Posts: 172
Location: Punta Gorda, Florida USA

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 06, 2020 10:29 am     Reply with quote

Thank you PCM Programmer but actually I was not declaring the variable type inside the printf() command I did it that way to explain that I was using a float for that variable the actual way I have it is as follows:

float var; // global var

then I use this to print to lcd

printf(lcd_putc,"float value - %f",var);

But I get an error that only chars are allowed
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 06, 2020 11:07 am     Reply with quote

It compiles fine on vs. 5.094. I suspect you have an older compiler version.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Mon Jul 06, 2020 11:33 am     Reply with quote

Post the actual code segment you are using, and the exact full error.
Include line numbers.
I'd suspect you have some other basic syntax error.
cbarberis



Joined: 01 Oct 2003
Posts: 172
Location: Punta Gorda, Florida USA

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 06, 2020 12:01 pm     Reply with quote

I am not sure where the error is coming from. I have copied the code segment where the error occurs if I comment out LINE 137 everything compiles just fine and the code works fine on the hardware. Also there seems to be a bunch of continuing errors after that but obviously LINE 137 seems to be the issue, like I said if I comment out this line there are no errors. BTW, I am using PCHD 5.094 which is the latest

Code:
     
   BME280_readTemperature(&temperature);  // read temperature
   Deg_f = Convert_C_to_F(temperature);
   lcd_gotoxy(1, 2);     
   if(temperature < 0)
    {  // if temperature is negative
      putc('-');   // print minus sign
      temperature = abs(temperature);  // abs: absolute value
    }
   
 LINE 137 ->  printf(lcd_putc, "Temp = "%f DegF",Deg_f); // does not work with the I2C_FlexLCD driver only characters allowed
 
  // printf(lcd_putc,"Temp = %02Lu C, or %02Lu F", temperature / 100,(int32)Deg_f ); // this works fine
   BME280_readHumidity(&humidity);
   lcd_gotoxy(1, 3);       
   printf(lcd_putc, "Humidity = %02Lu %%", humidity / 1024);
   BME280_readPressure(&pressure);
   lcd_gotoxy(1, 4);       
   printf(lcd_putc, "Pressure = %04Lu Mb", pressure/100);
   
        delay_ms(100);
   
        restart_wdt();   

ERRORS:

Compiling C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor on 06-Jul-20 at 13:45
--- Info 300 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.h" Line 12(1,1): More info: Actual Clock is 31822506
>>> Warning 203 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 124(1,1): Condition always TRUE
*** Error 12 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 137(31,32): Undefined identifier f
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 173(22,23): Illegal C character in input file 0x72 after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 173(24,25): Illegal C character in input file 0x6E after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 174(42,43): Illegal C character in input file 0x72 after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 174(44,45): Illegal C character in input file 0x6E after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 178(40,41): Illegal C character in input file 0x72 after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 178(42,43): Illegal C character in input file 0x6E after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 179(32,33): Illegal C character in input file 0x72 after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 179(34,35): Illegal C character in input file 0x6E after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 180(43,44): Illegal C character in input file 0x72 after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 180(45,46): Illegal C character in input file 0x6E after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 183(39,40): Illegal C character in input file 0x72 after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 183(41,42): Illegal C character in input file 0x6E after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 184(43,44): Illegal C character in input file 0x72 after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 184(45,46): Illegal C character in input file 0x6E after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 197(22,23): Illegal C character in input file 0x72 after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 197(24,25): Illegal C character in input file 0x6E after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 203(32,33): Illegal C character in input file 0x72 after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 203(34,35): Illegal C character in input file 0x6E after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 208(39,40): Illegal C character in input file 0x72 after \
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 208(41,42): Illegal C character in input file 0x6E after \
*** Error 79 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 221(43,44): Expect }
*** Error 79 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 221(43,44): Expect }
23 Errors, 1 Warnings.
Build Failed.
cbarberis



Joined: 01 Oct 2003
Posts: 172
Location: Punta Gorda, Florida USA

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 06, 2020 12:21 pm     Reply with quote

Just wanted to note one more thing if I use the printf() line as such printf(lcd_putc, "Temp = "%3.1f DegF",Deg_f); it brings out the real error which is shown as ERROR # 3 on the error list when I used %f I just got an error indicating the character 'f' was invalid.

Code:
 LINE 137 -> printf(lcd_putc, "Temp = "%3.1f DegF",Deg_f); // does not work with the I2C_FlexLCD driver only integers allowed
   //printf(lcd_putc,"Temp = %02Lu C, or %02Lu F", temperature / 100,(int32)Deg_f ); // this works fine

COMPILATION ERRORS:

Compiling C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor on 06-Jul-20 at 14:09
--- Info 300 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.h" Line 12(1,1): More info:   Actual Clock is 31822506
>>> Warning 203 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 124(1,1): Condition always TRUE
*** Error 3 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 137(31,35): Only integers are supported for this operation
*** Error 1 "C:\Picomp\FILES\Bartek\BME280-SENSOR\WeatherSensor.c" Line 173(22,23): Illegal C character in input file  0x72 after \
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jul 06, 2020 1:54 pm     Reply with quote

hmm...
LINE 137 -> printf(lcd_putc, "Temp = "%3.1f DegF",Deg_f); // does not work with the I2C_FlexLCD driver only integers allowed

I think there should be a " after .1F and before DefgF"...

I only see 3 ", and shouldn't there be 4 of them ?

Jay
cbarberis



Joined: 01 Oct 2003
Posts: 172
Location: Punta Gorda, Florida USA

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 06, 2020 2:15 pm     Reply with quote

Jay and the rest of you guys, thank you for enlightening me to the fact that this was just a simple stupid syntax error that I just could not see.


This works --->. printf(lcd_putc, "Temp = %3.1f DegF",Deg_f);

This CANNOT work --->. printf(lcd_putc, "Temp = "%3.1f DegF",Deg_f);

The problem although obvious was invisible to me, there should have never been a " inside string delimiter as you can see on the line that gives me the compilation error with the " just before %3.1f
And YES, to print out a floating numeric format of XX.X it should be %4.1f

I guess my eyes and brain are not connecting too well.
Embarassed Embarassed
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jul 06, 2020 2:41 pm     Reply with quote

Hay it's dang near 100*F here in Ontario, gotta be hotter 'down south', so I understand the 'glaring eyes - see nothing wrong' syndrome.
it gets worse the older you get and a 1/2 a dead finger doesn't help either.
wished I'd taking 'touch typing ' in high school but for guys to take it ,that was frowned upon.

Jay
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Mon Jul 06, 2020 3:27 pm     Reply with quote

Hmm... Which IDE are you using? Won't there be syntax highlighting in most IDEs nowadays that would make it pretty obvious if you've added an extra quotation mark somewhere, or missed any brackets and stuff?
cbarberis



Joined: 01 Oct 2003
Posts: 172
Location: Punta Gorda, Florida USA

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 06, 2020 3:45 pm     Reply with quote

Using the latest IDE version 5.094 from CCS. There is some syntax high lighting to show variables and things of that sort but I have never seen any highlighting take place when you enter a wrong expression or just do something stupid like I did. You must be using a more advanced IDE like MPLABX
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Mon Jul 06, 2020 3:54 pm     Reply with quote

Yes, I have been using MPLAB X.

I also use programs like notepad++ or Sublime Text for quick editing of code. They also have decent syntax highlighting.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Tue Jul 07, 2020 12:31 am     Reply with quote

We have all done this.
Spent ages tracking down a line that would not compile. Turned out that
two lines before I had typed a ':' instead of a ';'.
All too common I'd afraid... Sad

Good thing was that posting the code allowed 'eagle eyed Jay' to find
the fault. Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group