#include "parallelsram.h" // Assumes any Output Enable pin is hardwired-enabled; // any Chip Enable pin is hardwared-enabled. // // Uses the low 8 bits of Port D as I/O lines (2, 14, 7, 8, 6, 20, 21, 5). // // R/W (aka WriteEnable) is on pin 31. #define RAM_RW 34 // The Address pins (19 of them). It would be nice to have these // easily bitwise-manipulable, instead of having to set each bit // individually. // // We can use 12 bits of Port C: 15, 22, 23, 9, 10, 13, 11, 12, 35, 36, 37, 38 // And then 6 bits of Port B: 16 17 19 18 49 50 // // And hard wire one bit low (we don't need all 19 lines). That gets us // 256 Kb of RAM which should be sufficient. static uint8_t addrPins[] = { 15, 22, 23, 9, 10, 13, 11, 12, 35, 36, 37, 38, 16, 17, 19, 18, 49, 50 }; #if 0 #define DELAY { delayMicroseconds(1); /* overkill, but useful for debugging */ } #else #define DELAY { __asm__ volatile ("nop"); __asm__ volatile ("nop"); \ __asm__ volatile ("nop"); __asm__ volatile ("nop"); \ __asm__ volatile ("nop"); __asm__ volatile ("nop"); \ __asm__ volatile ("nop"); __asm__ volatile ("nop"); \ } #endif #define OE_ON { /*if (noe != 255) {digitalWrite(noe, LOW);}*/ } #define OE_OFF { /*if (noe != 255) {digitalWrite(noe, HIGH);}*/ } #define CE_ON { /*if (n_ce != 255) {digitalWrite(n_ce, LOW);} if (p_ce != 255) { digitalWrite(p_ce, HIGH); }*/ } #define CE_OFF { /*if (n_ce != 255) {digitalWrite(n_ce, HIGH);} if (p_ce != 255) { digitalWrite(p_ce, LOW); }*/ } #define WE_ON { digitalWriteFast(RAM_RW, LOW); } #define WE_OFF { digitalWriteFast(RAM_RW, HIGH); } ParallelSRAM::ParallelSRAM() { pinMode(RAM_RW, OUTPUT); // Port D is our I/O port. Use the AVR emulation layer to set up the // pins once, and then we'll just fiddle with the DDR, input, and // output directly. // Enable it as a digital port... // SIM_SCGC5 |= SIM_SCGC5_PORTD; //... what else? How do we set PORTD_PCR[0-7]? pinMode(2, INPUT); pinMode(14, INPUT); pinMode(7, INPUT); pinMode(8, INPUT); pinMode(6, INPUT); pinMode(20, INPUT); pinMode(21, INPUT); pinMode(5, INPUT); isInput = true; // Set up the address pins for (int i=0; i> 12); #if 0 for (uint8_t i=0; i