0

I'm sending text to an LCD display, in the form of a string right now. I'm having some trouble getting a format that works for all inputs.

The declarations and calls for the variable look like this...

void DisplayString(unsigned char row, unsigned char column, const char * string)
{
.
.
}

DisplayString(0, 0, "Hello World!");

This works just fine.

Now, I have some custom characters that get mapped to the LCD from 0x00 to 0x07. For example, the character "ó"(in dot matrix form) is mapped to 0x01. I'm able to display them just fine, but I've had to change the prototype for it to work. (from 'const char *' to just 'char')

For example, this works:

void DisplayStringTwo(unsigned char row, unsigned char  column, char string)
{
.
.
}

DisplayStringTwo(0, 4,  0x01);

Is there a way to include the hex character (0x01) within the string to display it all at once from one function? Such as, 'Helló World!'.

I've tried a few methods which haven't worked, such as:

void DisplayString(unsigned char row, unsigned char column, const char * string)
{
.
.
}

DisplayString(0, 0, "Hell\x01 World!");

Any suggestions are highly appreciated.

qoou
  • 155
  • 8
  • 1
    How do you expect this character to look on the screen? Why do you think `ó ` is `0x01`? – Eugene Sh. May 13 '16 at 20:54
  • Why did you have to change the prototype from `char*` to `char`? That prototype no longer makes sense. – abelenky May 13 '16 at 20:55
  • It's a custom character mapped to memory in dot matrix form. To be honest, I'm only posting 'ó' here as an example since it's something easily typed. The LCD isn't so mch the problem as it is combining a hex value within a string. – qoou May 13 '16 at 20:56
  • The string is valid with \xhh, except with \x00 which acts like a \0. Do you check all character with isprint() in you DisplayString() ? – damorin May 13 '16 at 20:58
  • The way you are doing it is correct. Just try the same with the known printable ASCII codes – Eugene Sh. May 13 '16 at 20:58
  • Perhaps you have a bug in the implementation of DisplayString. Show that code? – abelenky May 13 '16 at 20:59
  • @abelenky The example script from the LCD manufacturer uses `char`. – qoou May 13 '16 at 21:00
  • 1
    Your solution (`\x01`) should have worked, unless your compiler doesn't support the hex escape. But in that case, you should see the `x` and/or `01` on the the LCD. – user3386109 May 13 '16 at 21:01
  • I would say - write a simple loop iterating over all byte values and use `DisplayStringTwo` to print them. This way you will know exactly the mapping of the printable characters. – Eugene Sh. May 13 '16 at 21:03
  • Okay, you all are right in that it is working with characters 0x01 - 0x07. I had been testing with the first char mapped to 0x00, which does not work. So I guess my question now is, how do I use 0x00? – qoou May 13 '16 at 21:15
  • 1
    You can't. `0` is indicating the end of the string. The `DisplayStringTwo` should be able to handle it as a single character. Unless there is some additional function taking the array and it's length. – Eugene Sh. May 13 '16 at 21:17
  • The solution is to use `\x01` thru `\x08` in the string. Then, in the display routine, when you encounter a byte that's between 1 and 8, subtract 1 before sending it to the LCD. – user3386109 May 13 '16 at 21:52

0 Answers0