/*
Demonstration of a 4 bit register.
See entry 9 https://blog.jochumzen.com/p/entries.html
Set the DIP switches 5-8 to any combination, say 0101.
Click the clock button to latch
The flip-flops "remembers" 0101
The LED Bars Q3-Q0 show the content of the flip-flops.
Change the DIP switches
The LED continuous to display 0101 until the clock again is clicked.
The component QuadDFlipFlop is also added. Its output is displayed on "Quad Q3-Q0"
It functions the same as the four D flip-flops.
*/
//Library with basic gates
#include <ACELCore.h>
#include <ACELBG.h>
#include <ACELBC.h>
//Create an Arduino board
auto* ard = new ArduinoBoard();
//Define chips
auto* d0 = new DFlipFlop((char*)("D0"));
auto* d1 = new DFlipFlop((char*)("D1"));
auto* d2 = new DFlipFlop((char*)("D2"));
auto* d3 = new DFlipFlop((char*)("D3"));
auto* quadD = new QuadDFlipFlop();
//Add all chips to be emulated here
Chip* chips[] = {
d0,d1,d2,d3,quadD
};
//Add all connections here
ConnectionBase* connections[] = {
// D3-D0 are on pin 2-5, CLK on pin 6. Q3-Q0 are on pins 22-25
new Connection(ard, 2, d3->D),
new Connection(ard, 3, d2->D),
new Connection(ard, 4, d1->D),
new Connection(ard, 5, d0->D),
new Connection(ard, 6, d0->Clock),
new Connection(ard, 6, d1->Clock),
new Connection(ard, 6, d2->Clock),
new Connection(ard, 6, d3->Clock),
new Connection(d3->Q, ard, 22),
new Connection(d2->Q, ard, 23),
new Connection(d1->Q, ard, 24),
new Connection(d0->Q, ard, 25),
// Quad
new Connection(ard, 2, quadD->D[3]),
new Connection(ard, 3, quadD->D[2]),
new Connection(ard, 4, quadD->D[1]),
new Connection(ard, 5, quadD->D[0]),
new Connection(ard, 6, quadD->Clock),
new Connection(quadD->Q[3], ard, 26),
new Connection(quadD->Q[2], ard, 27),
new Connection(quadD->Q[1], ard, 28),
new Connection(quadD->Q[0], ard, 29),
};
//Section 6: Setting up the emulation. No need to change
Emulation emulation = Emulation(ard, chips, sizeof(chips)/2,
connections, sizeof(connections)/2);
void setup() {
Serial.begin(9600); Serial.println(); Serial.println("START");
Serial.println();
emulation.makePrintPin(13, 1);
}
void loop() {
emulation.emulate();
}
D3..D0
CLK
Q3..Q0
Print
Quad Q3..Q0