cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in displaying a number on char LCD displays

Arman Ilmak
Senior
Posted on May 01, 2018 at 12:39

Hi.

I was working with my new stm8s105 MCU trying to get started with the timers.

But every time I use the command to display the time on the LCD the same number showed every time.I thought that the problem is my timer code but when I just put a number on the LCD to show it just showed an irrelevant number.

I use the same LCD.h on LPC1768 and STM32F2 and just converted the same header.The only difference is that I used Keil compiler for them and now I'm using IAR.

lcd_gotoxy(1,2);

sprintf(buf,'%d',100);

lcd_print(buf);

delay_ms(1000);

This is a simple code that must show 100 but it displays 12594

>:(

The characters are displayed properly.The problem is numbers.

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on May 01, 2018 at 16:48

The last questions refers to compiler messages like the one you show earlier (spriinf() declared implicitely , etc)

View solution in original post

13 REPLIES 13
Posted on May 01, 2018 at 13:34

'buf' variable definition? Is the memory for 'buf' allocated?

For example, you can reserve some memory this way:

char buf[100];

Posted on May 01, 2018 at 15:44

Add at the beginning:

#include <string.h>

Posted on May 01, 2018 at 16:43

Is the 'HELLO WORLD' correctly displayed in the position of 0,2?

Do yo still see 1,2,... instead of 100?

What messages do you see now?

Posted on May 01, 2018 at 15:37

Yeah, the LCD is 2*16 and this is the code.

0690X00000604g0QAA.jpg
Posted on May 01, 2018 at 16:23

Did it.But no result.

Posted on May 01, 2018 at 16:48

The last questions refers to compiler messages like the one you show earlier (spriinf() declared implicitely , etc)

Posted on May 01, 2018 at 19:15

>On my LCD or in the message box of the compiler?

In the compile window

Posted on May 01, 2018 at 19:40

I was wrong - the sprintf is a part of:

#include <

https://pl.wikibooks.org/wiki/C/Biblioteka_standardowa/Indeks_tematyczny#stdio.h

>

So include the stdio.h as shown above to clear the message and test it again.
Posted on May 01, 2018 at 19:13

Bogdan Golab wrote:

Is the 'HELLO WORLD' correctly displayed in the position of 0,2?

Yes, it's ok and in its proper position.

Bogdan Golab wrote:

Do yo still see 1,2,... instead of 100?

I just see 18501 instead of 100 at first, then after 30 seconds, I see 12594. 

What messages do you see now?

On my LCD or in the message box of the compiler?