pato-z80-home-computer/prototiping-with-arduino/hd44780_debugger/hd44780_debugger.ino

55 lines
1.6 KiB
Arduino
Raw Normal View History

2021-07-11 09:49:42 +02:00
/*
* This file is part of Pat80 Utils.
*
* Pat80 Utils is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pat80 Utils is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY * without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Pat80 Utils. If not, see <http://www.gnu.org/licenses/>.
*
*
* HD44780 Character display debugger
* Used to intercept data sent from Pat80 to character display
*/
2020-10-18 14:47:46 +02:00
2020-11-19 07:32:11 +01:00
#define EN 2
const byte DATA_BUS[] = {10, 9, 8, 7, 6, 5, 4, 3};
2020-10-18 14:47:46 +02:00
void setup() {
2020-11-19 07:32:11 +01:00
pinMode(EN, INPUT_PULLUP);
2020-10-18 14:47:46 +02:00
for(int pin=0; pin < 8; pin++) {
pinMode(DATA_BUS[pin], INPUT);
}
Serial.begin(57600);
Serial.println("HD44780 debugger");
2020-10-24 23:30:50 +02:00
Serial.println("DATA BUS HEX EN");
2020-10-18 14:47:46 +02:00
2020-11-19 07:32:11 +01:00
attachInterrupt(digitalPinToInterrupt(EN), onClk, FALLING);
2020-10-18 14:47:46 +02:00
}
void loop() {}
void onClk() {
unsigned int data = 0;
for(int pin=0; pin < 8; pin++) {
byte b = digitalRead(DATA_BUS[pin]) ? 1 : 0;
Serial.print(b);
data = (data << 1) + b; // Shifta di 1 e aggiunge il bit corrente. Serve per ricostruire il numero da binario
}
2020-10-24 23:30:50 +02:00
char output[50] = {};
sprintf(output, " 0x%02x %c",
data,
digitalRead(EN) ? 'D' : 'I'
);
2020-10-18 14:47:46 +02:00
Serial.println(output);
}