コード例 #1
0
ファイル: dlatch.py プロジェクト: kjcole/LogicCircuits
    def setupGraphics(s):
        n1 = Nand2(s, "N1", s.scale1((50,  0)))   # Upper Nand
        n2 = Nand2(s, "N2", s.scale1((50, 40)))   # Lower Nand
        i1 = Inv(s, "I1", (n2.B.x(-40), n2.B.y(0)))
        i2 = Inv(s, "I2", (s.scale1((5, 25))))
        i1.align(i1.B, n2.B, -10, 0)
        l1 = Latch(s, "L1", s.scale1((90, 12)))

        td = (n1.A.x(-60), n1.A.y())  # terminal D
        tc = (n1.A.x(-60), i2.A.y())  # terminal C
        s.D = Connector(s, "D", td)
        s.C = Connector(s, "C", tc)
        s.Q = Connector(s, "Q", l1.Q.pos)
        s.output = s.Q
        l1.Q.addWire(s.Q)
        s.gates = (i1, i2, n1, n2, l1)

        if s.encapsulated():
            s.D.pos, s.C.pos, s.Q.pos = s.scaleM((0, 8), (0, 32), (20, 20))

        n1.C.addWire(l1.A)    # Wire Nands to the latch
        n2.C.addWire(l1.B)
        s.C.addWire(i2.A)
        i2.B.addWire(n1.B)
        i2.B.addWire(n2.A)
        s.D.addWire(n1.A)
        s.D.addWire((s.D.x(), i1.A.y()), i1.A)  # down then take a right
        i1.B.addWire(n2.B)
コード例 #2
0
ファイル: div2.py プロジェクト: kjcole/LogicCircuits
    def setupGraphics(s):
        el  = ELatch(s, "EL", s.scale1((50, 20)))
        inv = Inv(s, "Inv", (el.D.x(-40), el.D.y(-12)))
        # wire up the feedback loop
        cn1 = (el.Q.x(5),    el.Q.y())
        cn2 = (el.Q.x(5),    inv.y(-20))
        cn3 = (inv.A.x(-15), inv.y(-20))
        cn4 = (inv.A.x(-15), inv.A.y())
        el.Q.addWire(cn1, cn2, cn3, cn4, inv.A)
        inv.B.addWire(el.D)

        tc = (el.C.x(-60), el.C.y())  # terminal C
        tq = (el.Q.x( 60), el.Q.y())  # terminal Q
        s.C = Connector(s, "C", tc)
        s.Q = Connector(s, "Q", tq)
        el.output.addWire(s.Q)
        s.output = s.Q
        s.C.addWire(el.C)
        s.gates = (el, inv)
        if s.encapsulated():
            s.C.pos, s.Q.pos = s.scaleM((0, 32), (20, 20))
コード例 #3
0
ファイル: or1.py プロジェクト: kjcole/LogicCircuits
    def setupGraphics(s):
        s.banner = "Building an OR gate from basic components"
        n1 = Nand2(s, "N1", s.scale1((150, 30))) # Nand Gate
        i1 = Inv(s,   "I1")  # Inverter for n1.A
        i2 = Inv(s,   "I2")  # Inverter for n1.B
        s1 = Swt(s,   "S1")  # Switch feeding input A
        s2 = Swt(s,   "S2")  # Switch feeding input B

        s2.align(s2.B, n1.B, -30,   0)
        i1.align(i1.B, n1.A, -40, -20)  # inverter precedes Nand
        s1.align(s1.B, i1.A, -50,   0)  # line up the gates
        i2.align(i2.B, n1.B, -40,  20)  # inverter precedes Nand
        s2.align(s2.B, i2.A, -50,   0)  # line up the gates

        n1.A.labelQuad = 3              # Label all the connectors
        n1.B.labelQuad = 2
        n1.C.labelQuad = 1
        i1.A.labelQuad = 2              # Inverter
        i1.B.labelQuad = 1
        i2.A.labelQuad = 3              # Inverter
        i2.B.labelQuad = 4
        s1.B.labelQuad = 1              # Switches
        s2.B.labelQuad = 1

        s.gates = (s1, s2, i1, i2, n1)
        s1.B.addWire(i1.A)
        s2.B.addWire(i2.A)
        i1.B.addWire(n1.A)
        i2.B.addWire(n1.B)
        n1.C.addWire( (n1.C.x(30), n1.C.y()))  # tail to see
コード例 #4
0
ファイル: or2.py プロジェクト: kjcole/LogicCircuits
    def setupGraphics(self):
        n1 = Nand2(self, "N1", self.scale1((80, 30)))  # Nand Gate
        i1 = Inv(self,   "I1")  # Inverter for n1.A
        i2 = Inv(self,   "I2")  # Inverter for n1.B
        # external connectorself. Same depth as xor circuit
        i1.align(i1.B, n1.A, -40, -20)  # inverter precedes Nand
        i2.align(i2.B, n1.B, -40,  20)  # inverter precedes Nand
        self.A = Connector(self, "A", ((i1.A.x(-20), i1.A.y())))
        self.B = Connector(self, "B", ((i2.A.x(-20), i2.B.y())))
        self.C = Connector(self, "C", ((n1.C.x( 20), n1.C.y())))
        self.output = self.C       # who is output

        self.gates = (i1, i2, n1)
        self.i1, self.i2, self.n1 = (i1, i2, n1)

        i1.B.addWire(n1.A)
        i2.B.addWire(n1.B)
        self.A.addWire(i1.A)
        self.B.addWire(i2.A)
        n1.C.addWire(self.C)

        if self.encapsulated():  # if encapsulated re-work externals
            self.A.pos, self.B.pos, self.C.pos = self.scaleM(( 0,  5),
                                                             ( 0, 35),
                                                             (20, 20))
コード例 #5
0
ファイル: basics.py プロジェクト: kjcole/LogicCircuits
    def setupGraphics(self):
        self.banner = "Basic components. Switch, Multipulsar, Nand, Inverter"

        n1 = Nand2(self, "N1", self.scale1((50, 30))) # Nand Gate
        i1 = Inv(self, "I1")           # Inverter
        s1 = Swt(self, "S1")           # Switch feeding input A
        m1 = MultPuls(self, "MP1")     # Pulsar feeding input B

        s1.align(s1.B, n1.A, -50, 0)   # line up the gates
        m1.align(m1.B, n1.B, -30, 0)
        i1.align(i1.B, n1.C,  80, 0)   # inverter follows Nand

        n1.A.labelQuad = 2             # Label all connectors
        n1.B.labelQuad = 2
        n1.C.labelQuad = 1
        i1.A.labelQuad = 2
        i1.B.labelQuad = 1

        self.gates = (m1, s1, n1, i1)
        s1.B.addWire(n1.A)
        m1.B.addWire(n1.B)
        n1.C.addWire(i1.A)
        i1.B.addWire( (i1.B.x(30), i1.B.y()))  # tail to see
コード例 #6
0
ファイル: elatch.py プロジェクト: kjcole/LogicCircuits
    def setupGraphics(s):
        dl1 = DLatch(s, "DL1", s.scale1((50, 0)))
        dl2 = DLatch(s, "DL2")
        dl2.align(dl2.D, dl1.Q, 20, 0)

        ei1 = Inv(s, "I3")
        ei1.align(ei1.A, dl1.C, 0, 60)

        td = (dl1.D.x(-30), dl1.D.y())  # terminal D
        tc = (dl1.C.x(-30), dl1.C.y())  # terminal C
        tq = (dl2.Q.x(30), dl2.Q.y())  # terminal Q
        s.D = Connector(s, "D", td)
        s.C = Connector(s, "C", tc)
        s.Q = Connector(s, "Q", tq)
        s.D.addWire(dl1.D)
        s.C.addWire(dl1.C)
        s.C.addWire((s.C.x(), ei1.A.y()), ei1.A)
        ei1.B.addWire((dl2.C.x(-10), dl2.C.y()), dl2.C)
        dl1.Q.addWire(dl2.D)
        dl2.Q.addWire(s.Q)
        s.output = s.Q
        s.gates = (ei1, dl1, dl2)
        if s.encapsulated():
            s.D.pos, s.C.pos, s.Q.pos = s.scaleM((0, 8), (0, 32), (20, 20))