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

printat function

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



Joined: 19 Feb 2019
Posts: 11

View user's profile Send private message

printat function
PostPosted: Wed Dec 01, 2021 7:45 am     Reply with quote

Those who want the function can develop more complex.
But I will simply share.
Code:

#define printat(x,y,_str,nmr) do{ \
  lcd_gotoxy(x,y); \
  printf(lcd_putc,_str,nmr); \ 
}while(0);

or
Code:

#define printat(x,y,_str,nmr,nmr1) do{ \
  lcd_gotoxy(x,y); \
  printf(lcd_putc,_str,nmr,nmr1); \ 
}while(0);

Here's the usage
Code:

int8 month=12;
printat(1,1,"MONTH: %02d",month);

or
Code:

int16 year=2021;
printat(1,1,"YEAR: %lu",year);

or this is how it is defined
Code:

#define printat(x,y,_str,nmr,nmr1) do{ \
  lcd_gotoxy(x,y); \
  printf(lcd_putc,_str,nmr,nmr1); \ 
}while(0);

int16 year=2021;
int8 month=12;
printat(1,1,"Date: %lu/%02d",year,month);
jeremiah



Joined: 20 Jul 2010
Posts: 1315

View user's profile Send private message

PostPosted: Thu Dec 02, 2021 10:12 am     Reply with quote

you can also use variant macro arguments:

Code:


#define printat(x,y,_str,...) do{ \
  lcd_gotoxy(x,y); \
  printf(lcd_putc,_str,__VA_ARGS__); \
}while(0);



Also you can also use multiple statement syntax if you like:

Code:

#define printat(x,y,_str,...)  \
  (lcd_gotoxy(x,y), printf(lcd_putc,_str,__VA_ARGS__))
dexta64



Joined: 19 Feb 2019
Posts: 11

View user's profile Send private message

PostPosted: Tue Dec 07, 2021 1:34 am     Reply with quote

jeremiah thank you so much. It had puzzled me for days.
"__VA_ARGS__"
is that the magic command? I shared well.

Code:


typedef struct
{
  uint8_t day;
  uint8_t month;
  uint8_t year;
  uint8_t dow;
  uint8_t hour;
  uint8_t min;
  uint8_t sec;
}t_time;
t_time date;

printat(1,1,"TEST");
printat(2,1,"T:%02d/%02d/%02d-%02d:%02d",date.day,date.month,date.year,date.hour,date.min);


it works perfectly.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Tue Dec 07, 2021 1:55 am     Reply with quote

Not a 'magic command', just a deeper bit of C for handling things with
variable length argument lists. It's called a 'variadic macro'.

[url]
https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html
[/url]

It is in the K&R C reference.
dexta64



Joined: 19 Feb 2019
Posts: 11

View user's profile Send private message

PostPosted: Tue Dec 07, 2021 3:26 am     Reply with quote

other I have defined and working

The lcd_puts command is like this in the lcd driver.
Code:

void lcd_puts(char * str)
{
  while (*str != '\0') //\0 will scan the inside of lcdtxt until you see this
                              //statement.
  {   
    lcd_putc(*str);
    str++;
  }
}

my definitions
Code:

//
#define printat(x,y,_str,...)  \
  (lcd_gotoxy(x,y), printf(lcd_putc,_str,__VA_ARGS__))

//command i get string from rom
//My goal is to save ram space.
#define printst(x,y,_str)  \
  (lcd_gotoxy(x,y), strcpy(lcdtxt,_str), lcd_puts(lcdtxt)) //lcdtxt be very careful here.
//This way it uses a lot of ram. Also the Rom area.
#define printstr(x,y,_str,...)  \
  (lcd_gotoxy(x,y), sprintf(lcdtxt,_str,__VA_ARGS__), lcd_puts(lcdtxt))  //lcdtxt be very careful here.


#device PASS_STRINGS=IN_RAM without using this definition.
reads the definition directly from the Rom.

Code:

unsigned char lcdtxt[16]; //regular program variable that I defined once. I throw my writings in it.

const char menuprgstatus[2][12]={
"ON STAND-BY",
"WORKING    "};


Code:

//on my lcd drive x=row, y=column
printst(1,1,menuprgstatus[0]);
printst(2,1,menuprgstatus[1]);


Last edited by dexta64 on Tue Dec 07, 2021 3:51 am; edited 3 times in total
dexta64



Joined: 19 Feb 2019
Posts: 11

View user's profile Send private message

PostPosted: Tue Dec 07, 2021 3:32 am     Reply with quote

Ttelmah thank you so much.
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