|
|
View previous topic :: View next topic |
Author |
Message |
dexta64
Joined: 19 Feb 2019 Posts: 11
|
printat function |
Posted: Wed Dec 01, 2021 7:45 am |
|
|
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: 1353
|
|
Posted: Thu Dec 02, 2021 10:12 am |
|
|
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
|
|
Posted: Tue Dec 07, 2021 1:34 am |
|
|
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: 19537
|
|
|
dexta64
Joined: 19 Feb 2019 Posts: 11
|
|
Posted: Tue Dec 07, 2021 3:26 am |
|
|
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
|
|
Posted: Tue Dec 07, 2021 3:32 am |
|
|
Ttelmah thank you so much. |
|
|
|
|
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
|