Author SHA1 Message Date
mangavalk 91396a582f not sure if this is useful or can be deleted. 2024-07-26 20:09:40 +02:00
mangavalk 94a399010e arduinp driver 2024-07-26 20:06:58 +02:00
Patrick Valk 556190fdfe Personal drivers/hd44780.c 2016-11-07 11:31:48 +01:00
5 changed files with 533 additions and 1 deletions
@@ -0,0 +1,158 @@
#include <LiquidCrystal.h>
LiquidCrystal lcd(9, 8, 7, 6, 5, 4, 3, 2);
int row = 0;
int line = 0;
bool controller = false;
void setup() {
Serial.begin(115200);
// set up the LCD's number of columns and rows:
lcd.begin(40, 4);
lcd.clear();
lcd.home();
}
#define LCDSERIALIZER_LCDI 0xFE
byte serial_getch() {
int incoming;
while (Serial.available() == 0) {
}
// read the incoming byte:
incoming = Serial.read();
//Serial.write(incoming);
return (incoming & 0xff);
}
void loop() {
byte rxbyte = serial_getch(); // Fetch byte
if (rxbyte == LCDSERIALIZER_LCDI) // If LCD instruction
{
//Serial.write("[CMD]");
rxbyte = serial_getch(); // Fetch byte
if (rxbyte == 0x01)
{
Serial.println("Clear screen");
}
else if (rxbyte == 0x0c)
{
Serial.println("Restore the display (with cursor hidden)");
}
else if (rxbyte == 0x08)
{
Serial.println("Blank the display (without clearing)");
}
else if (rxbyte == 0x0c)
{
Serial.println("Make cursor invisible");
}
else if (rxbyte == 0x0f)
{
Serial.println("Turn on visible blinking-block cursor");
}
else if (rxbyte == 0x0e)
{
Serial.println("Turn on visible underline cursor");
}
else if (rxbyte == 0x10)
{
Serial.println("Move cursor one character left");
}
else if (rxbyte == 0x14)
{
Serial.println("Move cursor one character right");
}
else if (rxbyte == 0x15)
{
Serial.println("(15)Move cursor one character right");
}
else if (rxbyte == 0x02)
{
Serial.println("Home (move cursor to top/left character position)");
}
else if (rxbyte == 0x18)
{
Serial.println("Scroll display one character left (all lines)");
}
else if (rxbyte == 0x1e)
{
Serial.println("Scroll display one character right (all lines)");
}
else if (rxbyte == 0x20)
{
Serial.println("Function set (4-bit interface, 1 line, 5*7 Pixels)");
}
else if (rxbyte == 0x28)
{
Serial.println("Function set (4-bit interface, 2 lines, 5*7 Pixels)");
}
else if (rxbyte == 0x30)
{
Serial.println("Function set (8-bit interface, 1 line, 5*7 Pixels)");
}
else if (rxbyte == 0x38)
{
Serial.println("Function set (8-bit interface, 2 lines, 5*7 Pixels)");
}
else if (rxbyte == 0x80)
{
serial_getch(); // instruction
row = serial_getch();
serial_getch(); // instruction
line = serial_getch();
lcd.setCursor(line, row);
Serial.println("Set Cursor to " + String(row) + "," + String(line));
return;
}
else if (rxbyte & 0x40)
{
//Serial.println("Set pointer in character-generator RAM (CG RAM address)");
Serial.println();
lcd.setController(0);
lcd.command(rxbyte);
lcd.setController(1);
lcd.command(rxbyte);
// get custom char
for (int i = 0; i < 8; i++)
{
rxbyte = serial_getch(); // Fetch byte
lcd.setController(0);
lcd.write(rxbyte);
lcd.setController(1);
lcd.write(rxbyte);
}
return;
}
else
{
// print byte.
String thisString = String(rxbyte, HEX);
Serial.println("UNKNOWN " + thisString);
}
//if (rxbyte != 0x80 && !(rxbyte & 0x40))
lcd.command(rxbyte);
}
else
{
// print byte.
//String thisString = String(rxbyte, HEX);
//Serial.println(thisString);
//Serial.println("position " + String(row) + " " + String(line));
lcd.write(rxbyte);
line++;
}
}
@@ -0,0 +1,193 @@
#include <LiquidCrystal.h>
LiquidCrystal lcd(9, 8, 7, 6, 5, 4, 3, 2);
int row = 0;
int line = 0;
bool controller = false;
int temp = 0;
int ignore = 0;
void setup() {
Serial.begin(115200);
// set up the LCD's number of columns and rows:
lcd.begin(40, 4);
lcd.clear();
lcd.home();
}
#define LCDSERIALIZER_LCDI 0xFE
byte serial_getch() {
int incoming;
while (Serial.available() == 0) {
}
// read the incoming byte:
incoming = Serial.read();
//Serial.write(incoming);
return (incoming & 0xff);
}
void loop() {
byte rxbyte = serial_getch(); // Fetch byte
if (rxbyte == LCDSERIALIZER_LCDI) // If LCD instruction
{
//Serial.write("[CMD]");
rxbyte = serial_getch(); // Fetch byte
if (rxbyte == 0x01)
{
Serial.println("Clear screen");
}
else if (rxbyte == 0x0c)
{
Serial.println("Restore the display (with cursor hidden)");
}
else if (rxbyte == 0x08)
{
Serial.println("Blank the display (without clearing)");
}
else if (rxbyte == 0x0c)
{
Serial.println("Make cursor invisible");
}
else if (rxbyte == 0x0f)
{
Serial.println("Turn on visible blinking-block cursor");
}
else if (rxbyte == 0x0e)
{
Serial.println("Turn on visible underline cursor");
}
else if (rxbyte == 0x10)
{
Serial.println("Move cursor one character left");
}
else if (rxbyte == 0x14)
{
Serial.println("Move cursor one character right");
}
else if (rxbyte == 0x15)
{
Serial.println("(15)Move cursor one character right");
}
else if (rxbyte == 0x02)
{
Serial.println("Home (move cursor to top/left character position)");
}
else if (rxbyte == 0x18)
{
Serial.println("Scroll display one character left (all lines)");
}
else if (rxbyte == 0x1e)
{
Serial.println("Scroll display one character right (all lines)");
}
else if (rxbyte == 0x20)
{
Serial.println("Function set (4-bit interface, 1 line, 5*7 Pixels)");
}
else if (rxbyte == 0x28)
{
Serial.println("Function set (4-bit interface, 2 lines, 5*7 Pixels)");
}
else if (rxbyte == 0x30)
{
Serial.println("Function set (8-bit interface, 1 line, 5*7 Pixels)");
}
else if (rxbyte == 0x38)
{
Serial.println("Function set (8-bit interface, 2 lines, 5*7 Pixels)");
}
else if (rxbyte & 0x80)
{
byte address = rxbyte & 0x7f;
row = address <= 0x27 ? 0 : 1;
line = address <= 0x27 ? address : address - 64;
Serial.print("Address received " + String(row) + "," + String(line) + " \t");
if (controller)
row = row + 2;
if (row == 1 && line == 0)
controller = true;
else if (row == 3)
controller = false;
lcd.setCursor(line, row);
Serial.println("Set Cursor to " + String(row) + "," + String(line));
return;
}
else if (rxbyte & 0x40)
{
//Serial.println("Set pointer in character-generator RAM (CG RAM address)");
Serial.println();
// uhh?
//ignore = 8;
lcd.setController(0);
lcd.command(rxbyte);
lcd.setController(1);
lcd.command(rxbyte);
// get custom char
for (int i = 0; i < 8; i++)
{
rxbyte = serial_getch(); // Fetch byte
lcd.setController(0);
lcd.write(rxbyte);
lcd.setController(1);
lcd.write(rxbyte);
}
return;
}
else
{
// print byte.
String thisString = String(rxbyte, HEX);
Serial.println("UNKNOWN " + thisString);
}
//if (rxbyte != 0x80 && !(rxbyte & 0x40))
lcd.command(rxbyte);
}
else
{
// print byte.
//String thisString = String(rxbyte, HEX);
//Serial.println(thisString);
//Serial.println("position " + String(row) + " " + String(line));
//if (ignore == 0)
//{
lcd.write(rxbyte);
line++;
//}
/*else
{
lcd.setController(0);
lcd.write(rxbyte);
lcd.setController(1);
lcd.write(rxbyte);
ignore--;
}*/
/*if (line > 39)
{
row = row < 3 ? row + 1 : 0;
line = 0;
Serial.println("row increased by line count");
}
lcd.setCursor(line, row);*/
}
}
@@ -0,0 +1,172 @@
/*#include <LiquidCrystal.h>
LiquidCrystal lcd(9, 8, 7, 6, 5, 4, 3, 2);
int row = 0;
int line = 0;
void setup() {
Serial.begin(115200);
// set up the LCD's number of columns and rows:
lcd.begin(40, 4);
lcd.clear();
lcd.home();
}
#define LCDSERIALIZER_LCDI 0xFE
byte serial_getch() {
int incoming;
while (Serial.available() == 0) {
}
// read the incoming byte:
incoming = Serial.read();
//Serial.write(incoming);
return (incoming & 0xff);
}
void loop() {
byte rxbyte;
rxbyte = serial_getch(); // Fetch byte
if (rxbyte == 0x11) // If LCD instruction
{
Serial.write("[CMD]");
rxbyte = serial_getch(); // Fetch byte
if (rxbyte == 0x0C)
{
lcd.clear();
lcd.home();
Serial.println("[ff]");
line = 0;
row = 0;
lcd.setCursor(line, row);
}
else if (rxbyte == 0x01)
{
Serial.println("[clr]");
lcd.clear();
}
else if (rxbyte == 0x0D)
{
Serial.println("[cr]");
lcd.setCursor(0, row);
}
else if (rxbyte == 0x0A)
{
Serial.println("[nl]");
row = row < 3 ? row + 1 : 0;
line = 0;
lcd.setCursor(line, row);
}
else if (rxbyte == 0xc0) {
lcd.clear();
lcd.home();
Serial.println("[ff]");
row = 0;
line = 0;
lcd.setCursor(line, row);
}
else if (rxbyte == 0x12) {
Serial.println("[\n]");
row = row < 3 ? row + 1 : 0;
line = 0;
lcd.setCursor(line, row);
}
else if (rxbyte == 0x04) {
Serial.println("[ ]");
line++;
if (line > 39)
{
row = row < 3 ? row + 1 : 0;
line = 0;
}
lcd.setCursor(line, row);
}
else if (rxbyte == 0x02) {
Serial.write("[hm]");
lcd.clear();
lcd.home();
Serial.println("[ff]");
line = 0;
row = 0;
lcd.setCursor(line, row);
}
else if (rxbyte == 0x80) {
lcd.clear();
lcd.home();
Serial.println("[80 clr]");
line = 0;
row = 0;
lcd.setCursor(line, row);
}
else
{
Serial.print("[?]");
String thisString = String(rxbyte, HEX);
Serial.println(thisString);
}
}
/*else if (rxbyte == 0x12) {
Serial.println("[]");
}
else if (rxbyte == 0x15) {
Serial.println("[]");
}*/
/*else if (rxbyte == 0x20) {
Serial.println("[]");
}*/
/*else if (rxbyte == 0x15) {
Serial.println("[]");
}
else if (rxbyte == 0x00) {
Serial.println("[]");
}
else if (rxbyte == 0x1b) {
Serial.println("[]");
}
else if (rxbyte == 0x1f) {
Serial.println("[]");
}
else if (rxbyte == 0x0e) {
Serial.println("[<]");
line--;
if (line < 0)
{
row = row > 0 ? row - 1 : 3;
line = 0;
}
}
else if (rxbyte == 0x01) {
Serial.print("[pos]");
serial_getch();
serial_getch();
serial_getch();
serial_getch();
}
else if (rxbyte == 0x0a) {
row = row < 3 ? row + 1 : 0;
lcd.setCursor(line, row);
}
else {
String thisString = String(rxbyte, HEX);
Serial.println(thisString);
lcd.write(rxbyte); //Otherwise just dump it as text
line++;
if (line > 39)
{
row = row < 3 ? row + 1 : 0;
line = 0;
}
lcd.setCursor(line, row);
}
}
*/
+10 -1
View File
@@ -622,8 +622,17 @@ HD44780_position(Driver *drvthis, int x, int y)
if ((relY % 4) >= 2)
DDaddr += p->width;
}
p->hd44780_functions->senddata(p, dispID, RS_INSTR, POSITION | DDaddr);
//p->hd44780_functions->senddata(p, dispID, RS_INSTR, POSITION | DDaddr);
p->hd44780_functions->senddata(p, dispID, RS_INSTR, 0x80);
p->hd44780_functions->uPause(p, 40); /* Minimum exec time for all commands */
p->hd44780_functions->senddata(p, dispID, RS_INSTR, relY);
p->hd44780_functions->uPause(p, 40); /* Minimum exec time for all commands */
p->hd44780_functions->senddata(p, dispID, RS_INSTR, x);
p->hd44780_functions->uPause(p, 40); /* Minimum exec time for all commands */
if (p->hd44780_functions->flush != NULL)
p->hd44780_functions->flush(p);
}