-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
2,615 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#define SER_Pin A3 // 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 // AT28 CE, chip enable | ||
#define AT28_WE_Pin 11 // AT28 WE, write enable | ||
#define AT28_OE_Pin 12 // AT28 OE, output enable | ||
|
||
#define numOfRegisterPins 16 | ||
|
||
// 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) | ||
|
||
void testShiftRegister(); | ||
int writeEEPROM(); | ||
void verifyEEPROM(); | ||
void readEEPROM(); | ||
void setupAT28(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Arduino Uno Programmer for AT28 EEPROM | ||
// Chris Torrence, 2015 | ||
// ideas from: http://forum.6502.org/viewtopic.php?f=4&t=2491 | ||
// | ||
|
||
#include "ProgrammerAT28.h" | ||
|
||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
|
||
setupAT28(); | ||
|
||
Serial.println("***** TESTING *****"); | ||
testShiftRegister(); | ||
|
||
// Wait until user hits return. | ||
if (1) { | ||
Serial.println("***** Hit <RETURN> to start WRITE/VERIFY *****"); | ||
while (Serial.available() == 0) {}; | ||
Serial.read(); | ||
int success = writeEEPROM(); | ||
if (success) { | ||
verifyEEPROM(); | ||
} | ||
} else { | ||
Serial.println("***** Hit <RETURN> to read & dump EEPROM *****"); | ||
while (Serial.available() == 0) {}; | ||
Serial.read(); | ||
readEEPROM(); | ||
} | ||
} | ||
|
||
|
||
void loop() | ||
{ | ||
// Do nothing | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,235 @@ | ||
|
||
#include <Arduino.h> | ||
#include "ProgrammerAT28.h" | ||
|
||
#include "ProgData.h" | ||
|
||
|
||
// 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(100); | ||
for (int i=0; i < numOfRegisterPins; i++) | ||
{ | ||
writeShiftRegister(1 << i); | ||
delay(50); | ||
} | ||
// Light them all up, then turn them off. | ||
writeShiftRegister(8191); | ||
delay(50); | ||
writeShiftRegister(0); | ||
} | ||
|
||
|
||
void printValue(int address, byte value, int debug) | ||
{ | ||
if (address % 32 == 0 || debug) | ||
{ | ||
Serial.println(""); | ||
Serial.print("$"); | ||
if (address < 4096) Serial.print("0"); | ||
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); | ||
} | ||
|
||
byte readValue(int address) | ||
{ | ||
// Now read the value. | ||
// Set the AT28 for "READ", WE high, OE low | ||
// Set the data pins for input | ||
digitalWrite(AT28_WE_Pin, HIGH); | ||
for (int i=2; i <= 9; i++) pinMode(i, INPUT); | ||
|
||
writeShiftRegister(address); | ||
digitalWrite(AT28_OE_Pin, LOW); | ||
|
||
int actualValue = 0; | ||
// the (9 - i) translates from bit # to pin # | ||
for (int i=0; i <= 7; i++) { | ||
if (digitalRead(9 - i)) actualValue += (1 << i); | ||
} | ||
|
||
digitalWrite(AT28_OE_Pin, HIGH); | ||
return actualValue; | ||
} | ||
|
||
// Procedure to write to the AT28: | ||
// Set OE and WE high | ||
// For each address, write the address and data, then pulse WE low | ||
int writeEEPROM() | ||
{ | ||
Serial.println(""); | ||
Serial.println("***** WRITE *****"); | ||
digitalWrite(AT28_CE_Pin, LOW); | ||
byte currentValue; | ||
|
||
for (int address=0; address < ADDRESS_MAX; address++) | ||
{ | ||
byte value = pgm_read_byte_near(values + address); | ||
printValue(address, value, 0); | ||
|
||
currentValue = readValue(address); | ||
if (currentValue != value) | ||
{ | ||
|
||
for (int l=0; l < 10; l++) | ||
{ | ||
for (int i=2; i <= 9; i++) pinMode(i, OUTPUT); | ||
digitalWrite(AT28_OE_Pin, HIGH); | ||
digitalWrite(AT28_WE_Pin, HIGH); | ||
writeShiftRegister(address); | ||
|
||
// the (9 - i) translates from bit # to pin # | ||
for (int i=0; i <= 7; i++) { | ||
if (value & (1 << i)) digitalHigh(9 - i); else digitalLow(9 - i); | ||
} | ||
|
||
// Send a pulse to the AT28 to write the data | ||
digitalLow(AT28_WE_Pin); | ||
delay(1); | ||
digitalHigh(AT28_WE_Pin); | ||
currentValue = readValue(address); | ||
if (currentValue == value) break; | ||
} | ||
|
||
for (int i=0; i <= 7; i++) { | ||
digitalLow(9 - i); | ||
} | ||
currentValue = readValue(address); | ||
if (currentValue == value) | ||
{ | ||
currentValue = readValue(address); | ||
if (currentValue != value) | ||
{ | ||
Serial.println(""); | ||
Serial.println("Error writing value!"); | ||
return 0; | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
writeShiftRegister(0); | ||
return 1; | ||
} | ||
|
||
|
||
// Procedure to read from the AT28: | ||
// Set OE low and WE high | ||
// For each address, write the address, then read the data | ||
void verifyEEPROM() | ||
{ | ||
Serial.println(""); | ||
Serial.println("***** READ *****"); | ||
for (int i=2; i <= 9; i++) pinMode(i, INPUT); | ||
digitalWrite(AT28_CE_Pin, LOW); | ||
|
||
for (int address=0; address < ADDRESS_MAX; address++) | ||
{ | ||
int value = readValue(address); | ||
|
||
byte expectvalue = pgm_read_byte_near(values + address); | ||
|
||
if (expectvalue != value) { | ||
printValue(address, value, 1); | ||
Serial.print(" <-- Wrong value, should be: "); | ||
if (expectvalue < 16) Serial.print("0"); | ||
Serial.println(expectvalue, HEX); | ||
} | ||
else | ||
{ | ||
printValue(address, value, 0); | ||
} | ||
delay(1); | ||
} | ||
|
||
writeShiftRegister(0); | ||
Serial.println(""); | ||
} | ||
|
||
|
||
// 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 *****"); | ||
for (int i=2; i <= 9; i++) pinMode(i, INPUT); | ||
digitalWrite(AT28_CE_Pin, LOW); | ||
|
||
for (int address=0; address < ADDRESS_MAX; address++) | ||
{ | ||
if (address % 32 == 0) Serial.println(""); | ||
int value = readValue(address); | ||
Serial.print(value); | ||
Serial.print(","); | ||
|
||
delay(1); | ||
} | ||
|
||
writeShiftRegister(0); | ||
Serial.println(""); | ||
} | ||
|
||
|
||
// Initial setup of all of the AT28C16/C64 pins. | ||
void setupAT28() | ||
{ | ||
|
||
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); | ||
|
||
if (ADDRESS_MAX > 2048) | ||
{ | ||
Serial.println("***** Is the switch in the UP position?! *****"); | ||
} | ||
else | ||
{ | ||
Serial.println("***** Is the switch in the DOWN position?! *****"); | ||
} | ||
|
||
} |
Oops, something went wrong.