|
|
View previous topic :: View next topic |
Author |
Message |
vtrx
Joined: 11 Oct 2017 Posts: 142
|
Format text on the OLED display |
Posted: Fri Jul 24, 2020 4:19 pm |
|
|
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
|
|
Posted: Fri Jul 24, 2020 5:46 pm |
|
|
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:
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
|
|
Posted: Sun Jul 26, 2020 2:53 pm |
|
|
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:
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. |
|
|
|
|
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
|