#include /* DDRx - The Port x Data Direction Register - read/write PORTx - The Port x Data Register - read/write PINx - The Port x Input Pins Register - read only */ #define SERIALBUFSIZE 11 //char serialBuffer[SERIALBUFSIZE]; //byte setBufPointer = 0; #define D2 10 #define D3 11 #define DEVVCC 12 #define REC_TYPE 0 #define OUTS 10 #define INS 8 unsigned long addrSize = 1024; void setup() { Serial.begin(115200); delay(1000); PORTD = 0xFF; PORTC = 0xFF; PORTB = 0xFF; // needed for switch from tristate to output low PORTA = 0xFF; DDRD = DDRD | 0b11111100; // switch all but serial pins to output DDRC = 0x00; // input DDRB = 0xFF; // output DDRA = 0xFF; // output Serial.println("PAL16R6 read v1.0"); Serial.println("1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19"); Serial.println("D2, B7, B6, B5, B4, B3, B2, B1, B0, D3, C0, C1, C2, C3, C4, C5, C6, C7"); Serial.println("CLK,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,IN8,OUT0,OUT1,OUT2,OUT3,OUT4,OUT5,OUT6,OUT7"); Serial.println(" R R"); Serial.println(" A0, A1"); Serial.println("D3,D2 A1-A0,B7-B0 C7-C0"); delay(100); digitalWrite(D3,0); } void loop() { int addrPoint; byte data; char fmtStr[20]; for (addrPoint = 0; addrPoint < addrSize; addrPoint++) { // sprintf(fmtStr, "%04X\n", addrPoint); // Serial.print(fmtStr); digitalWrite(D2,0); Serial.print("00 "); printBinary(addrPoint, OUTS); setAddress(addrPoint); printBinary(getData(), INS); Serial.println(); digitalWrite(D2,1); Serial.print("01 "); printBinary(addrPoint, OUTS); printBinary(getData(), INS); Serial.println(); } while(1) {} // halt } void setAddress(int address) { byte highAddr; byte lowAddr; highAddr = address >> 8; lowAddr = address & 0xFF; PORTA = highAddr; PORTB = lowAddr; } byte getData(void) { return PINC; } void printBinary(int address, int base) { int bit; int bitCounter; address = address & 0xFFFF; for (bitCounter = base - 1; bitCounter >= 0; bitCounter--) { bit = (address & (1 << bitCounter)) ? 1 : 0; Serial.print(bit, DEC); } Serial.print(" "); }