EPROM Utils

What can I say?  I have this thing for old electronics.  I had some EPROMs I needed to test and it was a good excuse to buy an EPROM burner.  So, I did the smart thing and bought some great Chinese burner.  It works…sometimes.  It reads correctly though…sometimes.  Anyway, long story short, I needed an excuse to get an Arduino Mega.

Using an SD Card shield and a bunch of wires to a breadboard, I was able to test my old EPROMS.  I found various source code on the net for EPROM reading in many different ways and decided to write a program that could do this and compare to files on an SD card.  I may add the burner part down the road, when I feel like making a power supply for the various voltages, or maybe if I decide to use a newer EEPROM that burns with 5v.  For now, you can view, compare and save to files.  I actually wrote an emulator in here, but it is really just too slow for real use, so I took it out.

Not all SD shields are compatible with Mega, BTW.  They decided to move the SPI pins.  Not a big deal.  I bent the standard shield pins out of the way and ran breadboard wires to the correct ones for the Mega.

eprom

Just upload this to your board and then open the Serial Monitor.  You will then see your options.  Check the datasheet of your part before using and make sure you have all the A’s, Q’s, GNDs and V’s connected properly.  You may have to tie your VPP line to +5v to get an output as well.

//BE SURE TO CREATE A ROMS SUBDIRECTORY ON YOUR SD CARD

#include <stdint.h>
#include <SdFat.h>
#include <SdFatUtil.h>

const uint8_t chipSelect = SS;
SdFat sd;
SdBaseFile romsdir; //roms subdir
SdBaseFile romfile; //This will be the selected file for use

ArduinoOutStream cout(Serial); //allows cout to go right to serial port

// Connect EPROM address lines in sequence
// to the A0-A15 lines, and pins 2-10 to the
// Q0-Q7 lines. Change if using different pins.
#define AS 26 //Address start pin
#define QS 2  //Output start pin
#define OE 22 //Output enable
#define CE 23 //Chip enable
#define PE 24 //program or program enable

char sbuff[13];
char curfile[13];
long maxaddr = 1024; //set a default value
long fsize=0;

void setup() {
	pinMode(OE,OUTPUT);  //output enable pin - High = Disable
	digitalWrite(OE,HIGH);
	pinMode(CE,OUTPUT); //chip enable pin  - High = Disable
	digitalWrite(CE,HIGH);
	pinMode(PE,OUTPUT); //program enable pin  - High = Disable
	digitalWrite(PE,HIGH);
	for (int i = AS; i < AS+13; i++) { //set for reading EPROM address lines
		pinMode(i, OUTPUT);
		digitalWrite(i,LOW);
	}
	for (int i = QS; i < QS+8; i++) { //set for reading EPROM data lines
		pinMode(i, INPUT);
		digitalWrite(i,HIGH);
	}
	Serial.begin(115200);
	cout << pstr("Eprom Utilities - Don Peruski v1.0\n\n");
	if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
	if (!romsdir.open(sd.vwd(),"roms", O_READ)) cout << ("Could not open //roms directory."); //open /roms directory
}

void writeAddr(uint32_t addr) {
	uint32_t mask = 0x01;
	//digitalWrite(OE,HIGH); //disable output for address set
	//delay(1);
	for (int i = AS; i < AS+13; i++) {
		if ((mask & addr) != 0) {
			digitalWrite(i,HIGH);
		} 
		else { 
			digitalWrite(i,LOW);
		}
		mask = mask << 1;
	}
}

uint8_t readbyteeprom() {
	uint8_t data = 0;
	uint8_t mask = 0x1;
	//digitalWrite(OE,LOW); //enable output for data read
	//delay(1);
	for (int i = QS; i < QS+8; i++) {
		if (digitalRead(i) == HIGH) {
			data |= mask;
		}
		mask = mask << 1;
	}
	return data;
}

void readsdfile2screen() {
	long c=0;
	uint8_t b;
	romfile.rewind();
	cout << pstr("File Contents:\n-----------------------------------------------------\n\n");
	while(c<fsize) {
		romfile.read(sbuff,1);
		memcpy(&b,sbuff,1);
		c++;
		if (b<16) Serial.print(0);
		Serial.print(b,HEX);
		cout << pstr(" ");
		if (c % 16==0) Serial.println();
	}
	cout << pstr("\n\n------------------------------------------------------\nFinished\n");
}

void compare(){
	uint32_t c=0;
	byte fbuff;
	byte b;
	romfile.rewind();
	cout << pstr("\nVerifying:\n");
	if (fsize!=maxaddr) cout << pstr("The ROM Size and SD File Size do not match!\n\n");
	else {
		digitalWrite(CE,LOW); //enable the chip
		digitalWrite(OE,LOW); //enable output for data read
		while (c<fsize) {
			romfile.read(sbuff,1);
			memcpy(&fbuff,sbuff,1);
			writeAddr(c);
			b = readbyteeprom();
			if (b!=fbuff) {
				cout << pstr("Address:") << c << pstr(" Mismatch.  ROM= ") << b << pstr(" File = ") << fbuff << pstr ("\n");
			}
			c++;
			if (c % 2000 == 0) cout << ".";
		}
		cout << pstr("\n\n---Done. If mismatches were found, they are printed above.---\n\n");
		digitalWrite(CE,HIGH); //disable the chip
		digitalWrite(OE,HIGH); //disable output for data read
	}
}

void readeprom2screen() {
	uint32_t addr = 0;
	delay(1000);
	Serial.flush();
	delay(1000);
	digitalWrite(CE,LOW); //enable the chip
	digitalWrite(OE,LOW); //enable output for data read
	while (addr < maxaddr) {
		for (int i = 0; i < 16; i++) {
			writeAddr(addr);
			//delay(1);
			uint8_t b = readbyteeprom();
			//Serial.print(addr, HEX); //if you want to see the address
			//Serial.print(":");
			if (b<16) Serial.print(0); //this is to format hex output for the app HxD by adding an extra 0
			Serial.print(b, HEX);
			cout << pstr(" ");
			//delay(1);
			addr++;
		}
		Serial.println();
	}
	digitalWrite(OE,HIGH);
	digitalWrite(CE,HIGH);
	cout << ("\n\nDone\n\n");
}

void writeepromtosdfile() {
	uint32_t addr = 0;
	delay(1000);
	Serial.flush();
	delay(1000);
	digitalWrite(CE,LOW); //enable the chip
	digitalWrite(OE,LOW); //enable output for data read
	while (addr < maxaddr) {
		writeAddr(addr);
		//delay(1);
		sbuff[0] = readbyteeprom();
		romfile.write(sbuff,1);
		addr++;
		if (addr % 2000 == 0) cout << ".";
	}
	romfile.sync();
	fsize=romfile.fileSize();
	digitalWrite(OE,HIGH);
	digitalWrite(CE,HIGH);
	cout << ("\n\nDone\n\n");
}

void getepromsize(){
	byte c;
	maxaddr=2048;
	cout << pstr("Eprom Size: \n\n(a)2716\n(b)2732\n(c)2764\n(d)27128\n(e)27256\n(f)27512\n:");
	while (!Serial.available()) {
	}
	c = Serial.read();
	maxaddr=maxaddr<<c-97; 
}

void opensdfile(uint8_t flg) {
	memset(sbuff,NULL,13);
	cout << pstr("\nEnter File Name:\n\n");
	while (!Serial.available()) {
	}
	Serial.readBytes(sbuff,13);
	romfile.close();
	if(!romfile.open(&romsdir,sbuff,(flg))){
		cout <<pstr("Error Opening or Creating: ") << sbuff <<"\n";
		romfile.close();
		delay(5000);
		memset(curfile,NULL,13);
		fsize=0;
	} 
	else {
		memcpy(curfile,sbuff,13);
		cout << curfile << pstr (" opened successfully.\n\n");
		fsize=romfile.fileSize();
	}
}

void getcommand() {
	char c;
	while (Serial.read() >= 0) {
	}
	cout << pstr("\nSD File Currently Selected :")<< curfile << pstr("  FileSize: ") << fsize;
	cout << pstr("\nEprom Size set to :") << maxaddr <<" bytes\n";
	cout << pstr("\n(1)View \\roms Directory\n(2)Set EPROM Size\n(3)Select SD File for READ ONLY\n(4)Select SD file to OVERWRITE or CREATE\n"
		"(5)Select SD File to Append\n(6)Read Eprom to Screen in Hex\n(7)Read SD File to Screen in Hex\n(8)Verify Eprom to selected SD File\n"
		"(9)Write Eprom to SD File\n\n");
	while (!Serial.available()){
	}
	c = Serial.read();  
	switch (c) {
	case '1':
		cout << pstr("Files found in \\roms:\n--------------------------------------------------------------\n");
		romsdir.ls(LS_DATE | LS_SIZE);
		cout << pstr("--------------------------------------------------------------\n\n\n");
		break;
	case '2':
		getepromsize();
		break;
	case '3':
		cout << pstr("This will open the file safely so an overwrite won't occur.\n");
		opensdfile(O_READ);
		break;
	case '4':
		cout << pstr("This will destroy contents in the file if it exists!\n");
		opensdfile(O_RDWR | O_CREAT | O_TRUNC);
		break;
	case '5':
		cout << pstr("This option will allow you to append to an existing file.  You can keep writing to it to join ROMS.\n");
		opensdfile(O_RDWR | O_CREAT |O_APPEND);
		break;     
	case '6':
		cout << pstr("Preparing Eprom to READ\n\n");
		readeprom2screen();
		break;
	case '7':
		readsdfile2screen();
		break;
	case '8':
		compare();
		break;
	case '9':
		cout << pstr("Preparing to write file from Eprom\n\n");
		writeepromtosdfile();
		break;
	}
}

void loop() {
	getcommand();
}



One Response to EPROM Utils

  1. Pingback: Added EPROM Utils Page | Diskwiz

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s