Close

1st Bit of Progress

A project log for ZAViouR Board - AVR/Z80 Hybrid

A Z80 experimenters board with a supervisory AVR and 64K of SRAM

steve-smithSteve Smith 08/21/2015 at 15:490 Comments

I find C programming really frustrating! I'm not sure if it's because I'm past it or if C is just to damn abstract but I have real problems with it. Anyway, today, I made a little progress. Originally, my thoughts on how to set the AVRs ports to pass data on to SRAM were based around comparing each bit of a databyte (from the Z80 program bytes in an array) and setting the AVR ports literally bit-by-bit. However, I have found that you can set the entire port with one PORTx = y command! How simple is that. You have to set the port's direction first but that's also easier with DDRx = B11111111 so I have wired up 8 LEDs with resistors on my trusty Arduino UNO and run this:

unsigned char Z80_CODE[]={0x21,0x00,0x00,0x11,0x01,0x00,0x01,0xff,0x1a,0x36,0xaa,0xed,0xb0,0xc3,0x0d,0x00,0xff};
int b = 0;

void setup() {
  // put your setup code here, to run once:
  DDRD = B11111111; // set PORTD (digital 7~0) to outputs
  Serial.begin(9600);
}

void loop() {
  for (int l = 0; l < sizeof(Z80_CODE); ++l) {
  for (int i = 0; i < 8; ++i) {
      Serial.print((Z80_CODE[l] >> i) & 1);
      b = Z80_CODE[l];
      PORTD = b;    
      }
    Serial.print('\n');
    delay (500);
  }
while(true) {}
}
It picks up each byte from the array in turn, prints it in binary to the serial port and then sets port D accordingly. There is a delay of half a second just so you can see it working. FAB!

OK, Next up is to write functions to set the Data and Address ports and pulse the /CE and /WR lines on the SRAM so that the data is stored.

Discussions