NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » LCD- clearing a line with 0x00 in the array

March 07, 2013
by Johnny544
Johnny544's Avatar

Hi-

I recently completed the PS2 keyboard project. Overall it went well and I understand most of it, but there's one bit of code I couldn't figure out. These lines act to clear a line from the LCD:

str_buf[0] = str_buf[1] = 0x00;
lcd_home();
fprintf_P(&lcd_stream,PSTR("%-20s"),str_buf);

What puzzles me about this is there are characters remaining in other positions in the array, such as in str_buf[4] and str_buf[5] but these characters don't display on the LCD. I can only guess that sending 0x00 to the LCD is a special code of some kind.

Here's a link to the PS2 keyboard project

Thanks in advance for the explanation.

John

March 07, 2013
by Noter
Noter's Avatar

A character string in C is terminated with a null or 0x00. It doesn't have anything to do with the display, it just tells printf where the string ends so it will stop reading/sending characters to the LCD. The string is ended at the 1st 0x00 so also setting str_buf[1] is not necessary. All the string functions in C expect a terminating null. For example there is string copy, strcpy(out, in) and the string in must be terminated as opposed to memcpy(out, in, len) where a terminator is not needed or considered. memcpy will simply copy nulls that exist within len characters.

March 07, 2013
by Johnny544
Johnny544's Avatar

Noter- Thanks for the clear explanation. Much appreciated.

-John

Post a Reply

Please log in to post a reply.

Did you know that you can build a digital read out (DRO) for a lathe or milling machine? Learn more...