I have thought about subroutines, but I think it requires more bytes.
This is what I do now to send data to an LCD:
Code:
mov <port 1 address>, <8-bit data>
clr P3.0
setb P3.0
clr = clear bit, and setb = set bit. P3.0 is connected to the "enable" pin of the LCD. Port 1 is connected to the LCD data pins.
This is what I would have done, had I used subroutines:
Code:
mov <port 1 address>, <8-bit data>
<code to jump to the subroutine>
The jumping code could be as simple as a jump statement, but it would save me only 50% of code.
If I timed the "enable" pin with an external timer, my code will be like this:
(port 3.0 determines whether the external timer is enabled or not. 1 = yes.)
Code:
setb P3.0
mov <port 1 address>, <8-bit data>
mov <port 1 address>, <8-bit data>
mov <port 1 address>, <8-bit data>
....
mov <port 1 address>, <8-bit data>
mov <port 1 address>, <8-bit data>
mov <port 1 address>, <8-bit data>
clr P3.0
This way is much better! I save at least 2 - 4 bytes of code per character. Multiply that by a 2x16 character display, I would save 64 - 128 bytes.
So instead of using 5 - 7 bytes of code, I use 3 bytes (just for a MOV instruction) per letter.
But the only problem that I might have is with the timing. If I can get the enable pin to go low, then high, the moment the MOV instruction is complete, and have the same happen for every MOV instruction thereafter, I will be happy. Also, if P3.0 is cleared, the external timing doesn't count, and the LCD is then not written to. So I treat P3.0 as the "write enable" byte.
Actually I'm using the 7555 right now. I'm just saying "555" because it is easier to type in.
Also, I notice that my rom and the 8051 works well with each other but the output of the ports either produce a strong logic high, or in between high, and low. In other words, if I tied an LED with a resistor between a port pin and ground, the light goes bright, or dim, but never off.
This makes me think that I need pull-down resistors.
my 8051 is the intel 80C51BH.