Been feverishly writing bit bang code in assembly for this I2C backpack/4 bit LCD and dont quite understand the binary constructs I need to display text. Im trying to learn this the real way, not the Arduino way where everything is handled for you in the background by library's. Please correct me where I am wrong. Thank you.
I start out in 8-bit mode initializing the 20x4 LCD because it only really recognizes the high order 0010 and disregards the low order 0000 because it is wired for 4 bit anyway:
Send 00110000 (30h) 3 times to LCD in 8 bit mode because thats what the Hitachi controller says to do before 4-bit setup.
Then Hitachi says to send 0010000 (20H) in an 8 bit send and this really puts it in 4 bit mode.
This all works fine. The problem is when in 4 bit mode Im getting confused as to how the nibbles should be constructed for sending commands and text versus interfering with the "RS" and "EN" pins.
So I know the LCD control pins are in the low byte. "EN" is tied to bit 2 so to turn it on I would need to send 00000100 and "RS" is tied to bit 0 so to turn on RS I would send 00000001
Lets use the letter "H" 01110010 (72H) as letter to send to screen. In 4 bit mode I need to break this up into high nibble 0111 and low nibble 0010.
So knowing that in 4 bit wiring mode the LCD only recognizes the high order for data and expects the upper order of the letter "H" first for data, then the lower order of the letter "H" for data.
So I would need to send out in 8 bit format 01110000 and then 00100000 for my letter "H" and the LCD would take the high order only of these 2 bytes sent separately and reassemble them correctly for letter display.
Now I know for the LCD to actually know this is data I need to make "RS" high so I would first need to send 00000001 in 8 bit mode, because the "RS" is in the lower order no matter what LCD mode I am in? Or would I need to send it twice because I am in 4 bit mode and that would complete a 4 bit transaction and still keep "RS" high?
Then for the letter "H" I would send my upper 01110000 part. Now the high order of letter "H" is in the LCD RAM, waiting for the low order of letter "H" to appear in the next incoming 8 bit high order.
But by sending this haven't I just wiped out the "RS" from being high? Would I need to send 01110001 to keep "RS" high? Wouldn't the 4 bit LCD only see my high order and the low order would still go to the control pins?
Now I need to make "EN" high 00000100 but here is my problem. If I send this I have now just made "RS" low as well. So Wouldn't I need to send 00000101 ? To make "EN" high and KEEP "RS" high?
Then I would need to make "EN" low 00000000, but that would make "RS" low now, so wouldn't I need to send 00000001 to make "EN" low and keep "RS" high?
Now I need to repeat this using the low order nibble of the letter "H" but in the high order position of the 8 bit send 00100000.
When sending data to 4 bit LCD via I2C, would I still have to include the "RS" bit in the low order of both 8 bit nibble sends just to maintain the state of "RS" should it need to be kept at 1 high?
This is SUPER CONFUSING and so far has demanded a lot of assembly code just to get this to try to work.