Hello, I a beginner and trying to program a 2864 type parallel EEPROM. I want to write simple data to 2 locations in parallel EEPROM memory. After writing, I want to read this data and display it on the serial monitor. Unfortunately, the serial monitor displays both locations as the same data "2" - not as "1" and "2". Where is the mistake? I use Arduino Mega board.
Thanks Jurek
#define CS 2
#define OE 3
#define WE 4
#define IO PORTC
#define AD0 5
#define AD1 6
#define AD2 7
#define AD3 8
#define AD4 9
#define AD5 10
#define AD6 11
#define AD7 12
#define AD8 13
#define AD9 22
#define AD10 23
#define AD11 24
#define AD12 25
void setup() {
// put your setup code here, to run once:
// Configure control pins
pinMode(CS, OUTPUT);
pinMode(WE, OUTPUT);
pinMode(OE, OUTPUT);
digitalWrite(OE, HIGH);
digitalWrite(WE, HIGH);
digitalWrite(CS, HIGH);
// Configure data pins
DDRC = 0x00;
// Configure address pins
pinMode(AD0, OUTPUT);
pinMode(AD1, OUTPUT);
// Set remaining address pins to LOW
for(int i=AD2; i<=AD12; i++) {
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
}
// Initialize serial communication
Serial.begin(9600);
}
void loop() {
// **************************************************
// Write data 0b1 (1) to data location 1
// **************************************************
// Configure the control pins
digitalWrite(OE, HIGH);
digitalWrite(WE, HIGH);
digitalWrite(CS, LOW);
// Set our data on the IO port and configure IO as output
DDRC = 0xFF;
IO = 0b1;
// Set the address pins
digitalWrite(AD0, HIGH);
digitalWrite(AD1, LOW);
// Perform the cycle
digitalWrite(WE, LOW);
delay(5);
digitalWrite(WE, HIGH);
digitalWrite(CS, HIGH);
// **************************************************
// Write data 0b10 (2) to data location 3
// **************************************************
// Configure the control pins
digitalWrite(OE, HIGH);
digitalWrite(WE, HIGH);
digitalWrite(CS, LOW);
// Set our data on the IO port and configure IO as output
DDRC = 0xFF;
IO = 0b10;
// Set the address pins
digitalWrite(AD0, HIGH);
digitalWrite(AD1, HIGH);
// Perform the cycle
digitalWrite(WE, LOW);
delay(5);
digitalWrite(WE, HIGH);
digitalWrite(CS, HIGH);
// **************************************************
// Read data from data location 1
// **************************************************
// Configure the control pins
digitalWrite(OE, HIGH);
digitalWrite(WE, HIGH);
digitalWrite(CS, LOW);
// Configure data as input
DDRC = 0x00;
// Set the address pins
digitalWrite(AD0, HIGH);
digitalWrite(AD1, LOW);
// Perform the read cycle
digitalWrite(OE, LOW);
delay(5);
unsigned char data1 = PORTC;
digitalWrite(OE, HIGH);
digitalWrite(CS, HIGH);
// Print the read data
Serial.print("Data read from memory location 1: ");
Serial.println(data1, HEX);
delay(1000); // Add a delay so the output is more readable
// **************************************************
// Read data from data location 3
// **************************************************
// Configure the control pins
digitalWrite(OE, HIGH);
digitalWrite(WE, HIGH);
digitalWrite(CS, LOW);
// Configure data as input
DDRC = 0x00;
// Set the address pins
digitalWrite(AD0, HIGH);
digitalWrite(AD1, HIGH);
// Perform the read cycle
digitalWrite(OE, LOW);
delay(5);
unsigned char data3 = PORTC;
digitalWrite(OE, HIGH);
digitalWrite(CS, HIGH);
// Print the read data
Serial.print("Data read from memory location 3: ");
Serial.println(data3, HEX);
delay(1000); // Add a delay so the output is more readable
}



