View previous topic :: View next topic |
Author |
Message |
pekka1234
Joined: 28 May 2017 Posts: 80
|
Empty strings to end of the LCD automatically |
Posted: Fri Mar 25, 2022 8:32 am |
|
|
I try to create empty strings to end of LCD, but it doesn't succeed.
Otherwise I must always put empty string to end of each printat- sentence.
I use macro found lately in this discussion forum.
Code: |
void LCD_PUTC(char in_data);
// I want to create empty strings to the end of the LCD, but it came error:
void fillempty (int16 lenx)
{
int8 x;
for ( x=0; x<lenx; x++)
printf(lcd_putc," ");
}
#define printat(x,y,_str,...) do{ \
lcd_gotoxy(x,y); \
printf(lcd_putc,_str,__VA_ARGS__); \
fillempty(strlen(_str)); \ // error: Attempt to create a pointer to a constant
}while(0);
|
Can somebody help?
Pekka |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 25, 2022 9:36 am |
|
|
I modified your program as shown below to make it work.
It displays the following output in the Output Window of MPLAB
vs. 8.92, when the program is run in the simulator.
I assumed you actually want to write spaces to the end of the line.
I used 'e' to represent a space for testing purposes. 'e' = empty.
Code: |
#include <18F46K22.h>
#device PASS_STRINGS=IN_RAM
#fuses NOWDT
#use delay(internal=4M)
#use rs232(UART1, baud=9600, ERRORS, stream=PC)
#include <string.h>
#define LCD_LINE_LEN 16
// Send output to console for testing.
void lcd_putc(char c)
{
putc(c);
}
// Stub, not used for testing.
void lcd_gotoxy(int8 x, int8 y)
{
}
// Fill to end of line with spaces.
// Use 'e' for empty, for testing.
void fillempty (int16 lenx)
{
int8 x;
for ( x=0; x<lenx; x++)
printf(lcd_putc,"e");
}
#define printat(x,y,_str,...) \
lcd_gotoxy(x,y); \
printf(lcd_putc,_str,__VA_ARGS__); \
fillempty(LCD_LINE_LEN - strlen(_str));
//=================================
void main()
{
printat(1,1,"Hello World");
while(TRUE);
} |
|
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 478 Location: Montenegro
|
|
Posted: Fri Mar 25, 2022 11:49 am |
|
|
Very nice.
Does something similar exist for OLED displays? |
|
|
pekka1234
Joined: 28 May 2017 Posts: 80
|
|
Posted: Fri Mar 25, 2022 12:36 pm |
|
|
PCM Programmer
I tried your code in my PIC 18F27K40 and CCS 5.092 compiler.
It worked well.
I have not tried with real LCD, but I believe it will work.
Thanks for Saturday work! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Sat Mar 26, 2022 1:51 am |
|
|
PrinceNai wrote: | Very nice.
Does something similar exist for OLED displays? |
Just use the same code, with the corresponding putc. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 478 Location: Montenegro
|
|
Posted: Sat Mar 26, 2022 10:39 am |
|
|
Will try to do it. On the first look, one additional check must be added to deal with the "NORMAL" or "LARGE" size of the font. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Sun Mar 27, 2022 3:18 am |
|
|
I'd suggest you have a flag 'large_font', and in the code that selects the
font size, this is set true/false. Then in the code to clear the line, the line
length is changed according to whether this is set or not. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 478 Location: Montenegro
|
|
Posted: Sun Mar 27, 2022 3:56 am |
|
|
I'm using 1306.h driver found on this forum, where this is already defined, so it is even easier:
Code: |
// size=NORMAL; // 21 characters in a row, 8 rows, total 168 chars
size=LARGE; // 10 characters, 4 rows. Use rows 0,2,4,6 to avoid overlapping
|
Probably only need to change LCD_LINE_LEN to 21 or 10 depending on "size" variable, either through #define or on the fly if different sizes of fonts are used. |
|
|
|