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
6 changed files with 525 additions and 8 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);
}
}
*/
+1 -1
View File
@@ -164,7 +164,7 @@ check_board_rev(Driver *drvthis)
/* On boards that have been overvolted, the MSB will be set */
rev &= 0x00ff;
if ((strcmp(hw, "BCM2708") != 0 && strcmp(hw, "BCM2709") != 0) || rev == 0) {
report(RPT_ERR, "check_board_rev: This board is not recognized as a Raspberry Pi! Found:%s",hw);
report(RPT_ERR, "check_board_rev: This board is not recognized as a Raspberry Pi!");
return NULL;
}
+1 -7
View File
@@ -624,8 +624,7 @@ HD44780_position(Driver *drvthis, int x, int y)
}
//p->hd44780_functions->senddata(p, dispID, RS_INSTR, POSITION | DDaddr);
// 40X4
p->hd44780_functions->senddata(p, dispID, RS_INSTR, POSITION);
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);
@@ -700,15 +699,11 @@ HD44780_flush(Driver *drvthis)
/* there are differences, ... */
if (sp <= ep) {
for (drawing = 0; sp <= ep; x++, sp++, sq++) {
/* x%8 is for 16x1 displays only ! */
if (!drawing || (p->dispSizes[dispID-1] == 1 && p->width == 16 && (x % 8 == 0))) {
drawing = 1;
HD44780_position(drvthis,x,y);
}
// 40X4 fix? // NOT WORKING
// HD44780_position(drvthis,x,y);
p->hd44780_functions->senddata(p, dispID, RS_DATA, *sp);
p->hd44780_functions->uPause(p, 40); /* Minimum exec time for all commands */
*sq = *sp; /* Update backing store */
@@ -724,7 +719,6 @@ HD44780_flush(Driver *drvthis)
if (!p->cc[i].clean) {
int row;
// 40X4
/* Tell the HD44780 we will redefine char number i */
p->hd44780_functions->senddata(p, 0, RS_INSTR, SETCHAR | i * 8);
p->hd44780_functions->uPause(p, 40); /* Minimum exec time for all commands */