Symptom: pin 0 on the controller gets overwritten every time anything is written towards LCD, although pin 0 is not assigned anywhere. The LCD is initialized with call
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
Cause: LCD driver uses '-1' as a value for initializing _rw_pin variable from ::init routine, in case the RW pin is not used. However, the parameter is passed as uint8_t and therefore all conditional checks against '-1' fail inside the routines, what causes the _rw_pin being updated. It manifests with digital pin 0 value being changed.
Fix: replace all the '-1' values regarding rw and _rw_pin with '0xFF'.
If you look at the insides of the library you will see that the R/W pin is just used so that it is always in the read position so unless you are hacking it there is no point in using this.
If you are hacking it you can get up to 50% increase in speed by reading when the LCD is not busy instead of just waiting the maximum delay time given in the data sheet.
Isn't the 6 variable version of this for if you're just wiring R/W to ground and not connecting it to arduino ? If you wanted to connect R/W to say arduino pin 10, the code would be :