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

Empty strings to end of the LCD automatically

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



Joined: 28 May 2017
Posts: 74

View user's profile Send private message

Empty strings to end of the LCD automatically
PostPosted: Fri Mar 25, 2022 8:32 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 25, 2022 9:36 am     Reply with quote

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.
Quote:
Hello Worldeeeee

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: 453
Location: Montenegro

View user's profile Send private message

PostPosted: Fri Mar 25, 2022 11:49 am     Reply with quote

Very nice.

Does something similar exist for OLED displays?
pekka1234



Joined: 28 May 2017
Posts: 74

View user's profile Send private message

PostPosted: Fri Mar 25, 2022 12:36 pm     Reply with quote

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: 19215

View user's profile Send private message

PostPosted: Sat Mar 26, 2022 1:51 am     Reply with quote

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: 453
Location: Montenegro

View user's profile Send private message

PostPosted: Sat Mar 26, 2022 10:39 am     Reply with quote

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: 19215

View user's profile Send private message

PostPosted: Sun Mar 27, 2022 3:18 am     Reply with quote

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: 453
Location: Montenegro

View user's profile Send private message

PostPosted: Sun Mar 27, 2022 3:56 am     Reply with quote

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