Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dump EPROM over serial with AVR
/**
* Thrown together program to dump 512 kbit EPROMs from an AVR ATMega64A/128A
* More specifically, a bunch of ST M27C512 from the early 90's
*
* Connections:
*
* Port A 0-7: low address byte (output)
* Port B 0-7: high address byte (output)
* Port D 0-7: data (input)
*
* Written for this expedition:
* https://twitter.com/stecman/status/1019167609051213824
*/
#include <avr/interrupt.h>
#include <avr/io.h>
#include <util/delay.h>
void init_usart(void)
{
cli();
// Set baud rate to 38400 (with 16MHz clock)
UBRR0H = (uint8_t)(25 >> 8);
UBRR0L = (uint8_t)(25);
// Enable receiver and transmitter
UCSR0B = _BV(RXEN0) | _BV(TXEN0);
// Set frame format: 8 data, 1 stop bit
UCSR0C = (3<<UCSZ00);
UCSR0C &= ~(1<<USBS0);
sei();
}
void usart_transmit(uint8_t data)
{
// Wait for empty transmit buffer
while ( !( UCSR0A & (1<<UDRE0)) );
// Put data into buffer, sends the data
UDR0 = data;
}
uint8_t usart_receive(void)
{
// Wait for data to be received
while ( !(UCSR0A & (1<<RXC0)) );
// Get and return received data from buffer
return UDR0;
}
int main(void)
{
init_usart();
// Port A: low address byte output (start at 0x0)
DDRA = 0xFF;
PORTA = 0x0;
// Port B: high address byte output (start at 0x0)
DDRB = 0xFF;
PORTB = 0x0;
// Port D: data input with no pull-up
DDRD = 0x0;
PORTD = 0x0;
// Wait half a second for humans
_delay_ms(500);
for (uint16_t address = 0; address < 0xFFFF; ++address) {
// Set address
PORTA = address & 0xFF;
PORTB = address >> 8;
// Wait 10x longer than necessary for the output to stablise (because why not)
_delay_us(1);
// Read and send data over serial
usart_transmit( PIND );
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.