Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1.  
  2. class Circ_SR_Latch(Circuit):
  3.     def __init__(self, inputs, x, y, flip=False):
  4.         super().__init__(inputs, x, y, flip)
  5.  
  6.         n_o1 = Node(DummyNode(), x + 21, y)
  7.         n_o2 = Node(DummyNode(), x + 121, y)
  8.         n_i1 = Node(n_o2, x + 25, y + 150)
  9.         n_i2 = Node(n_o1, x + 100, y + 150)
  10.  
  11.         g1 = Gate_NOR([inputs[0], n_i1], x, y + 25)
  12.         g1.state = True
  13.         g2 = Gate_NOR([n_i2, inputs[1]], x + 100, y + 25)
  14.         g2.state = False
  15.         n_o1.inp = g1
  16.         n_o2.inp = g2
  17.  
  18.         Wire(g1.output, [], n_o1)
  19.         Wire(g2.output, [], n_o2)
  20.         Wire(g1.output, [(x + 50, y + 25), (x + 90, y + 150)], n_i2)
  21.         Wire(g2.output, [(x + 100, y + 25), (x + 45, y + 150)], n_i1)
  22.  
  23.         self.outputs = [n_o1, n_o2]
  24.  
  25. class Circ_Gated_SR_Latch(Circuit):
  26.     def __init__(self, inputs, x, y, flip=False):
  27.         super().__init__(inputs, x, y, flip)
  28.  
  29.         ne = Node(inputs[1], x + 75, y + 285)
  30.         Wire(inputs[1], [], ne)
  31.         and_1 = Gate_AND([inputs[0], ne], x, y + 160)
  32.         and_2 = Gate_AND([ne, inputs[2]], x + 130, y + 160)
  33.         latch = Circ_SR_Latch([and_1.output, and_2.output], x + 15, y)
  34.         self.outputs = latch.outputs
  35.  
  36. class Circ_D_Latch(Circuit):
  37.     def __init__(self, inputs, x, y, flip=False):
  38.         super().__init__(inputs, x, y, flip)
  39.  
  40.         g_n = Gate_NOT([inputs[0]], x - 10, y + 275)
  41.         node = Node(inputs[0], x + 155, y + 365)
  42.         Wire(g_n.nodes[0], [], node)
  43.         latch = Circ_Gated_SR_Latch([g_n.output, inputs[1], node], x, y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement