I have a 6502 computer which includes a 1602 LCD, which are traditionally difficult to initialize. I have tried every possibility in assembler to initialize by software without success. If i power up without going through the initialization by instruction sequence it will start correctly when I hit reset. This means I have to power down and back up every time I want the the processor to run. Failing to go software i thought i could use a nano to develop a hardware reset procedure. This would involve using the nano when i hit the reset button to 1) power down the lcd 2) power up again 3) wait a certain time and then take the reset circuit low for a determined time. 4) bring the reset circuit high again.
I dont have any idea how to switch the lcd power on and off again. I cant use the nano directly as i dont think the pins can take the current on a continuous basis, 50mA or more as i would wish to switch the backlight as well to make sure all LCD systems are down. I tried a transistor but this gave inconsistent results. Would a relay be the way to go? I am not familiar with these components and how to specify them. Any input would be appreciated.
use either
lcd.backlight();
or
lcd.noBacklight();
to control the LCD.
How did you wire up your transistor? And which transistor did you use? 50mA is a very small current that a transistor can easily handle
What 1602 display? A bare display or with an I2C backpack?
If you switch the LCD Vcc off and on the LCD will have to go through the whole initialization process.
If you are using one of the LiquidCrystal or hd44780 libraies you can turn the display off with the noDisplay() function. Turn it back on with the display() function.
Thanks for the reply. It is a 2 line character LCD based on 44780. It is linked through a VIA to a 6502 MCU running code from an EEPROM. I realize that it is probably possible to use one of the Arduino libraries to switch on and off but I think I would struggle to coordinate this with resetting the 6502. I also don´t know if this would have the same effect as resetting the LCD. The programs run fine on activating reset after power up of the whole board. When pressing reset thereafter the LCD doesn't respond and all code that I´ve tried to reset the LCD by instruction hasn't worked. For this reason i want to try a quasi hardware approach. Using an Arduino as outlined above should avoid the software problems.
Thanks for the reply. See my reply to groundFungus.
For a 1602 LCD? Have you measured that? I would expect less than half of that.
I thought the current would not be a problem either and probably was not. What i got was flickering on the LCD screen and sometimes did not switch off. I used a BC337 NPN transistor, nano to base. Emitter tied to ground. Collector tied to VCC via 10k resistor. Then the cathodes of LCD (also backlight) also tied to collector downstream of resistor. Any thoughts on this arrangement?
Will have a look. I have seen posts talking about 100 mA including backlight.
You should have a resistor between your nano and base. When you cut power to the LCD, are you removing power from the 6502? If not, you may be back powering the LCD through the MCU which is not good.
While there could be a h/w issue, it sounds to me like this is a s/w issue that should be fixed by fixing the s/w rather than going down a path of throwing h/w at it - which also involves more s/w.
hd44780 LCD Initialization is not difficult. The most bullet proof way does however, require doing some very specific things, including some specific instruction sequences as well as honoring some specific instruction timing and low level h/w interface timing.
If you are having difficulty initializing or re-initializing then you are likely not doing something correctly.
Don't feel bad, from my reading through many hd44780 lcd libraries out there over more than 15+ years, it appears that most hd44780 LCD library authors really don't fully understand the hd44780 instruction set nor the initialization by instruction sequence and its odd looking instruction timing requirements.
There is much babble out there on this subject and much of it is either incomplete or just plain incorrect. Also there are some sections of the Hitachi hd44780 data sheet that are a bit confusing & misleading, and one section that is actually incorrect.
I have spent years working with these devices and put that experience into the Arduino hd44780 library.
My suggestion would be go look at the Arduino hd44780 library source code for some inspiration.
See the begin() function in the hd44780.cpp module.
It has hundreds of lines of comments explaining the initialization sequence in great detail.
There is even around a 250 line comment block dedicated to explaining how the initialize by instruction sequence actually works.
While you could figure this out after spending enough time with the datasheet, you will not find this information spelled out this directly in the data sheet.
Now, all that said, there are some "1602" LCD devices out there that do not use hd44780 chips but some other chips. And one of these chips is just plain broken by design. They decided to add a user selectable font, but the way they did it was to put a bit into the function set instruction. This breaks the initialize by instruction.
There is no bullet proof way to initialize that chip. i.e. once you get out of nibble sync in 4 bit mode, the chip must be power cycled to be re-initialized.
The developers of this chip were fools.
This is not a very common issues as chips with issue are not very common.
In terms of your issues, Could you explain a bit more. i.e.
- what voltage are you running at?
- which chipset on on the LCD module?
- what mode you are using. i.e. 4 bit or 8 bit.
- are you just doing writes or are you also using reads for BUSY status?
And how you are ensuring you are honoring all the various timing requirements.
How do you ensure instruction timing?
- fixed delays, or BUSY polling?
For h/w timing how do you ensure timing like
tAS, tCYCE, PWEH,
And for reads like BUSY status are you ensuring tDDR ?
--- bill
Thanks Bill, I must say the LCD initialization is a mystery, but I did follow the procedure for initialization by instruction. In the end i found i had an incorrect connection on the RAM chip, and now it is all working. I do intend to read the 44780 code you suggested. I always like to understand what is going on. My thanks to you and all the others for the kind inputs.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.