The data shift should change to the below code to access bit4..7
Code:
LCD= (dt & 0x0F0);
lcd=LCD;
RS=1;
EN=1;
delay();
EN=0;
LCD=((dt & 0x0F)<<4);
I hope, the code can work after these changes. There are however some weaknesses involved with the code.
- The init code will depend on a previous hardware reset (e.g. power on reset) of the LCD controller. It won't work, if the controller state has been messed up somehow. In this case the more complex "Initializing by Instruction" procedure would required, refer to the HD44780 datasheet.
- The display timing is ineffective by applying rather long delays for each write. Using optimized timing and checking LCD busy flag would considerably speed it up.
It should be also noted, that writing to the lcd data port (P0) implicitely resets all LCD control lines as well. But it's no problem with the present code.