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

36 lines
837 B
Arduino
Raw Normal View History

2020-10-18 14:47:46 +02:00
/* HD44780 Character display debugger */
2020-10-24 23:30:50 +02:00
#define EN 11
const byte DATA_BUS[] = {3, 4, 5, 6, 7, 8, 9, 10};
2020-10-18 14:47:46 +02:00
void setup() {
pinMode(EN, INPUT);
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-10-24 23:30:50 +02:00
attachInterrupt(digitalPinToInterrupt(2), 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);
}