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 CCS Technical Support

Format text on the OLED display

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



Joined: 11 Oct 2017
Posts: 142

View user's profile Send private message

Format text on the OLED display
PostPosted: Fri Jul 24, 2020 4:19 pm     Reply with quote

I have an OLED display model SSD1306.
I have a function that shows the temperature in this format;

Code:
signed int16 chip_temp;

chip_temp = Get_Temperature ();


The routine for displaying on the LCD is;

Code:
SSD1306_DrawText (4,4, "123", 1);//x,y,Text,size


Using a regular LCD, I use this routine;

Code:
printf (LCD_Print, "Temp:% 02Lu.% 02Lu C", abs (chip_temp) / 100, abs (chip_temp)% 100);


How can I adapt to the OLED routine?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 24, 2020 5:46 pm     Reply with quote

How about this:
sprintf it to a buffer, then give the buffer to the SSD1306_Drawtext() routine.

Here is the output of the program shown below, in the MPLAB v8.92 output window:
Quote:
Temp: 10.00 C

Test program:
Code:

#include <18F46K22.h>
#fuses NOWDT 
#use delay(internal=4M)
#use rs232(UART1, baud=9600, ERRORS)

//------------------------------------
// Substitute function for testing with MPLAB v8.92 simulator.
// This function displays text in the UART1 output window.
void SSD1306_Drawtext(int8 x, int8 y, char *text, int8 size)
{
puts(text);


//=================================
void main()
{
signed int16 chip_temp = 1000;
int8 buffer[20];

sprintf(buffer, "Temp: %02Ld.%02Ld C", abs(chip_temp) / 100, abs(chip_temp)% 100);
SSD1306_DrawText (4, 4, buffer, 1);

while(TRUE);
}
vtrx



Joined: 11 Oct 2017
Posts: 142

View user's profile Send private message

PostPosted: Sun Jul 26, 2020 2:53 pm     Reply with quote

PCM programmer wrote:
How about this:
sprintf it to a buffer, then give the buffer to the SSD1306_Drawtext() routine.

Here is the output of the program shown below, in the MPLAB v8.92 output window:
Quote:
Temp: 10.00 C

Test program:
Code:

#include <18F46K22.h>
#fuses NOWDT 
#use delay(internal=4M)
#use rs232(UART1, baud=9600, ERRORS)

//------------------------------------
// Substitute function for testing with MPLAB v8.92 simulator.
// This function displays text in the UART1 output window.
void SSD1306_Drawtext(int8 x, int8 y, char *text, int8 size)
{
puts(text);


//=================================
void main()
{
signed int16 chip_temp = 1000;
int8 buffer[20];

sprintf(buffer, "Temp: %02Ld.%02Ld C", abs(chip_temp) / 100, abs(chip_temp)% 100);
SSD1306_DrawText (4, 4, buffer, 1);

while(TRUE);
}


worked perfectly.
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