let me shed a little light on some beginner’s questions, using 4x20 LCD SainSmart2004 together with ATMEL AVR Attiny2313.
However, basically most of popular software libraries require MCUs with on board I2C- or TWI hardware interfaces.
Nevertheless, let me shortly explain, how you can get working that particular LCD together with an ATtiny2313 or ATtiny4313.
Some frequently asked questions may needing a clear up, first:
The slave addresses of port adapters used here are stated in 7-bit frame format.
Thus, you need to add the read/write bit to an eight bit frame, and the address bits are shifted left (or multiplied with two).
For instance: $38 should stated in program’s instruction as: $70.
Seven different slave addresses can be chosen by appropriate soldering the A0, A1, A2 pads. A left open pad means logical One, and soldering to GND means a logical Zero.
Thus, one covers slave addresses’ range from $27 to $20, and when using the unit PCF8574A from $3F to $38.
That is why you need to have a look on the port adaptor’s mcu’s stamped on part number, first, weather it is an PCF8574 or an quite different addressed PCF8574A.
The port adapter pinout is set accordingly to the LCD pinout:
Vss, Vdd, V0, RS, R/W, Ena, D0, D1 ,D2, D3, D4, D4, D6, D7, A, K
The pins D0…D3 are not connected and remain unused, thus you must initialize the LCD in four bit mode at all.
A and K are marking the anode (+) resp. catode (-) of the backlight, but should not be connected externally, because the backlight will be controlled by the program itself.
Pin D0 in above pinout is not directly accessible, but that one bit got the function of the setup of the led backlight by software after initialization successfully done.
The string for backlight on should read: 0b00001000 or $08.
The data value definition is defined from MSB to LSB, also to transmit in that direction.
There are not existing extra pins for the control bits to communicate with, which one might have ever used on other popular LCD initialization strings.
Thus, the function of the crucial pins, “Register Select”, “Read/Write”, “Enable” have to be included into the data byte transfer itself.
That means, that LCD init sequence programs should take this fact into consideration or have to be revised, occasionally.
The main difference in using ATMEL ATMegas and ATtinys is, that you can make it possible to communicate via I2C or TWI ,
when you set up the USI interface of the Attiny2313 accordingly. This program here will try to explain it.