int q_pins[] = {21, 19, 18, 5 , 17 , 16 , 4, 2};
#define ENABLE 26 // Enable pin
#define DS 25 // Serial Data
#define STCP 33 // Serial Clock
#define SHCP 32 // Storage Latch
int8_t get_memory(uint16_t address) {
// Set the address to be accessed, into
// the shift register
uint8_t low = address & 0xff;
uint8_t high = (address >> 8);
digitalWrite(SHCP, LOW);
shiftOut(DS, STCP, MSBFIRST, high);
shiftOut(DS, STCP, MSBFIRST, low);
digitalWrite(SHCP, HIGH);
// Set the chip enable to low, and read
// the data lines, and then set the chip
// enable high again
digitalWrite(ENABLE, LOW);
uint8_t byte = 0;
for (int i = 0; i < 8; i++) {
uint8_t bit = digitalRead(q_pins[i]);
if (bit == HIGH) {
byte = (byte >> 1) | 0x80;
}
else {
byte = byte >> 1;
}
}
digitalWrite(ENABLE, HIGH);
// Return the byte
return byte;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(DS, OUTPUT); // Serial data pin
pinMode(ENABLE, OUTPUT); // Chip enable pin
pinMode(STCP, OUTPUT); // Shift register clock
pinMode(SHCP, OUTPUT); // Shift register output latch
// Set enable to high, so no chip is selected
digitalWrite(ENABLE, HIGH);
// Set the data lines to input
for (int i = 0; i < 8; i++) {
pinMode(q_pins[i], INPUT);
}
uint8_t byte = 0;
// Read the first 32 bytes from the first chip
Serial.println("Dump data of 64 bytes from the first EPROM chip.");
for (int i = 0; i < 64; i++) {
byte = get_memory(i);
Serial.print("Memory: ");
Serial.print(i);
Serial.print(" - Byte: ");
Serial.println(byte);
}
// Read the first 32 bytes from the second chip
Serial.println("Dump data of 64 bytes from the second EPROM chip.");
for (int i = 0; i < 64; i++) {
byte = get_memory(i+2048);
Serial.print("Memory: ");
Serial.print(i+2048);
Serial.print(" - Byte: ");
Serial.println(byte);
}
// Dump string from the first EPROM chip
unsigned long pos = 0;
while ((byte = get_memory(pos)) != 0) {
Serial.print((char)byte);
pos++;
}
Serial.println("");
// Dump string from the second EPROM chip
pos = 2048;
while ((byte = get_memory(pos)) != 0) {
Serial.print((char)byte);
pos++;
}
Serial.println("");
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}