As a new member let me present myself.
My native language is not English so you have to be tolerant with my writing.
I work on IT as a business analyst - ERP implementations.
I have a good background on programming (c/c++). I never had the need to study assembler. Hardware and assembler is a complete new field to me.
About year ago I found a new hobby. I began to be interested on microcontrollers and made some projects on robotics with atmel chips.
One day found this site (6502.org) and I assume. I got the bug. I also want to build a single board computer. I also want to create my operating system, my basic and who knows what else.
So I decided to build a 6502 computer. And here I am with my first question.
While I am working on the schematics I am also testing my ROM (AT28C256). Using an Atmega16 I created two routines one to write and another to read from the eeprom. I only use the low address. High address is wired to ground.
Both routines work well. I can write and I can read. If my program just calls the write routine it writes. If my program just calls the read routine it reads. But if I use both routines (write and then read) the values that it reads aren’t real.
Can anybody help me with this?
I know this is not a microcontroller forum, but the objective is to use the microcontroller to study the timing and help to define the wiring.
This is my code:
Code:
#include <avr/io.h>
#include <util/delay.h>
#define LedDDR DDRC
#define LedPort PORTC
#define ControlPort PORTD
#define ControlDDR DDRD
#define DataPort PORTB
#define DataDDR DDRB
#define DataPIN PINB
#define AddressPort PORTA
#define AddressDDR DDRA
#define MemRW 3
#define MemOE 2
#define MemCE 1
void writeEPROM(unsigned char address, unsigned char c);
unsigned char readEPROM(unsigned char address);
void writeEPROM(unsigned char address, unsigned char c)
{
DataDDR |= 0xFF;
ControlPort |= (1 << MemRW | 1 << MemCE | 1 << MemOE);
ControlPort &= ~(1 << MemRW);
AddressPort = address;
//asm volatile ("nop");
ControlPort &= ~(1 << MemCE);
DataPort = c;
_delay_ms(20);
ControlPort |= (1 << MemCE);
}
unsigned char readEPROM(unsigned char address)
{
unsigned char c;
DataDDR |= 0x00;
ControlPort |= (1 << MemOE | 1 << MemCE | 1 << MemRW);
//ControlPort |= (1 << MemRW);
AddressPort = address;
ControlPort &= ~(1 << MemOE | 1 << MemCE);
_delay_ms(1);
c = DataPIN;
ControlPort |= (1 << MemOE | 1 << MemCE);
return c;
}
void write(void) {
writeEPROM(0b00000000, 0b10000000);
writeEPROM(0b00000001, 0b10000001);
writeEPROM(0b00000010, 0b10000010);
writeEPROM(0b00000011, 0b10000011);
writeEPROM(0b00000100, 0b10000100);
writeEPROM(0b00000101, 0b10000101);
writeEPROM(0b00000110, 0b10000110);
writeEPROM(0b00000111, 0b10000111);
writeEPROM(0b00001000, 0b10001000);
writeEPROM(0b00001001, 0b10001001);
writeEPROM(0b00001010, 0b10001010);
LedPort = 0xFF;
}
void read(void) {
LedPort = readEPROM(0b00000000); _delay_ms(1000);
LedPort = readEPROM(0b00000001); _delay_ms(1000);
LedPort = readEPROM(0b00000010); _delay_ms(1000);
LedPort = readEPROM(0b00000011); _delay_ms(1000);
LedPort = readEPROM(0b00000100); _delay_ms(1000);
LedPort = readEPROM(0b00000101); _delay_ms(1000);
LedPort = readEPROM(0b00000110); _delay_ms(1000);
LedPort = readEPROM(0b00000111); _delay_ms(1000);
LedPort = readEPROM(0b00001000); _delay_ms(1000);
LedPort = readEPROM(0b00001001); _delay_ms(1000);
LedPort = readEPROM(0b00001010); _delay_ms(1000);
LedPort = readEPROM(0b00001011); _delay_ms(1000);
LedPort = 0xFF;
}
int main(void) {
LedDDR = 0xFF;
ControlDDR |= 0xFF;
AddressDDR |= 0xFF;
//write();
read();
while(1) {
}
return 0;
}