diff --git a/docs/images/ben-eater-unlock-timing.png b/docs/images/ben-eater-unlock-timing.png new file mode 100644 index 0000000..3805c34 Binary files /dev/null and b/docs/images/ben-eater-unlock-timing.png differ diff --git a/unlock-ben-eater-hardware/README.md b/unlock-ben-eater-hardware/README.md index 88a772e..7b76edb 100644 --- a/unlock-ben-eater-hardware/README.md +++ b/unlock-ben-eater-hardware/README.md @@ -13,3 +13,8 @@ but would require changes for other platforms. **NOTE** that this sketch **will not** work on TommyPROM hardware. It is included here to help people with locked chips who are using the Ben Eater design. + +![Unlock timing with Ben Eater Hardware](../docs/images/ben-eater-unlock-timing.png) + +The timing trace shows the tBLC for the bytes of the unlock sequence within 65us, well +within the required 150us in the datasheet. diff --git a/unlock-ben-eater-hardware/unlock-ben-eater-hardware.ino b/unlock-ben-eater-hardware/unlock-ben-eater-hardware.ino index 3beb8b2..9cf8748 100755 --- a/unlock-ben-eater-hardware/unlock-ben-eater-hardware.ino +++ b/unlock-ben-eater-hardware/unlock-ben-eater-hardware.ino @@ -56,17 +56,50 @@ void loop() { // Output the address bits and outputEnable signal using shift registers. -void setAddress(int address, bool outputEnable) { - // Shift the address bits in - shiftOut(SHIFT_DATA, SHIFT_CLK, MSBFIRST, (address >> 8) | (outputEnable ? 0x00 : 0x80)); - shiftOut(SHIFT_DATA, SHIFT_CLK, MSBFIRST, address); +void setAddress(int addr, bool outputEnable) { + // Set the highest bit as the output enable bit (active low) + if (outputEnable) { + addr &= ~0x8000; + } else { + addr |= 0x8000; + } + byte dataMask = 0x04; + byte clkMask = 0x08; + byte latchMask = 0x10; + + // Make sure the clock is low to start. + PORTD &= ~clkMask; + + // Shift 16 bits in, starting with the MSB. + for (uint16_t ix = 0; (ix < 16); ix++) + { + // Set the data bit + if (addr & 0x8000) + { + PORTD |= dataMask; + } + else + { + PORTD &= ~dataMask; + } + + // Toggle the clock high then low + PORTD |= clkMask; + delayMicroseconds(3); + PORTD &= ~clkMask; + addr <<= 1; + } // Latch the shift register contents into the output register. - digitalWrite(SHIFT_LATCH, LOW); - digitalWrite(SHIFT_LATCH, HIGH); - digitalWrite(SHIFT_LATCH, LOW); + PORTD &= ~latchMask; + delayMicroseconds(1); + PORTD |= latchMask; + delayMicroseconds(1); + PORTD &= ~latchMask; } + + // Read a byte from the EEPROM at the specified address. byte readEEPROM(int address) { setDataBusMode(INPUT);