Skip to content

Commit 30ae19c

Browse files
committed
Initial revision
1 parent 061dfaa commit 30ae19c

18 files changed

+2615
-0
lines changed

AT28 Programmer wiring.odg

2.33 MB
Binary file not shown.

AT28 Programmer wiring.pdf

1.52 MB
Binary file not shown.

AT28 programmer.jpg

6.14 MB
Loading

AT28 programmer.odg

152 KB
Binary file not shown.

AT28 programmer.pdf

112 KB
Binary file not shown.

ProgData.h

Lines changed: 520 additions & 0 deletions
Large diffs are not rendered by default.

Prog_Booti.h

Lines changed: 520 additions & 0 deletions
Large diffs are not rendered by default.

ProgrammerAT28.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#define SER_Pin A3 // 75HC595 pin 14, serial input
2+
#define STCP_Pin A2 // 75HC595 pin 12, STCP storage register clock
3+
#define SHCP_Pin A1 // 75HC595 pin 11, SHCP shift register clock
4+
5+
#define AT28_CE_Pin 10 // AT28 CE, chip enable
6+
#define AT28_WE_Pin 11 // AT28 WE, write enable
7+
#define AT28_OE_Pin 12 // AT28 OE, output enable
8+
9+
#define numOfRegisterPins 16
10+
11+
// Fast way of setting/reading/writing pins on the Arduino
12+
// http://masteringarduino.blogspot.com/2013_10_01_archive.html
13+
#define portOfPin(P)\
14+
(((P)>=0&&(P)<8)?&PORTD:(((P)>7&&(P)<14)?&PORTB:&PORTC))
15+
#define pinOfPin(P)\
16+
(((P)>=0&&(P)<8)?&PIND:(((P)>7&&(P)<14)?&PINB:&PINC))
17+
#define pinIndex(P) ((uint8_t)(P>13?P-14:P&7))
18+
#define pinMask(P) ((uint8_t)(1<<pinIndex(P)))
19+
#define digitalLow(P) *(portOfPin(P))&=~pinMask(P)
20+
#define digitalHigh(P) *(portOfPin(P))|=pinMask(P)
21+
#define isHigh(P) ((*(pinOfPin(P))& pinMask(P))>0)
22+
#define isLow(P) ((*(pinOfPin(P))& pinMask(P))==0)
23+
24+
void testShiftRegister();
25+
int writeEEPROM();
26+
void verifyEEPROM();
27+
void readEEPROM();
28+
void setupAT28();

ProgrammerAT28.ino

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Arduino Uno Programmer for AT28 EEPROM
2+
// Chris Torrence, 2015
3+
// ideas from: http://forum.6502.org/viewtopic.php?f=4&t=2491
4+
//
5+
6+
#include "ProgrammerAT28.h"
7+
8+
9+
void setup()
10+
{
11+
Serial.begin(115200);
12+
13+
setupAT28();
14+
15+
Serial.println("***** TESTING *****");
16+
testShiftRegister();
17+
18+
// Wait until user hits return.
19+
if (1) {
20+
Serial.println("***** Hit <RETURN> to start WRITE/VERIFY *****");
21+
while (Serial.available() == 0) {};
22+
Serial.read();
23+
int success = writeEEPROM();
24+
if (success) {
25+
verifyEEPROM();
26+
}
27+
} else {
28+
Serial.println("***** Hit <RETURN> to read & dump EEPROM *****");
29+
while (Serial.available() == 0) {};
30+
Serial.read();
31+
readEEPROM();
32+
}
33+
}
34+
35+
36+
void loop()
37+
{
38+
// Do nothing
39+
}

ProgrammerAT28Main.cpp

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
2+
#include <Arduino.h>
3+
#include "ProgrammerAT28.h"
4+
5+
#include "ProgData.h"
6+
7+
8+
// Procedure to set and display registers:
9+
// STCP low
10+
// For each address bit (high to low): SHCP low, write bit, SHCP high
11+
// STCP high to transfer to the storage register (and the output)
12+
//
13+
void writeShiftRegister(long val)
14+
{
15+
digitalWrite(STCP_Pin, LOW);
16+
17+
// From highest bit to lowest bit
18+
for(int i = 15; i >= 0; i--)
19+
{
20+
digitalWrite(SHCP_Pin, LOW);
21+
digitalWrite(SER_Pin, (val >> i) & 1); // Write the next highest bit
22+
digitalWrite(SHCP_Pin, HIGH); // Left shift the register 1 bit
23+
24+
}
25+
digitalWrite(STCP_Pin, HIGH);
26+
}
27+
28+
29+
// Light up the LEDs using each valid address
30+
void testShiftRegister()
31+
{
32+
// Just light up the LEDs in order.
33+
writeShiftRegister(0);
34+
delay(100);
35+
for (int i=0; i < numOfRegisterPins; i++)
36+
{
37+
writeShiftRegister(1 << i);
38+
delay(50);
39+
}
40+
// Light them all up, then turn them off.
41+
writeShiftRegister(8191);
42+
delay(50);
43+
writeShiftRegister(0);
44+
}
45+
46+
47+
void printValue(int address, byte value, int debug)
48+
{
49+
if (address % 32 == 0 || debug)
50+
{
51+
Serial.println("");
52+
Serial.print("$");
53+
if (address < 4096) Serial.print("0");
54+
if (address < 256) Serial.print("0");
55+
if (address < 16) Serial.print("0");
56+
Serial.print(address, HEX);
57+
Serial.print(":");
58+
}
59+
60+
Serial.print(" ");
61+
if (value < 16) Serial.print("0");
62+
Serial.print(value, HEX);
63+
}
64+
65+
byte readValue(int address)
66+
{
67+
// Now read the value.
68+
// Set the AT28 for "READ", WE high, OE low
69+
// Set the data pins for input
70+
digitalWrite(AT28_WE_Pin, HIGH);
71+
for (int i=2; i <= 9; i++) pinMode(i, INPUT);
72+
73+
writeShiftRegister(address);
74+
digitalWrite(AT28_OE_Pin, LOW);
75+
76+
int actualValue = 0;
77+
// the (9 - i) translates from bit # to pin #
78+
for (int i=0; i <= 7; i++) {
79+
if (digitalRead(9 - i)) actualValue += (1 << i);
80+
}
81+
82+
digitalWrite(AT28_OE_Pin, HIGH);
83+
return actualValue;
84+
}
85+
86+
// Procedure to write to the AT28:
87+
// Set OE and WE high
88+
// For each address, write the address and data, then pulse WE low
89+
int writeEEPROM()
90+
{
91+
Serial.println("");
92+
Serial.println("***** WRITE *****");
93+
digitalWrite(AT28_CE_Pin, LOW);
94+
byte currentValue;
95+
96+
for (int address=0; address < ADDRESS_MAX; address++)
97+
{
98+
byte value = pgm_read_byte_near(values + address);
99+
printValue(address, value, 0);
100+
101+
currentValue = readValue(address);
102+
if (currentValue != value)
103+
{
104+
105+
for (int l=0; l < 10; l++)
106+
{
107+
for (int i=2; i <= 9; i++) pinMode(i, OUTPUT);
108+
digitalWrite(AT28_OE_Pin, HIGH);
109+
digitalWrite(AT28_WE_Pin, HIGH);
110+
writeShiftRegister(address);
111+
112+
// the (9 - i) translates from bit # to pin #
113+
for (int i=0; i <= 7; i++) {
114+
if (value & (1 << i)) digitalHigh(9 - i); else digitalLow(9 - i);
115+
}
116+
117+
// Send a pulse to the AT28 to write the data
118+
digitalLow(AT28_WE_Pin);
119+
delay(1);
120+
digitalHigh(AT28_WE_Pin);
121+
currentValue = readValue(address);
122+
if (currentValue == value) break;
123+
}
124+
125+
for (int i=0; i <= 7; i++) {
126+
digitalLow(9 - i);
127+
}
128+
currentValue = readValue(address);
129+
if (currentValue == value)
130+
{
131+
currentValue = readValue(address);
132+
if (currentValue != value)
133+
{
134+
Serial.println("");
135+
Serial.println("Error writing value!");
136+
return 0;
137+
}
138+
}
139+
}
140+
141+
}
142+
143+
writeShiftRegister(0);
144+
return 1;
145+
}
146+
147+
148+
// Procedure to read from the AT28:
149+
// Set OE low and WE high
150+
// For each address, write the address, then read the data
151+
void verifyEEPROM()
152+
{
153+
Serial.println("");
154+
Serial.println("***** READ *****");
155+
for (int i=2; i <= 9; i++) pinMode(i, INPUT);
156+
digitalWrite(AT28_CE_Pin, LOW);
157+
158+
for (int address=0; address < ADDRESS_MAX; address++)
159+
{
160+
int value = readValue(address);
161+
162+
byte expectvalue = pgm_read_byte_near(values + address);
163+
164+
if (expectvalue != value) {
165+
printValue(address, value, 1);
166+
Serial.print(" <-- Wrong value, should be: ");
167+
if (expectvalue < 16) Serial.print("0");
168+
Serial.println(expectvalue, HEX);
169+
}
170+
else
171+
{
172+
printValue(address, value, 0);
173+
}
174+
delay(1);
175+
}
176+
177+
writeShiftRegister(0);
178+
Serial.println("");
179+
}
180+
181+
182+
// Procedure to read from the AT28:
183+
// Set OE low and WE high
184+
// For each address, write the address, then read the data
185+
void readEEPROM()
186+
{
187+
Serial.println("");
188+
Serial.println("***** READ *****");
189+
for (int i=2; i <= 9; i++) pinMode(i, INPUT);
190+
digitalWrite(AT28_CE_Pin, LOW);
191+
192+
for (int address=0; address < ADDRESS_MAX; address++)
193+
{
194+
if (address % 32 == 0) Serial.println("");
195+
int value = readValue(address);
196+
Serial.print(value);
197+
Serial.print(",");
198+
199+
delay(1);
200+
}
201+
202+
writeShiftRegister(0);
203+
Serial.println("");
204+
}
205+
206+
207+
// Initial setup of all of the AT28C16/C64 pins.
208+
void setupAT28()
209+
{
210+
211+
pinMode(SER_Pin, OUTPUT);
212+
pinMode(STCP_Pin, OUTPUT);
213+
pinMode(SHCP_Pin, OUTPUT);
214+
215+
pinMode(AT28_CE_Pin, OUTPUT);
216+
pinMode(AT28_WE_Pin, OUTPUT);
217+
pinMode(AT28_OE_Pin, OUTPUT);
218+
219+
// Disable the AT28
220+
digitalWrite(AT28_CE_Pin, HIGH);
221+
digitalWrite(AT28_WE_Pin, HIGH);
222+
digitalWrite(AT28_OE_Pin, HIGH);
223+
224+
for (int i=2; i <= 9; i++) pinMode(i, INPUT);
225+
226+
if (ADDRESS_MAX > 2048)
227+
{
228+
Serial.println("***** Is the switch in the UP position?! *****");
229+
}
230+
else
231+
{
232+
Serial.println("***** Is the switch in the DOWN position?! *****");
233+
}
234+
235+
}

0 commit comments

Comments
 (0)