Hello,
Firstly, there is contradictory data given within the datasheet for the LCD module. Section 5 specifies the Vdd range 4.5 - 5.5 volt, whereas Section 7 suggests that Vdd should be at a level of 3.0 volt. I suspect that the first voltage range is the correct one.
However, I notice that you are not feeding Vdd from a regulated source, but are using a resistive voltage divider supplied from 12 volt, which effectively gives a 600 ohm source resistance. Why not feed Vdd from the same 5 volt (regulated?) source that supplies the MCU device? If the V0 level at pin 3 alters, possibly because of poor regulation at pin 2, this will affect the display contrast, and may well be part of the problem, should the display current draw fluctuate.
What you are doing at pins 15 and 16 of the display totally escapes me. Apparently these pins provide current to the display backlight, with pin 16 being designated LED- (assuming the datasheet is correct). I would expect this pin should not have +12 volt connected via a series resistor. I would also expect that the LED+ pin should not be connected to the V0 pin, via a resistor.
I think that you need to clean up these hardware issues before investigating any coding problems. Normally, the V0 pin would be supplied via a preset potentiometer, or some other variable voltage source, to provide for contrast adjustment. The V0 level is usually quite sensitive.
In your later post, you mention the presence of a relay, which is not apparent within your schematic.
Regards,
Mac