-2

Could anyone explain to me what this function is doing? I understand it is used to display text on an LCD but I do not exactly understand how it works.

I want to send a volatile integer to the LCD and would like to understand how this function works before attempting to do so. I would appreciate any efforts to explain this to me.

void LCD_Send_String(uint8_t ch[])  // Send a string to the display.
{
    volatile int i=0;
    while(ch[i] != 0)
    {
        LCD_Send_Data(ch[i]);
        i++;
        _delay_us(80);
    }
}
LoneCoder
  • 45
  • 6
  • 3
    Do you understand C null-terminated char arrays? – Martin James Feb 15 '16 at 13:38
  • Please show how you call the `LCD_Send_String` function. Also we cannot really know what the `LCD_Send_Data` does, we can only guess. – Jabberwocky Feb 15 '16 at 13:44
  • It loops and sends one character at a time, with a delay in between. What else is there to understand? Unless your question is why the iterator is declared as `volatile`. That is indeed a good question. Looks like remains from a debug build that someone forgot to remove. – Lundin Feb 15 '16 at 13:59
  • 2
    "I want to send a volatile integer to the LCD" - then your code is completely wrong. The code shown is very basic. How about learning C instead of relying on others explaining/doing your assignment? – too honest for this site Feb 15 '16 at 14:10

2 Answers2

0

ch[] is a character array(string to be transmitted) and string is send to lcd, letter by letter using ch[i] to refer to each letter.

geetesh singh
  • 49
  • 1
  • 6
0

When you say you want to "send a volatile integer to the LCD" do you mean you want the LCD to display a number? If so then you'll need to use something that converts that number to a character array, before passing it as a parameter into this function.

There are various functions such as sprintf that will convert from an integer to a char array, if you have access to those libraries. Other answers cover its usage as well as the documentation.

JBurger
  • 26
  • 3
  • Sorry I did not word my question properly, that is correct I wanted to display a number on an LCD and increment/decrement that value so yes I wanted to know how to convert that number into a character. I have solved this issue now but thank you for your help – LoneCoder Feb 17 '16 at 09:04
  • Sure thing. If my answer was useful to you please upvote it. :) I would also recommend looking up `itoa()` and related functions, should be found in `stdlib.h`. – JBurger Feb 19 '16 at 18:27
  • Will do once my reputation is high enough! – LoneCoder Feb 25 '16 at 08:20