I fixed the address issues with different LCD types by updating the TextLCD lib.
There is now support for
- LCD8x1, /< 8x1 LCD panel */
- LCD8x2, /< 8x2 LCD panel */
- LCD16x2, /< 16x2 LCD panel (default) */
- LCD16x2B, /< 16x2 LCD panel alternate addressing */
- LCD16x4, /< 16x4 LCD panel */
- LCD20x2, /< 20x2 LCD panel */
- LCD20x4, /< 20x4 LCD panel */
- LCD24x2, /< 24x2 LCD panel */
- LCD24x4, /< 24x4 LCD panel (for KS0078 controller) */
- LCD40x2 /< 40x2 LCD panel */
Also added is a new method getAddress(column,row) that will return the correct memoryaddress.
You can find the lib here:
http://mbed.org/users/wim/code/TextLCD/
The code may be tested using this example:
// Hello World! for the TextLCD
#include "mbed.h"
#include "TextLCD.h"
// Host PC Communication channels
Serial pc(USBTX, USBRX); // tx, rx
//TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD16x4); // rs, e, d4-d7 ok
//TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x2); // rs, e, d4-d7 ok
TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x4); // rs, e, d4-d7 ok
//TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD24x2); // rs, e, d4-d7 ok
//TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD40x2); // rs, e, d4-d7 ok
int main() {
pc.printf("LCD Test. Columns=%d, Rows=%d\n\r", lcd.columns(), lcd.rows());
for (int row=0; row<lcd.rows(); row++) {
int col=0;
pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row));
lcd.putc('-');
// lcd.putc('0' + row);
for (col=1; col<lcd.columns()-1; col++) {
lcd.putc('*');
}
pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row));
lcd.putc('+');
}
}
Some results are shown here:
The terminal will print the actual memory address like this:
LCD Test. Columns=20, Rows=4
MemAddr(Col=0, Row=0)=0x00
MemAddr(Col=19, Row=0)=0x13
MemAddr(Col=0, Row=1)=0x40
MemAddr(Col=19, Row=1)=0x53
MemAddr(Col=0, Row=2)=0x14
MemAddr(Col=19, Row=2)=0x27
MemAddr(Col=0, Row=3)=0x54
MemAddr(Col=19, Row=3)=0x67
Edit:
Added support for LCD24x4 (KS0078 controller only) and method to show or hide cursor.
Thanks Wim I think I know where the problem lies in the TextLCD.cpp file.
case 2 and case 3 addresses are probably not correct for a 16x4 display as these were originally for a 20x4 display.