Code from the main program calling the function:
WRITE AA
TO X555
edata = read_eeprom(eaddr, ce_master);
Figure 2.
Read EEPROM function definition.
Function name
WRITE 55
TO XAAA
Read Function:
Parameters passed from calling
program – EEPROM address and
chip to read from (Master or Slave)
byte read_eeprom (int address, byte ce)
{
WRITE A0
TO X555
byte fdata;
// Code to address chip and request a read omitted for simplicity
fdata = PINA;
Type of data returned by
function. “Void” if no data
returned
PERFORM
BYTE OR
PAGE WRITE
OPERATIONS
return fdata;
}
Figure 3.
Write sequence
required by the
X88C64.
work. I then considered reading 4K
into an array and swapping the
chips twice to complete the copy.
Since we only had two good
EEPROMs remaining, I didn’t want to take a chance of
accidentally overwriting a working chip. I settled on a
design that had two ZIF sockets: one for the working
EEPROM (Master) and one for the blank EEPROM (Slave).
I could then read and write on a byte-by-byte basis and
not require RAM storage in the Mega. This also would
allow me to scale up to any size EEPROM. The downside
was more involved wiring on the breadboard.
Direct Port I/O
The digital Write Arduino command is actually setting
Read data from Port A into the
fdata variable
Value returned to the
calling program
one bit in an eight-bit register. The ATmega1280 CPU
used in the Mega has 11 registers designated PORTA
through PORTL (PORTI is not defined) of which 54 digital
bits are brought out to connectors on the Mega board.
[See the ATmega 1280 datasheet section 13 (in Links) for
more details.] For my programmer, I need to control all 13
address bits and read or write eight data bits, so setting
bits one at a time would be quite inefficient. Also, it takes
much less time to control the ports directly, even though
(in my case) performance was not an issue. Each port pin
actually consists of three register bits — DDRxn, PORTxn,
and PINxn — where x designates the port (A through L)
and n specifies the bit (0 through 7). The DDRxn bit
specifies the direction of the pin. If DDRxn is set to a logic
one, the pin is an output. If DDRxn is set to a logic zero,
the pin is an input. PORTxn is used to set output data and
Figure 4.
Final breadboard
layout.
Master EEPROM
is on the left (read
only) and the blank
Slave EEPROM
(writeable) is on
the right.
May 2010 43