How to print variables to LCD?

General discussion on mikroC.
Post Reply
Author
Message
ascomm
Posts: 129
Joined: 30 Mar 2005 18:28
Location: Finland

How to print variables to LCD?

#1 Post by ascomm » 07 Jun 2005 18:15

I'm really confused about printing int variables on LCD.
How should I do it? The following "test"-program does not work and I don't know why?
Only the last "Valmis!!" is printed to LCD. Before that - nothing.

Code: Select all

void main()
{
  int a;
  char *abc;
  TRISB = 0;                // PORTB asetetaan lähdöksi
  Lcd_Init(&PORTB);         // Alustetaan LCD
  Lcd_Cmd(Lcd_CURSOR_OFF);  // Kursori pois

while (1==1)
{
  Lcd_Cmd(Lcd_CLEAR);       // Tyhjennetään näyttö
  for (a = 0; a<9; a++)
  {
    IntToStr(a, abc);
    Lcd_Out(1, 2, abc);      // Tulostetaan näyttöön, 1. rivi, 1. sarake
    Delay_ms(200);
  }

  Lcd_Out(1, 3, "Valmis!!");      // Tulostetaan näyttöön, 1. rivi, 1. sarake
  Delay_ms(1000);

}

}

olivierh
Posts: 8
Joined: 21 Mar 2005 21:57
Location: France

Re: How to print variables to LCD?

#2 Post by olivierh » 07 Jun 2005 20:48

ascomm wrote:

Code: Select all

void main()
{
  int a;
  char *abc;

IntToStr return a 6 characters string. So you have to change char *abc to char abc[7] to have some space to store the string (6 char + `\0`).

ascomm
Posts: 129
Joined: 30 Mar 2005 18:28
Location: Finland

Re: How to print variables to LCD?

#3 Post by ascomm » 07 Jun 2005 21:18

olivierh wrote:IntToStr return a 6 characters string. So you have to change char *abc to char abc[7] to have some space to store the string (6 char + `\0`).
Ofcourse. I totally forgot about that six character string lenght. :oops:
Thanks for help :)

Post Reply

Return to “mikroC General”