Reading EPROM with Arduino

Опубликовано: 20 Июль 2026
на канале: chinesemusic
8,666
88

This is a program I wrote to interface an Arduino Leonardo to read the contents of an ancient EPROM memory chip. My Arduino sketch pulses the clock to a pair of cascaded 12 bit binary counters (74HC4040). to count up a binary address from $0000 to $FFFF hex. The data is then read into the arduino's pin 2 to 9 where it is assembled back into a byte. The addresses and data are sent out the serial port and read by my Mac.

Connect Arduino Pin 13 for the counter clock pulse to the 74HC4040. Pin 12 resets the counter to 0. The counter output is feed to the address lines of the EPROM , here it is a 27C256 (32K byte EPROM). With the CE and OE enabled , the data is read into Pin 2 to 9 of the Arduino.

Here is the source code I wrote:

/*
EPROM reader with two 74HC4040
by Ian PUN MD July 24, 2016
*/

int clockpulse = 13;
int masterreset = 12;
int button = 10; // pin 10 for start button
int val = 0;
int readbyte = 0;
int Q = 0;


const long SIZEofROM = 65536;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(clockpulse, OUTPUT);
pinMode(masterreset, OUTPUT);
pinMode(button, INPUT);
digitalWrite(clockpulse, LOW);
digitalWrite(masterreset, HIGH); // reset the counter
digitalWrite(masterreset, LOW);
for(int Q = 2; Q < 10; Q++)
{pinMode(Q, INPUT);} //set pins for for the byte data input

Serial.begin(57600); // open the serial port at 9600 bps: D7000D ED12-6
}

// the loop routine runs over and over again forever:
void loop() {

while (digitalRead(button) == 1){} // wait for button

digitalWrite(masterreset, HIGH); // reset the counter SIZEofROM
digitalWrite(masterreset, LOW);
for (long x = 0; x < SIZEofROM; x++ ) {
digitalWrite(clockpulse, HIGH); // pulse the 74HC4040
digitalWrite(clockpulse, LOW); // pulse the 74HC4040

if (x % 8 == 0) {
print_hex(x,16);
Serial.print(":");
}

readbyte = 0;
Q = 9;
while(Q >= 2){
readbyte = (readbyte << 1) | digitalRead(Q); // shift bit over and bit wise OR with read bit
Q--;
}
Serial.print(" ");
print_hex(readbyte,8);

//Serial.write(readbyte);

if (x % 8 == 7) {
Serial.println("");
}


}



Serial.println("Again");

Serial.println(" ");

for(int Q = 9; Q >= 2; Q--)
{
Serial.print(digitalRead(Q));
delay (1);
}


Serial.println(" ");

digitalWrite(clockpulse, LOW);
delay (500);
digitalWrite(clockpulse, HIGH);
delay (2000);
digitalWrite(clockpulse, LOW);





}


void print_hex(int v, int num_places)
{
int mask=0, n, num_nibbles, digit;

for (n=1; n<=num_places; n++)
{
mask = (mask << 1) | 0x0001;
}
v = v & mask; // truncate v to specified number of places

num_nibbles = num_places / 4;
if ((num_places % 4) != 0)
{
++num_nibbles;
}

do
{
digit = ((v >> (num_nibbles-1) * 4)) & 0x0f;
Serial.print(digit, HEX);
} while(--num_nibbles);

}