2014-01-02 02:47 AM
struct tm time;
char year[50]; Guys, I want to display year into LCD screen but I got 00 on LCD, any clues on how to do it ? thanks printf(''Time: %d-%d-%d %02d:%02d:%02d \r\n'', time.tm_year, \ time.tm_mon+1, time.tm_mday,\ time.tm_hour, time.tm_min, time.tm_sec); sprintf(year,''%.2f'',time.tm_year);lcd_string(year); #!complicated
2014-01-04 06:59 AM
Then you'll need to review the lcd_string() code, but it's clearly not going to accept an integer as a parameter if it is expecting a string.
2014-01-04 07:38 AM
You previously said that ''00'' was appearing on the LCD. Is this for any string you send e.g. if you used LCD_string(''35'') would it display 35 as expected or would it display ''00''?
You need to be more specific and describe exactly what does and what does not work.2014-01-04 09:24 PM
Yes it was displaying 00 before.....
Here's the time variable I have : struct tm { int tm_sec; /* seconds after the minute, 0 to 60 (0 - 60 allows for the occasional leap second) */ int tm_min; /* minutes after the hour, 0 to 59 */ int tm_hour; /* hours since midnight, 0 to 23 */ int tm_mday; /* day of the month, 1 to 31 */ int tm_mon; /* months since January, 0 to 11 */ int tm_year; /* years since 1900 */ int tm_wday; /* days since Sunday, 0 to 6 */ int tm_yday; /* days since January 1, 0 to 365 */ int tm_isdst; /* Daylight Savings Time flag */ union { /* ABI-required extra fields, in a variety of types */ struct { int __extra_1, __extra_2; }; struct { long __extra_1_long, __extra_2_long; }; struct { char *__extra_1_cptr, *__extra_2_cptr; }; struct { void *__extra_1_vptr, *__extra_2_vptr; }; }; }; lcd_string code : void lcd_string(unsigned char *str){ while(*str){ lcd_data(*str++); } }2014-01-04 10:22 PM
it displays something already, in unix time :
the code : sprintf(year,''%2d'',time.tm_year); lcd_cmd(LCD_CLEAR); lcd_string(''YEAR: ''); lcd_string(year); vTaskDelay(15000); on LCD, now another puzzle for me for converting that value to 2...any clues ? thanks ________________ Attachments : IMG_20140105_141247.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I19a&d=%2Fa%2F0X0000000bj7%2F7xud0rBkhUeZnRi2iOXedL7qX1qOyN9qS2hdz8_ETEg&asPdf=false2014-01-04 10:59 PM
any clues ?
One might reasonably assume the structure simply doesn't contain what you want it too?
time.tm_year
= 1234; // try setting it explicitlysprintf(year,''%2d'',time.tm_year);
lcd_cmd(LCD_CLEAR); lcd_string(''YEAR: ''); lcd_string(year); vTaskDelay(15000); I'll observed that printf/scanf functions are stack hogs, and that issues can occur with the locale if they collide. Understand your stack size allocation, and actual usage.2014-01-05 09:22 AM
Hi,
This is the routine I am using to display integers on my Nokia 5110 LCD in case it can be of any help. It displays up to 5 digits, and you can control the number of digits to display based on the last parameter passed. So, for a day, the digit_num is 2 and for a year, the digit_num is 4./*
* Takes an integer and display it as ascii on the LCD
* state: normal or reverse Video
* leading: how may digits to display from the right side
* if zero that means display the full number without leading zeros
*/
void LCD5110_Write_Dec(uint16_t b, uint8_t state, uint8_t digit_num)
{
unsigned char datas[5],i,j;
datas[0] = b/10000;
b = b - datas[0]*10000;
datas[1] = b/1000;
b = b - datas[1]*1000;
datas[2] = b/100;
b = b - datas[2]*100;
datas[3] = b/10;
b = b - datas[3]*10;
datas[4] = b;
datas[0]+=48;
datas[1]+=48;
datas[2]+=48;
datas[3]+=48;
datas[4]+=48;
/* find the first non zero digit to display - display at least one digit */
for (i = 0; i <
5
; i++) {
if (datas[i] != 48) {
break;
}
}
if (digit_num > 0 && digit_num < 6){ // valid range
i = 5-digit_num;
}
for (j = i; j < 5; j++) {
if (state == NORMAL) {
LCD5110_write_char(datas[j]);
} else {
LCD5110_write_char_rev(datas[j]);
}
}
}
2014-01-05 02:35 PM
2014-01-05 02:37 PM
2014-01-05 09:30 PM
yea, it's working, displaying 1234......so what do I miss here ?
Here's the variable I have here : struct tm { int tm_sec; /* seconds after the minute, 0 to 60 (0 - 60 allows for the occasional leap second) */ int tm_min; /* minutes after the hour, 0 to 59 */ int tm_hour; /* hours since midnight, 0 to 23 */ int tm_mday; /* day of the month, 1 to 31 */ int tm_mon; /* months since January, 0 to 11 */ int tm_year; /* years since 1900 */ int tm_wday; /* days since Sunday, 0 to 6 */ int tm_yday; /* days since January 1, 0 to 365 */ int tm_isdst; /* Daylight Savings Time flag */ union { /* ABI-required extra fields, in a variety of types */ struct { int __extra_1, __extra_2; }; struct { long __extra_1_long, __extra_2_long; }; struct { char *__extra_1_cptr, *__extra_2_cptr; }; struct { void *__extra_1_vptr, *__extra_2_vptr; }; }; };2014-01-05 10:21 PM
yea, it's working, displaying 1234......so what do I miss here ?
Whatever is initializing the structure, doesn't seem to be doing it's job.