When programming AT28c16 it returns all "02" in the field area

I have built a EEPROM Programmer using instructions and code from Ben Eater. On the surface it seems to function but when I execute the serial monitor the field is just all " 02's". Two sets of 8 across left to right. And cascade downward from 00 to 0xf. This project may be outside of my knowledge skill set. My best guess is the eeprom is bad. I would post a view of the serial monitor but when I attempt it comes in very large. Sorry. Any comments might be helpful. Thanks

Here is the code I used:

#define SHIFT_DATA 2
#define SHIFT_CLK 3
#define SHIFT_LATCH 4
#define EEPROM_D0 5
#define EEPROM_D7 12
#define WRITE_EN 13

/*
   Output the address bits and outputEnable signal using shift registers.
*/
void setAddress(int address, bool outputEnable) {
  shiftOut(SHIFT_DATA, SHIFT_CLK, MSBFIRST, (address >> 8) | (outputEnable ? 0x00 : 0x80));
  shiftOut(SHIFT_DATA, SHIFT_CLK, MSBFIRST, address);

  digitalWrite(SHIFT_LATCH, LOW);
  digitalWrite(SHIFT_LATCH, HIGH);
  digitalWrite(SHIFT_LATCH, LOW);
}


/*
   Read a byte from the EEPROM at the specified address.
*/
byte readEEPROM(int address) {
  for (int pin = EEPROM_D0; pin <= EEPROM_D7; pin += 1) {
    pinMode(pin, INPUT);
  }
  setAddress(address, /*outputEnable*/ true);

  byte data = 0;
  for (int pin = EEPROM_D7; pin >= EEPROM_D0; pin -= 1) {
    data = (data << 1) + digitalRead(pin);
  }
  return data;
}


/*
   Write a byte to the EEPROM at the specified address.
*/
void writeEEPROM(int address, byte data) {
  setAddress(address, /*outputEnable*/ false);
  for (int pin = EEPROM_D0; pin <= EEPROM_D7; pin += 1) {
    pinMode(pin, OUTPUT);
  }

  for (int pin = EEPROM_D0; pin <= EEPROM_D7; pin += 1) {
    digitalWrite(pin, data & 1);
    data = data >> 1;
  }
  digitalWrite(WRITE_EN, LOW);
  delayMicroseconds(1);
  digitalWrite(WRITE_EN, HIGH);
  delay(10);
}


/*
   Read the contents of the EEPROM and print them to the serial monitor.
*/
void printContents() {
  for (int base = 0; base <= 255; base += 16) {
    byte data[16];
    for (int offset = 0; offset <= 15; offset += 1) {
      data[offset] = readEEPROM(base + offset);
    }

    char buf[80];
    sprintf(buf, "%03x:  %02x %02x %02x %02x %02x %02x %02x %02x   %02x %02x %02x %02x %02x %02x %02x %02x",
            base, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7],
            data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15]);

    Serial.println(buf);
  }
}


// 4-bit hex decoder for common anode 7-segment display
byte data[] = { 0x81, 0xcf, 0x92, 0x86, 0xcc, 0xa4, 0xa0, 0x8f, 0x80, 0x84, 0x88, 0xe0, 0xb1, 0xc2, 0xb0, 0xb8 };

// 4-bit hex decoder for common cathode 7-segment display
// byte data[] = { 0x7e, 0x30, 0x6d, 0x79, 0x33, 0x5b, 0x5f, 0x70, 0x7f, 0x7b, 0x77, 0x1f, 0x4e, 0x3d, 0x4f, 0x47 };


void setup() {
  // put your setup code here, to run once:
  pinMode(SHIFT_DATA, OUTPUT);
  pinMode(SHIFT_CLK, OUTPUT);
  pinMode(SHIFT_LATCH, OUTPUT);
  digitalWrite(WRITE_EN, HIGH);
  pinMode(WRITE_EN, OUTPUT);
  Serial.begin(9600);

  // Erase entire EEPROM
  Serial.print("Erasing EEPROM");
  for (int address = 0; address <= 2047; address += 1) {
    writeEEPROM(address, 0xff);

    if (address % 64 == 0) {
      Serial.print(".");
    }
  }
  Serial.println(" done");


  // Program data bytes
  Serial.print("Programming EEPROM");
  for (int address = 0; address < sizeof(data); address += 1) {
    writeEEPROM(address, data[address]);

    if (address % 64 == 0) {
      Serial.print(".");
    }
  }
  Serial.println(" done");


  // Read and print out the contents of the EERPROM
  Serial.println("Reading EEPROM");
  printContents();
}


void loop() {
  // put your main code here, to run repeatedly:

}

Here is the serial monitor read out:

Erasing EEPROM................................ done
Programming EEPROM. done
Reading EEPROM
000: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
010: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
020: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
030: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
040: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
050: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
060: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
070: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
080: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
090: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
0a0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
0b0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
0c0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
0d0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
0e0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
0f0: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02

Here is a pic of the build:

Much more likely that your code and/or wiring is at fault.

For informed help, post the details, following the instructions in the "How to get the best out of this forum" post.

Be sure to post your code and your wiring, rather than point people to some web site or youtube channel.

Your code still not included in correct code tags. Please read the forum guidelines How to get the best out of this forum
especially the section "Code problems" and edit your message again.

Please edit your posts to add code tags.

Keep in mind that breadboards are intended for temporary experiments and are quite unreliable.

The symptoms you describe could be due to a bad or misplaced contact on the address bus, for example.

Also, many breadboards have discontinuous power connections across the top and bottom tracks, and need to be bridged with wires. If you don't, a chip can be powered through an input pin, leading to unexpected results and possibly damaging the chip, the Arduino, or both.

DOUBLE check all wiring and connections for correctness and continuity, using your multimeter.

I have taking your advise and did a continuity test on all wiring connections making sure to check from nano pin to either register pin or eeprom. Still no change. If possible and I get it to run differently what should that look like? Also, where in the code do you make changes to program the eeprom to have a different outcome. As I mentioned in my original post, maybe this project is a beyond my capabilities. But if you can just take the moment to bring me up to speed, it would be greatly appreciated. And sorry for not reading about how to post a question properly! Thanks for your time.

I wonder why this code does not enable the output line.

To debug the hardware you probably need a logic analyzer. This one is all you need to monitor whether address lines and read/write signals are being set properly. Available everywhere.

Just a quick update. I have a 8 channel logic analyzer coming from China. Won't get it till after the first of the year. I have downloaded the control software Pulseview and I have watched several video's and read many articles. I might contact you back for any help I might need. Again thanks for all of your help. This new device will help me make clear decisions. Best Regards.

You should have fun. That combination of logic analyzer and PulseView works really well, and is absolutely invaluable for tasks like this.

Hello. Please review the attached snip-it from Pulseview and the Arduino sketch I created for the test. Unfortunately the new analyzer is only reading 6 of 8 channels. Let me know if any of it makes sense. I can see that it is counting off binary numbers, but still not sure if that confirms anything. As always your assistance is much appreciated!

Just made this edit to include test on ic with Arduino disconnected. Please help me make sense of it. Thanks

//Digital Pin Test

///Created April 14, 2015




void setup() {
  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  
  
}


void loop() {
  digitalWrite(0, HIGH);  
  delay(1000);              
  digitalWrite(0, LOW);    
  delay(1000); 
  digitalWrite(1, HIGH);  
  delay(1000);              
  digitalWrite(1, LOW);    
  delay(1000);
  digitalWrite(2, HIGH);  
  delay(1000);              
  digitalWrite(2, LOW);    
  delay(1000); 
  digitalWrite(3, HIGH);  
  delay(1000);              
  digitalWrite(3, LOW);    
  delay(1000);
  digitalWrite(4, HIGH);  
  delay(1000);              
  digitalWrite(4, LOW);    
  delay(1000); 
  digitalWrite(5, HIGH);  
  delay(1000);              
  digitalWrite(5, LOW);    
  delay(1000); 
  digitalWrite(6, HIGH);  
  delay(1000);              
  digitalWrite(6, LOW);    
  delay(1000); 
  digitalWrite(7, HIGH);  
  delay(1000);              
  digitalWrite(7, LOW);    
  delay(1000); 
  
 
 digitalWrite(0, HIGH);
 digitalWrite(1, HIGH);
 digitalWrite(2, HIGH);
 digitalWrite(3, HIGH);
 digitalWrite(4, HIGH);
 digitalWrite(5, HIGH);
 digitalWrite(6, HIGH);
 digitalWrite(7, HIGH);

 delay(2000);

 digitalWrite(0, LOW);
 digitalWrite(1, LOW);
 digitalWrite(2, LOW);
 digitalWrite(3, LOW);
 digitalWrite(4, LOW);
 digitalWrite(5, LOW);
 digitalWrite(6, LOW);
 digitalWrite(7, LOW);
 

  
}

The probe shows digital outputs presenting HIGH and LOW, presumably as programmed.

What is connected to what, and what do the two different screenshots represent?

I knew I would leave off something. The first snip-it , the at28c16 chip is attached to the arduino using pins 2 thru 7 . I sent the sketch to arduino. I also had the analyzer attached to I/O pins D0 thru D5 of the ic chip. The second snip-it is the analyzer attached only to I/O pins on chip. I think that the fact it produced a recognized high and low signal could mean the chip is functioning. But still not sure.

Just an update. I want to start by saying, "Thank you very much". I purchased a new logic analyzer. Made necessary check while connected to Arduino Uno. Results where positive. I then found an other sketch with instructions for connection to AT28c16. Attached is the sketch and snip-it of analyzer results. I have since ordered another AT28c16 and will compare results. This has been a really good education and I look forward to greater discoveries. Again many thanks for your time.

// Arduino Uno Programmer for AT28 EEPROM
// Chris Torrence, 2015
// ideas from:  http://forum.6502.org/viewtopic.php?f=4&t=2491
//

#define SER_Pin   A4  // 75HC595 pin 14, serial input
#define STCP_Pin  A2  // 75HC595 pin 12, STCP storage register clock
#define SHCP_Pin  A1  // 75HC595 pin 11, SHCP shift register clock

#define AT28_CE_Pin  10  // AT28C64 WE, write enable
#define AT28_WE_Pin  11  // AT28 WE, write enable
#define AT28_OE_Pin  12  // AT28 OE, output enable

#define numOfRegisterPins 11   // 2^11 = 2048 address locations
#define ADDRESS_MAX (1 << numOfRegisterPins)

// Fast way of setting/reading/writing pins on the Arduino
// http://masteringarduino.blogspot.com/2013_10_01_archive.html
#define portOfPin(P)\
  (((P)>=0&&(P)<8)?&PORTD:(((P)>7&&(P)<14)?&PORTB:&PORTC))
#define pinOfPin(P)\
  (((P)>=0&&(P)<8)?&PIND:(((P)>7&&(P)<14)?&PINB:&PINC))
#define pinIndex(P) ((uint8_t)(P>13?P-14:P&7))
#define pinMask(P)  ((uint8_t)(1<<pinIndex(P)))
#define digitalLow(P)  *(portOfPin(P))&=~pinMask(P)
#define digitalHigh(P) *(portOfPin(P))|=pinMask(P)
#define isHigh(P) ((*(pinOfPin(P))& pinMask(P))>0)
#define isLow(P)  ((*(pinOfPin(P))& pinMask(P))==0)


// Data to be written to the AT28.
// Use PROGMEM to put into Arduino flash memory
const char values[2048] PROGMEM = {
 28, 34, 42, 42, 44, 32, 30,  0,  8, 20, 34, 34, 62, 34, 34,  0, 60, 34, 34, 60, 34, 34, 60,  0, 28, 34, 32, 32, 32, 34, 28,  0,
 60, 34, 34, 34, 34, 34, 60,  0, 62, 32, 32, 60, 32, 32, 62,  0, 62, 32, 32, 60, 32, 32, 32,  0, 30, 32, 32, 38, 34, 34, 30,  0,
 34, 34, 34, 62, 34, 34, 34,  0, 28,  8,  8,  8,  8,  8, 28,  0,  2,  2,  2,  2,  2, 34, 28,  0, 34, 36, 40, 48, 40, 36, 34,  0,
 32, 32, 32, 32, 32, 32, 62,  0, 34, 54, 42, 42, 34, 34, 34,  0, 34, 34, 50, 42, 38, 34, 34,  0, 28, 34, 34, 34, 34, 34, 28,  0,
 60, 34, 34, 60, 32, 32, 32,  0, 28, 34, 34, 34, 42, 36, 26,  0, 60, 34, 34, 60, 40, 36, 34,  0, 28, 34, 32, 28,  2, 34, 28,  0,
 62,  8,  8,  8,  8,  8,  8,  0, 34, 34, 34, 34, 34, 34, 28,  0, 34, 34, 34, 34, 34, 20,  8,  0, 34, 34, 34, 42, 42, 54, 34,  0,
 34, 34, 20,  8, 20, 34, 34,  0, 34, 34, 20,  8,  8,  8,  8,  0, 62,  2,  4,  8, 16, 32, 62,  0, 62, 48, 48, 48, 48, 48, 62,  0,
  0, 32, 16,  8,  4,  2,  0,  0, 62,  6,  6,  6,  6,  6, 62,  0,  8, 20, 34,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 62,  0,
  0,  0,  0,  0,  0,  0,  0,  0,  8,  8,  8,  8,  8,  0,  8,  0, 20, 20, 20,  0,  0,  0,  0,  0, 20, 20, 62, 20, 62, 20, 20,  0,
  8, 30, 40, 28, 10, 60,  8,  0, 50, 50,  4,  8, 16, 38, 38,  0, 24, 36, 40, 16, 42, 36, 26,  0,  8,  8,  8,  0,  0,  0,  0,  0,
  8, 16, 32, 32, 32, 16,  8,  0,  8,  4,  2,  2,  2,  4,  8,  0,  8, 42, 28,  8, 28, 42,  8,  0,  0,  8,  8, 62,  8,  8,  0,  0,
  0,  0,  0,  0,  0, 24,  8, 16,  0,  0,  0, 28,  0,  0,  0,  0,  0,  0,  0,  0,  0, 24, 24,  0,  0,  2,  4,  8, 16, 32,  0,  0,
 28, 34, 38, 42, 50, 34, 28,  0,  8, 24,  8,  8,  8,  8, 28,  0, 28, 34,  2, 12, 16, 32, 62,  0, 62,  2,  4, 12,  2, 34, 28,  0,
  4, 12, 20, 36, 62,  4,  4,  0, 62, 32, 60,  2,  2, 34, 28,  0, 14, 16, 32, 60, 34, 34, 28,  0, 62,  2,  4,  8, 16, 16, 16,  0,
 28, 34, 34, 28, 34, 34, 28,  0, 28, 34, 34, 30,  2,  4, 56,  0,  0,  0, 24, 24,  0, 24, 24,  0,  0,  0, 24, 24,  0, 24,  8, 16,
  4,  8, 16, 32, 16,  8,  4,  0,  0,  0, 60,  0, 60,  0,  0,  0, 16,  8,  4,  2,  4,  8, 16,  0, 28, 34,  4,  8,  8,  0,  8,  0,
156,162,170,170,172,160,158,128,136,148,162,162,190,162,162,128,188,162,162,188,162,162,188,128,156,162,160,160,160,162,156,128,
188,162,162,162,162,162,188,128,190,160,160,188,160,160,190,128,190,160,160,188,160,160,160,128,158,160,160,166,162,162,158,128,
162,162,162,190,162,162,162,128,156,136,136,136,136,136,156,128,130,130,130,130,130,162,156,128,162,164,168,176,168,164,162,128,
160,160,160,160,160,160,190,128,162,182,170,170,162,162,162,128,162,162,178,170,166,162,162,128,156,162,162,162,162,162,156,128,
188,162,162,188,160,160,160,128,156,162,162,162,170,164,154,128,188,162,162,188,168,164,162,128,156,162,160,156,130,162,156,128,
190,136,136,136,136,136,136,128,162,162,162,162,162,162,156,128,162,162,162,162,162,148,136,128,162,162,162,170,170,182,162,128,
162,162,148,136,148,162,162,128,162,162,148,136,136,136,136,128,190,130,132,136,144,160,190,128,190,176,176,176,176,176,190,128,
128,160,144,136,132,130,128,128,190,134,134,134,134,134,190,128,136,148,162,128,128,128,128,128,128,128,128,128,128,128,190,128,
128,128,128,128,128,128,128,128,136,136,136,136,136,128,136,128,148,148,148,128,128,128,128,128,148,148,190,148,190,148,148,128,
136,158,168,156,138,188,136,128,178,178,132,136,144,166,166,128,152,164,168,144,170,164,154,128,136,136,136,128,128,128,128,128,
136,144,160,160,160,144,136,128,136,132,130,130,130,132,136,128,136,170,156,136,156,170,136,128,128,136,136,190,136,136,128,128,
128,128,128,128,128,152,136,144,128,128,128,156,128,128,128,128,128,128,128,128,128,152,152,128,128,130,132,136,144,160,128,128,
156,162,166,170,178,162,156,128,136,152,136,136,136,136,156,128,156,162,130,140,144,160,190,128,190,130,132,140,130,162,156,128,
132,140,148,164,190,132,132,128,190,160,188,130,130,162,156,128,142,144,160,188,162,162,156,128,190,130,132,136,144,144,144,128,
156,162,162,156,162,162,156,128,156,162,162,158,130,132,184,128,128,128,152,152,128,152,152,128,128,128,152,152,128,152,136,144,
132,136,144,160,144,136,132,128,128,128,188,128,188,128,128,128,144,136,132,130,132,136,144,128,156,162,132,136,136,128,136,128,
 28, 34, 42, 42, 44, 32, 30,  0,  8, 20, 34, 34, 62, 34, 34,  0, 60, 34, 34, 60, 34, 34, 60,  0, 28, 34, 32, 32, 32, 34, 28,  0,
 60, 34, 34, 34, 34, 34, 60,  0, 62, 32, 32, 60, 32, 32, 62,  0, 62, 32, 32, 60, 32, 32, 32,  0, 30, 32, 32, 38, 34, 34, 30,  0,
 34, 34, 34, 62, 34, 34, 34,  0, 28,  8,  8,  8,  8,  8, 28,  0,  2,  2,  2,  2,  2, 34, 28,  0, 34, 36, 40, 48, 40, 36, 34,  0,
 32, 32, 32, 32, 32, 32, 62,  0, 34, 54, 42, 42, 34, 34, 34,  0, 34, 34, 50, 42, 38, 34, 34,  0, 28, 34, 34, 34, 34, 34, 28,  0,
 60, 34, 34, 60, 32, 32, 32,  0, 28, 34, 34, 34, 42, 36, 26,  0, 60, 34, 34, 60, 40, 36, 34,  0, 28, 34, 32, 28,  2, 34, 28,  0,
 62,  8,  8,  8,  8,  8,  8,  0, 34, 34, 34, 34, 34, 34, 28,  0, 34, 34, 34, 34, 34, 20,  8,  0, 34, 34, 34, 42, 42, 54, 34,  0,
 34, 34, 20,  8, 20, 34, 34,  0, 34, 34, 20,  8,  8,  8,  8,  0, 62,  2,  4,  8, 16, 32, 62,  0, 62, 48, 48, 48, 48, 48, 62,  0,
  0, 32, 16,  8,  4,  2,  0,  0, 62,  6,  6,  6,  6,  6, 62,  0,  8, 20, 34,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 62,  0,
  0,  0,  0,  0,  0,  0,  0,  0,  8,  8,  8,  8,  8,  0,  8,  0, 20, 20, 20,  0,  0,  0,  0,  0, 20, 20, 62, 20, 62, 20, 20,  0,
  8, 30, 40, 28, 10, 60,  8,  0, 50, 50,  4,  8, 16, 38, 38,  0, 24, 36, 40, 16, 42, 36, 26,  0,  8,  8,  8,  0,  0,  0,  0,  0,
  8, 16, 32, 32, 32, 16,  8,  0,  8,  4,  2,  2,  2,  4,  8,  0,  8, 42, 28,  8, 28, 42,  8,  0,  0,  8,  8, 62,  8,  8,  0,  0,
  0,  0,  0,  0,  0, 24,  8, 16,  0,  0,  0, 28,  0,  0,  0,  0,  0,  0,  0,  0,  0, 24, 24,  0,  0,  2,  4,  8, 16, 32,  0,  0,
 28, 34, 38, 42, 50, 34, 28,  0,  8, 24,  8,  8,  8,  8, 28,  0, 28, 34,  2, 12, 16, 32, 62,  0, 62,  2,  4, 12,  2, 34, 28,  0,
  4, 12, 20, 36, 62,  4,  4,  0, 62, 32, 60,  2,  2, 34, 28,  0, 14, 16, 32, 60, 34, 34, 28,  0, 62,  2,  4,  8, 16, 16, 16,  0,
 28, 34, 34, 28, 34, 34, 28,  0, 28, 34, 34, 30,  2,  4, 56,  0,  0,  0, 24, 24,  0, 24, 24,  0,  0,  0, 24, 24,  0, 24,  8, 16,
  4,  8, 16, 32, 16,  8,  4,  0,  0,  0, 60,  0, 60,  0,  0,  0, 16,  8,  4,  2,  4,  8, 16,  0, 28, 34,  4,  8,  8,  0,  8,  0,
 28, 34, 42, 42, 44, 32, 30,  0,  8, 20, 34, 34, 62, 34, 34,  0, 60, 34, 34, 60, 34, 34, 60,  0, 28, 34, 32, 32, 32, 34, 28,  0,
 60, 34, 34, 34, 34, 34, 60,  0, 62, 32, 32, 60, 32, 32, 62,  0, 62, 32, 32, 60, 32, 32, 32,  0, 30, 32, 32, 38, 34, 34, 30,  0,
 34, 34, 34, 62, 34, 34, 34,  0, 28,  8,  8,  8,  8,  8, 28,  0,  2,  2,  2,  2,  2, 34, 28,  0, 34, 36, 40, 48, 40, 36, 34,  0,
 32, 32, 32, 32, 32, 32, 62,  0, 34, 54, 42, 42, 34, 34, 34,  0, 34, 34, 50, 42, 38, 34, 34,  0, 28, 34, 34, 34, 34, 34, 28,  0,
 60, 34, 34, 60, 32, 32, 32,  0, 28, 34, 34, 34, 42, 36, 26,  0, 60, 34, 34, 60, 40, 36, 34,  0, 28, 34, 32, 28,  2, 34, 28,  0,
 62,  8,  8,  8,  8,  8,  8,  0, 34, 34, 34, 34, 34, 34, 28,  0, 34, 34, 34, 34, 34, 20,  8,  0, 34, 34, 34, 42, 42, 54, 34,  0,
 34, 34, 20,  8, 20, 34, 34,  0, 34, 34, 20,  8,  8,  8,  8,  0, 62,  2,  4,  8, 16, 32, 62,  0, 62, 48, 48, 48, 48, 48, 62,  0,
  0, 32, 16,  8,  4,  2,  0,  0, 62,  6,  6,  6,  6,  6, 62,  0,  8, 20, 34,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 62,  0,
 32, 16,  8,  0,  0,  0,  0,  0,  0,  0, 28,  2, 30, 34, 30,  0, 32, 32, 44, 50, 34, 50, 44,  0,  0,  0, 30, 32, 32, 32, 30,  0,
  2,  2, 26, 38, 34, 38, 26,  0,  0,  0, 28, 34, 62, 32, 28,  0, 12, 18, 16, 56, 16, 16, 16,  0,  0,  2, 28, 34, 34, 30,  2, 28,
 32, 32, 44, 50, 34, 34, 34,  0,  8,  0, 24,  8,  8,  8, 28,  0,  4,  0, 12,  4,  4,  4, 36, 24, 32, 32, 34, 36, 56, 36, 34,  0,
 24,  8,  8,  8,  8,  8, 28,  0,  0,  0, 52, 42, 42, 42, 42,  0,  0,  0, 44, 50, 34, 34, 34,  0,  0,  0, 28, 34, 34, 34, 28,  0,
  0,  0, 44, 50, 50, 44, 32, 32,  0,  0, 26, 38, 38, 26,  2,  2,  0,  0, 44, 48, 32, 32, 32,  0,  0,  0, 30, 32, 28,  2, 60,  0,
 16, 16, 56, 16, 16, 18, 12,  0,  0,  0, 34, 34, 34, 38, 26,  0,  0,  0, 34, 34, 34, 20,  8,  0,  0,  0, 34, 42, 42, 42, 20,  0,
  0,  0, 34, 20,  8, 20, 34,  0,  0,  0, 34, 34, 38, 26,  2, 28,  0,  0, 62,  4,  8, 16, 62,  0,  6,  8,  8, 48,  8,  8,  6,  0,
  8,  8,  8,  0,  8,  8,  8,  0, 48,  8,  8,  6,  8,  8, 48,  0,  0,  0, 16, 42,  4,  0,  0,  0, 42, 20, 42, 20, 42, 20, 42,  0};


// Procedure to set and display registers:
//   STCP low
//   For each address bit (high to low): SHCP low, write bit, SHCP high
//   STCP high to transfer to the storage register (and the output)
//
void writeShiftRegister(long val)
{
  digitalWrite(STCP_Pin, LOW);

  // From highest bit to lowest bit
  for(int i = 15; i >=  0; i--)
  {
    digitalWrite(SHCP_Pin, LOW);
    digitalWrite(SER_Pin, (val >> i) & 1);  // Write the next highest bit
    digitalWrite(SHCP_Pin, HIGH);  // Left shift the register 1 bit

  }
  digitalWrite(STCP_Pin, HIGH);
}


// Light up the LEDs using each valid address
void testShiftRegister()
{
  // Just light up the LEDs in order.
  writeShiftRegister(0);
  delay(200);
  for (int i=0; i < numOfRegisterPins; i++)
  {
    writeShiftRegister(1 << i);
    delay(100);
  }
  // Light them all up, then turn them off.
  writeShiftRegister(2047);
  delay(100);
  writeShiftRegister(0);
}


void printValue(int address, byte value)
{
  if (address % 32 == 0)
  {
    Serial.println("");
    Serial.print("$");
    if (address < 256) Serial.print("0");
    if (address < 16) Serial.print("0");
    Serial.print(address, HEX);
    Serial.print(":");
  }

  Serial.print(" ");
  if (value < 16) Serial.print("0");
  Serial.print(value, HEX);
}


// Procedure to write to the AT28:
//   Set OE and WE high
//   For each address, write the address and data, then pulse WE low
void writeEEPROM()
{
  Serial.println("");
  Serial.println("***** WRITE *****");
  digitalWrite(AT28_CE_Pin, LOW);
  digitalWrite(AT28_OE_Pin, HIGH);

  // Set the data pins for output
  for (int i=2; i <= 9; i++) pinMode(i, OUTPUT);

  for (int address=0; address < ADDRESS_MAX; address++)
  {
    byte value = pgm_read_byte_near(values + address);
    printValue(address, value);

    writeShiftRegister(address);

    // the (i + 2) translates from bit # to pin #
    for (int i=0; i <= 7; i++) {
      digitalWrite(i + 2, (value & (1 << i)) ? HIGH : LOW);
    }

    // Send a pulse to the AT28 to write the data
    digitalLow(AT28_WE_Pin);
    digitalHigh(AT28_WE_Pin);
    delay(10);
  }
}


// Procedure to read from the AT28:
//   Set OE low and WE high
//   For each address, write the address, then read the data
void readEEPROM()
{
  Serial.println("");
  Serial.println("***** READ *****");
  // Now read each address value and print out.
  // Set the AT28 for "READ", WE high, OE low
  // Set the data pins for input
  digitalWrite(AT28_CE_Pin, LOW);
  digitalWrite(AT28_WE_Pin, HIGH);
  digitalWrite(AT28_OE_Pin, LOW);
  for (int i=2; i <= 9; i++) pinMode(i, INPUT);

  for (int address=0; address < ADDRESS_MAX; address++)
  {
    writeShiftRegister(address);
    int value = 0;
    // the (i + 2) translates from bit # to pin #
    for (int i=0; i <= 7; i++) {
      if (digitalRead(i + 2)) value += (1 << i);
    }

    printValue(address, value);
  }

  Serial.println("");
}


void setup()
{
  Serial.begin(9600);

  pinMode(SER_Pin, OUTPUT);
  pinMode(STCP_Pin, OUTPUT);
  pinMode(SHCP_Pin, OUTPUT);

  pinMode(AT28_CE_Pin, OUTPUT);
  pinMode(AT28_WE_Pin, OUTPUT);
  pinMode(AT28_OE_Pin, OUTPUT);

  // Disable the AT28
  digitalWrite(AT28_CE_Pin, HIGH);
  digitalWrite(AT28_WE_Pin, HIGH);
  digitalWrite(AT28_OE_Pin, HIGH);

  for (int i=2; i <= 9; i++) pinMode(i, INPUT);

  Serial.println("***** TESTING *****");
  testShiftRegister();

  // Wait until user hits return.
  Serial.println("***** Hit <RETURN> to start WRITE/READ *****");
  while (Serial.available() == 0) {};
  Serial.read();

  writeEEPROM();
  readEEPROM();
}


void loop()
{
  // Do nothing
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.