Working debugger, non-working programmer and lcd test procedure with lcd mapped in memory

This commit is contained in:
Daniele Verducci su MatissePenguin 2020-10-14 19:09:54 +02:00
parent f65d572f74
commit 63974b148c
4 changed files with 244 additions and 31 deletions

BIN
assembly/a.bin Normal file

Binary file not shown.

View File

@ -0,0 +1,40 @@
;hd44780 lcd test procedure
ld hl,$4000 ;address reg points to lcd instruction address
;reset procedure
ld a,%00111000
ld (hl),a
ld a,%00001000
ld (hl),a
ld a,%00000001
ld (hl),a
;init procedure
ld a,%00111000
ld (hl),a
ld a,%00001110
ld (hl),a
;write characters to display
ld hl,$4001 ;address reg points to lcd data address
ld a,%01000100
ld (hl),a
ld a,%01100001
ld (hl),a
ld a,%01101110
ld (hl),a
ld a,%01101001
ld (hl),a
ld a,%01100101
ld (hl),a
ld a,%01101100
ld (hl),a
ld a,%01100101
ld (hl),a
ld a,%00100001
ld (hl),a
halt

View File

@ -0,0 +1,175 @@
/* ************** EEPROM PROGRAMMER ******************
HARDWARE:
CORRISPONDENZA PIN EEPROM Atmel AT28C64B -> ARDUINO MEGA 2560
(Compatibile con eeprom fino a 16 bit di address bus. In caso di altre eeprom collegare secondo datasheet)
NB: Nel caso della eeprom da 8k, ci sono solo 12 address bus, quindi gli altri 4 pin provenienti dall'Arduino
vengono lasciati disconnessi
Arduino VCC 11 38 40 44 10 42 12 9 8 7 6 5
Eeprom 28 27 26 25 24 23 22 21 20 19 18 17 16 15
____________________________________________________________________
| |
| |
|_ |
|_) Atmel AT28C64B |
| |
| |
|____________________________________________________________________|
Eeprom 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Arduino 46 36 34 32 30 28 26 24 22 2 3 4 GND
CORRISPONDENZA FUNZIONALE:
Address bus (A0...A15): 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52
Data bus (D0...D7): 2, 3, 4, 5, 6, 7, 8, 9
Control bus:
/OE 10
/WE 11
/CE 12
*/
const byte ROM_DATA[] = {0x76, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00};
const byte ADDR_BUS[] = {52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22};
const byte DATA_BUS[] = {9, 8, 7, 6, 5, 4, 3, 2};
const byte CTRL_BUS_OE = 10;
const byte CTRL_BUS_WE = 11;
const byte CTRL_BUS_CE = 12;
void setup() {
Serial.begin(57600);
for(int pin=0; pin < 16; pin++) {
pinMode(ADDR_BUS[pin], OUTPUT);
}
setDataBusAs(INPUT);
pinMode(CTRL_BUS_OE, OUTPUT);
pinMode(CTRL_BUS_WE, OUTPUT);
pinMode(CTRL_BUS_CE, OUTPUT);
digitalWrite(CTRL_BUS_OE, HIGH); //Active low
digitalWrite(CTRL_BUS_WE, HIGH); //Active low
digitalWrite(CTRL_BUS_CE, HIGH); //Active low
delay(1000);
//readRom(8192);
writeRom();
verifyRom();
}
void writeRom() {
digitalWrite(CTRL_BUS_OE, HIGH);
setDataBusAs(OUTPUT);
Serial.print("Starting to write ROM... ");
for (int i=0; i<sizeof(ROM_DATA); i++) {
writeIntToAddressBus(i);
delayMicroseconds(5); // Address hold time (tAH)
digitalWrite(CTRL_BUS_CE, LOW);
digitalWrite(CTRL_BUS_WE, LOW);
writeByteToDataBus(ROM_DATA[i]);
delayMicroseconds(5); // Data setup time (tDS)
digitalWrite(CTRL_BUS_WE, HIGH);
digitalWrite(CTRL_BUS_CE, HIGH); //Active low
delayMicroseconds(5); // Data hold time (tDH)
}
setDataBusAs(INPUT);
Serial.println("Done.");
}
void verifyRom() {
Serial.print("Starting to verify ROM... ");
digitalWrite(CTRL_BUS_WE, HIGH); //Active low
char output[50] = {};
for (int i=0; i<sizeof(ROM_DATA); i++) {
writeIntToAddressBus(i);
delayMicroseconds(5);
digitalWrite(CTRL_BUS_OE, LOW); //Active low
digitalWrite(CTRL_BUS_CE, LOW); //Active low
delayMicroseconds(5);
byte readData = getData();
if(readData != ROM_DATA[i]) {
sprintf(output, "Error at addr %04x: expected %02x, found %02x", i, ROM_DATA[i], readData);
Serial.println(output);
}
while(true){}
digitalWrite(CTRL_BUS_OE, HIGH); //Active low
digitalWrite(CTRL_BUS_CE, HIGH); //Active low
delayMicroseconds(5);
}
Serial.println("Done.");
}
void readRom(int bytes) {
digitalWrite(CTRL_BUS_WE, HIGH); //Active low
char output[50] = {};
for (int i=0; i<bytes; i++) {
writeIntToAddressBus(i);
delayMicroseconds(5);
digitalWrite(CTRL_BUS_OE, LOW); //Active low
digitalWrite(CTRL_BUS_CE, LOW); //Active low
delayMicroseconds(5);
byte readData = getData();
sprintf(output, "0x%02x ", readData);
Serial.print(output);
digitalWrite(CTRL_BUS_OE, HIGH); //Active low
digitalWrite(CTRL_BUS_CE, HIGH); //Active low
delayMicroseconds(5);
}
Serial.println("Done.");
}
unsigned int getData() {
setDataBusAs(INPUT);
unsigned int data = 0;
for(int pin=0; pin < 8; pin++) {
byte b = digitalRead(DATA_BUS[pin]) ? 1 : 0;
data = (data << 1) + b; // Shifta di 1 e aggiunge il bit corrente. Serve per ricostruire il numero da binario
}
return data;
}
void setDataBusAs(byte mode){
for(int pin=0; pin < 8; pin++) {
pinMode(DATA_BUS[pin], mode);
}
}
void writeByteToDataBus(byte j) {
setDataBusAs(OUTPUT);
for (int n=0; n<8; n++)
{
if((0x01&j) < 0x01)
{
digitalWrite(DATA_BUS[n],LOW);
} else {
digitalWrite(DATA_BUS[n],HIGH);
}
j>>=1;
}
}
void writeIntToAddressBus(int j) {
for (int n=0; n<16; n++)
{
if((0x01&j) < 0x01)
{
digitalWrite(ADDR_BUS[n],LOW);
} else {
digitalWrite(ADDR_BUS[n],HIGH);
}
j>>=1;
}
}
void loop() {}

View File

@ -55,8 +55,9 @@ const byte MODE_ROM_EMULATOR = 1;
const byte MODE_ROM_RAM_EMULATOR = 2; const byte MODE_ROM_RAM_EMULATOR = 2;
const byte ADDR_BUS[] = {50, 52, A11, A9, A8, A12, A15, A14, 53, 51, 49, 47, 45, 43, 41, 39}; const byte ADDR_BUS[] = {50, 52, A11, A9, A8, A12, A15, A14, 53, 51, 49, 47, 45, 43, 41, 39};
const byte DATA_BUS[] = {34, 40, 42, 46, 44, 36, 30, 32}; const byte DATA_BUS[] = {34, 40, 42, 44, 46, 36, 30, 32};
const byte CTRL_BUS_RD = 20; //const byte CTRL_BUS_RD = 20;
const byte CTRL_BUS_RD = 3;
const byte CTRL_BUS_WR = 23; const byte CTRL_BUS_WR = 23;
const byte CTRL_BUS_BUSACK = 25; const byte CTRL_BUS_BUSACK = 25;
const byte CTRL_BUS_WAIT = 27; const byte CTRL_BUS_WAIT = 27;
@ -68,7 +69,8 @@ const byte CTRL_BUS_IORQ = A13;
const byte CTRL_BUS_MREQ = 22; const byte CTRL_BUS_MREQ = 22;
const byte CTRL_BUS_HALT = 24; const byte CTRL_BUS_HALT = 24;
const byte CTRL_BUS_NMI = 26; const byte CTRL_BUS_NMI = 26;
const byte CTRL_BUS_CLK= 21; //const byte CTRL_BUS_CLK= 21;
const byte CTRL_BUS_CLK= 2;
const byte CTRL_BUS_INT = 28; const byte CTRL_BUS_INT = 28;
const byte PWR_GND = 37; const byte PWR_GND = 37;
const byte PWR_VCC = 38; const byte PWR_VCC = 38;
@ -88,8 +90,8 @@ const byte PWR_VCC = 38;
*/ */
const byte MODE = MODE_ROM_EMULATOR; const byte MODE = MODE_ROM_EMULATOR;
//const byte ROM_DATA[] = {0x00, 0x00, 0x00, 0x00, 0xC3, 0x00, 0x00}; const byte ROM_DATA[] = {0x00, 0x00, 0x00, 0x00, 0xC3, 0x00, 0x00};
const byte ROM_DATA[] = {0x00, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00}; //const byte ROM_DATA[] = {0x00, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00};
@ -97,6 +99,18 @@ const byte ROM_DATA[] = {0x00, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00};
void setup() { void setup() {
Serial.begin(57600); Serial.begin(57600);
Serial.print("Started in mode ");
switch(MODE) {
case MODE_DEBUGGER:
Serial.println("debugger");
break;
case MODE_ROM_EMULATOR:
Serial.println("rom emulator");
break;
case MODE_ROM_RAM_EMULATOR:
Serial.println("rom/ram emulator");
break;
}
for(int pin=0; pin < 16; pin++) { for(int pin=0; pin < 16; pin++) {
pinMode(ADDR_BUS[pin], INPUT); pinMode(ADDR_BUS[pin], INPUT);
} }
@ -121,19 +135,6 @@ void setup() {
pinMode(PWR_VCC, INPUT); pinMode(PWR_VCC, INPUT);
attachInterrupt(digitalPinToInterrupt(CTRL_BUS_CLK), onClk, RISING); attachInterrupt(digitalPinToInterrupt(CTRL_BUS_CLK), onClk, RISING);
unsigned int data = ROM_DATA[4];
writeByteToDataBus(data);
char output[30] = {};
sprintf(output, "%04x r- %02x Emu ROM read", 4, data);
Serial.println(output);
} }
@ -208,19 +209,16 @@ void setDataBusAs(byte mode){
} }
} }
void writeByteToDataBus(byte toWrite) { void writeByteToDataBus(byte j) {
setDataBusAs(OUTPUT); setDataBusAs(OUTPUT);
unsigned i; for (int n=0; n<8; n++)
for (i = 1 << 7; i > 0; i = i / 2){ {
if (toWrite & i) { if((0x01&j) < 0x01)
digitalWrite(DATA_BUS[i], HIGH); {
Serial.print(DATA_BUS[i]); digitalWrite(DATA_BUS[n],LOW);
Serial.print("->1 "); } else {
} else { digitalWrite(DATA_BUS[n],HIGH);
digitalWrite(DATA_BUS[i], LOW); }
Serial.print(DATA_BUS[i]); j>>=1;
Serial.print("->0 ");
}
} }
Serial.println(" ");
} }