LiquidCrystal bug with 'rw' pin (solved)

I've been getting some mysterious character corruption on my LCD, which would vary on editing completely unrelated parts of the program. I would get even weirder corruption on the serial output at the same time. Using the simulator in AVR Studio I have traced this to a bug in LiquidCrystal:
In LiquidCrystal.h:

uint8_t _rw_pin

In LiquidCrystal.cpp:

init(0, rs, -1, ...etc

and lower down in ::send

if (_rw_pin != -1) {
    digitalWrite(_rw_pin, LOW);
}

As _rw_pin is defined as unsigned, it can never take the value -1 (it has the value 255) and the compiler optimises out the 'if' and so LOW gets written to port 255.

Changing the type of _rw_pin to int8_t fixes the problem.

Added an issue on Google Code: Google Code Archive - Long-term storage for Google Code Project Hosting.

Thanks!! :slight_smile:
Have been lurking here for some time, and I was really bothered by this problem, even to the point of a program crashing when initializing the LCD.

I already had some experience with this problem, strange characters being printed to the serial monitor...

I had text that was only sent to the LCD appearing in the middle of strings sent to the serial, as well as odd characters on the LCD being corrupted. Even stranger was that editing completely unrelated parts of the program would alter (or even cure) the problem.

Since I made the change to the Library, I haven't seen any problems :sunglasses: