TommyPROM/TommyPROM/PromAddressDriver.cpp
per1234 642f540df2 Move sketch to appropriately named subfolder
The Arduino IDE requires that a sketch be located in a folder of the same name. Although the name of the repository does match the sketch name, when GitHub's popular Clone or download > Download ZIP feature is used to download the contents of a repository the branch/release/commit name is appended to the folder name, causing a mismatch.

When opening a file that does not meet this sketch/folder name matching requirement the Arduino IDE presents a dialog:

The file "TommyPROM.ino" needs to be inside a sketch folder named "TommyPROM".
Create this folder, move the file, and continue?

After clicking "OK" the Arduino IDE currently moves only the file TommyPROM.ino to the new folder, leaving behind the other source files. This causes compilation of the sketch to fail:

TommyPROM-master\TommyPROM\TommyPROM.ino:13:23: fatal error: Configure.h: No such file or directory

 #include "Configure.h"
2018-05-11 00:58:55 -07:00

71 lines
1.9 KiB
C++

#include "PromAddressDriver.h"
#define ADDR_CLK_HI A3
#define ADDR_CLK_LO A4
#define ADDR_DATA A5
void PromAddressDriver::begin()
{
// The address control pins are always outputs.
pinMode(ADDR_DATA, OUTPUT);
pinMode(ADDR_CLK_LO, OUTPUT);
pinMode(ADDR_CLK_HI, OUTPUT);
digitalWrite(ADDR_DATA, LOW);
digitalWrite(ADDR_CLK_LO, LOW);
digitalWrite(ADDR_CLK_HI, LOW);
// To save time, the setAddress only writes the hi byte if it has changed.
// The value used to detect the change is initialized to a non-zero value,
// so set an initial address to avoid the the case where the first address
// written is the 'magic' initial address.
setAddress(0x0000);
}
// Set a 16 bit address in the two address shift registers.
void PromAddressDriver::setAddress(word address)
{
static byte lastHi = 0xca;
byte hi = address >> 8;
byte lo = address & 0xff;
if (hi != lastHi)
{
setAddressRegister(ADDR_CLK_HI, hi);
lastHi = hi;
}
setAddressRegister(ADDR_CLK_LO, lo);
}
// Shift an 8-bit value into one of the address shift registers. Note that
// the data pins are tied together, selecting the high or low address register
// is a matter of using the correct clock pin to shift the data in.
void PromAddressDriver::setAddressRegister(uint8_t clkPin, byte addr)
{
// Make sure the clock is low to start.
digitalWrite(clkPin, LOW);
// Shift 8 bits in, starting with the MSB.
for (int ix = 0; (ix < 8); ix++)
{
// Set the data bit
if (addr & 0x80)
{
digitalWrite(ADDR_DATA, HIGH);
}
else
{
digitalWrite(ADDR_DATA, LOW);
}
digitalWrite(clkPin, HIGH); // Clock in a bit
digitalWrite(clkPin, LOW); // Reset the clock pin
addr <<= 1;
}
}