Created
January 4, 2018 04:36
-
-
Save jblang/25947d7ca48e19c52e7cd7d57c0514d9 to your computer and use it in GitHub Desktop.
Arduino ROM dump routine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define bytesPerLine 16 | |
#define dataSize 131072 | |
#define A16 10 | |
#define _CE 11 | |
#define _OE 12 | |
#define _WE 13 | |
void setupPorts() { | |
// Set disable writing and output, enable chip | |
digitalWrite(_WE, HIGH); | |
digitalWrite(_OE, HIGH); | |
digitalWrite(_CE, LOW); | |
digitalWrite(A16, LOW); | |
// Make A16 and control signals outputs | |
pinMode(A16, OUTPUT); | |
pinMode(_WE, OUTPUT); | |
pinMode(_OE, OUTPUT); | |
pinMode(_CE, OUTPUT); | |
// Make ports for low 16 bits of address outputs | |
DDRA = 0xff; | |
DDRB = 0xff; | |
} | |
void setAddress(long addr) { | |
PORTA = (addr >> 8) & 0xff; | |
PORTB = addr & 0xff; | |
digitalWrite(A16, addr & 0x100 ? HIGH : LOW); | |
} | |
void writeData(long addr, byte data) { | |
setAddress(addr); | |
byte DDRC_save = DDRC; | |
digitalWrite(_OE, HIGH); | |
DDRC = 0xff; | |
PORTC = data; | |
digitalWrite(_WE, LOW); | |
delayMicroseconds(1); | |
digitalWrite(_WE, HIGH); | |
DDRC = DDRC_save; | |
} | |
byte readData(long addr) { | |
setAddress(addr); | |
byte DDRC_save = DDRC; | |
DDRC = 0x00; | |
digitalWrite(_OE, LOW); | |
delayMicroseconds(1); | |
byte data = PINC; | |
digitalWrite(_OE, HIGH); | |
DDRC = DDRC_save; | |
return data; | |
} | |
void writeTestData() { | |
// Write test data | |
for (long addr = 0; addr < dataSize; addr++) { | |
writeData(addr, addr & 0xff); | |
} | |
} | |
void hexDump() { | |
Serial.println("ROM Dump"); | |
for (long row = 0; row < dataSize; row += bytesPerLine) { | |
Serial.print(row, HEX); | |
Serial.print(": "); | |
for (long col = 0; col < bytesPerLine; col++) { | |
Serial.print(readData(row + col), HEX); | |
Serial.print(" "); | |
} | |
Serial.println(); | |
} | |
} | |
void binaryDump() { | |
for (long addr = 0; addr < dataSize; addr++) { | |
Serial.write(readData(addr)); | |
} | |
Serial.flush(); | |
} | |
void setup() { | |
//Initialize serial and wait for port to open: | |
Serial.begin(500000); | |
while (!Serial) { | |
; // wait for serial port to connect. Needed for native USB port only | |
} | |
setupPorts(); | |
//writeTestData(); | |
hexDump(); | |
//binaryDump(); | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment