Step 10 : Software Write Function
Here is the C function that outputs the 6 write sequence to the control box.
set_box(int data, int box){
// set_box function by Hill Robertson
//
// This function sends the 6 writes for each parallel port instruction
// to control (currently) 40 8-circuit Christmas light SSR controller
// boxes. The box and bank data are selected and then the write sequence
// begins.
int bank;
int bankbox;
if(box>=1&&box<=8){ bank=8; bankbox=box-1; }
if(box>=9&&box<=16){ bank=16; bankbox=box-9; }
if(box>=17&&box<=24){ bank=32; bankbox=box-17; }
if(box>=25&&box<=32){ bank=64; bankbox=box-25; }
if(box>=33&&box<=40){ bank=128; bankbox=box-33; }
// base=0x378 for first parallel port base address
// control=base+2 for first parallel port control address
outb(data, base); // Write 1:
// Outputs data byte (D0-D7) on pins 2-9
// of parallel port
outb(0, control); // Write 2:
// Outputs a 1 (high) on C0 and C1
// (pins 1 and 14) since they are inverted
// without changing any states on the data pins
outb(1, control); // Write 3:
// Outputs a 0 (low) on C0 and a 1 (high) on
// C1 since they are inverted. Again, not
// changing any states on the data pins
outb(bankbox+bank, base); // Write 4:
// Outputs the steering (addressing) data on
// the data pins
outb(3, control); // Write 5:
// Outputs a 0 (low) on both C0 and C1
// since they are inverted
outb(1, control); // Write 6:
// Outputs a 0 (low) on C0 and a 1 (high) on
// C1 since they are inverted. Again, not
// changing any states on the data pins
}
Anytime lights need to be turned on or off, this function is called. For example, let's say we want the 2nd, 4th, and 5th light circuits on box 2 to come on. We simply call the function with the following code:
set_box(26,2);The 26 is the binary equivalent of 00011010. Looking at this binary code from right to left, you'll notice light circuits 2,4, and 5 are 1 (high) turning them ON. The second parameter "2" indicates the SSR circuit box number.