Ejemplo n.º 1
0
def testXBitPiPoRegister():
    from Circuits import XBitPiPoRegister
    from getch import getch
    import time
    import sys
    bitlength = 4
    register = XBitPiPoRegister(length=bitlength)
    print("\nvariable length parallel in parallel out register:")
    data = itot(0, bitlength)
    clock = 0
    char = ''
    while (char != u'q'):
        if char >= u'0' and char <= u'9':
            intdata = ttoi(data)
            shifted = (ord(char) - ord(u'0') - 1)
            intdata ^= (1 << shifted)
            data = itot(intdata, bitlength)
        elif char == u'c':
            clock = logic.Not(clock)
        signal = (data, clock)
        register.setinput(signal)
        output = register.getoutput()
        fmt = (clock, data, output, time.time())
        fmtstr = "Clock:%s Input:%s Output:%s %s\r" % fmt
        sys.stdout.write(fmtstr)
        char = getch()
Ejemplo n.º 2
0
def testDataLatch():
    from Circuits import DataLatch
    latch = DataLatch()
    enabled = 0
    data = 0
    print("Data latch: ")
    while (True):
        answer = raw_input("input (D)ata (E)nable (Q)uit: \n").lower()
        if answer == "q":
            break
        elif answer == "d":
            answer = raw_input("input 1 or 0 for data: \n").lower()
            data = eval(answer)
            latch.setinput((data, enabled))
            print(latch.getoutput())
            data = logic.Not(data)
        elif answer == "e":
            enabled = logic.Not(enabled)
Ejemplo n.º 3
0
def d_latch_vs_dms_latch():
    from getch import getch
    import sys
    from Circuits import DataLatch, MSDataLatch
    latch = DataLatch()
    latch2 = MSDataLatch()
    print("\ndifference between latch, and flipflop")
    data, enabled = 1, 0
    char = ' '
    while (char != u'q'):
        if char == u'2':
            enabled = logic.Not(enabled)
        elif char == u'1':
            data = logic.Not(data)
        latch.setinput((data, enabled))
        latch2.setinput((data, enabled))
        fmt = (data, enabled, latch.getoutput(), latch2.getoutput())
        fmtstr = "\rdata:%s enabled:%s D-Latch:%s MSD-Latch:%s"
        sys.stdout.write(fmtstr % fmt)
        char = getch()
Ejemplo n.º 4
0
def testTFlipflop():
    from Circuits import TFlipFlop
    from getch import getch
    import sys
    flipflop = TFlipFlop()
    t, clock = 0, 0
    print("\nToggle FlipFlop")
    print("")
    char = ""
    while (char != u'q'):
        if (char == u't'):
            t = logic.Not(t)
        elif (char == u'c'):
            clock = logic.Not(clock)
        signal = (t, clock)
        flipflop.setinput(signal)
        q, qn, = flipflop.getoutput()
        fmt = (t, clock, q, qn)
        fmtstr = "\rT:%s clock:%s q:%s qn:%s"
        sys.stdout.write(fmtstr % fmt)
        char = getch()
Ejemplo n.º 5
0
def testXBitSiPoRegister():
    from Circuits import XBitSiPoRegister
    from getch import getch
    import sys
    register = XBitSiPoRegister(length=4)

    print("XBit SiPo register:")
    clock = 0
    data = 0
    char = ""
    while (char != u'q'):
        if (char == u'c'):
            clock = logic.Not(clock)
        elif (char == u'd'):
            data = logic.Not(data)
        signal = (data, clock)
        register.setinput(signal)
        output = register.getoutput()
        fmt = (clock, data, output)
        fmtstr = "\rClock:%s Data:%s Output:%s"
        sys.stdout.write(fmtstr % fmt)
        char = getch()
Ejemplo n.º 6
0
def testCounter():
    from Circuits import Counter
    from getch import getch
    import sys
    counter = Counter(length=8)
    print("\ncounter:")
    print("")
    clock = 0
    enabled = 1
    char = ""
    while (char != u'q'):
        if (char == u'e'):
            enabled = logic.Not(enabled)
        elif (char == u'c'):
            clock = logic.Not(clock)
        signal = (clock, enabled)
        counter.setinput(signal)
        count = counter.getoutput()
        fmt = (enabled, clock, count)
        fmtstr = "\rEnabled:%s Clock:%s Count:%s"
        sys.stdout.write(fmtstr % fmt)
        char = getch()
Ejemplo n.º 7
0
def testJKFlipflop():
    from Circuits import JKFlipFlop
    from getch import getch
    import sys
    flipflop = JKFlipFlop()
    j, k, clock = 0, 0, 0
    print("\nJK-flipflop")
    print("")
    char = ""
    while (char != u'q'):
        if (char == u'j'):
            j = logic.Not(j)
        elif (char == u'k'):
            k = logic.Not(k)
        elif (char == u'c'):
            clock = logic.Not(clock)
        signal = (j, k, clock)
        flipflop.setinput(signal)
        q, qn, = flipflop.getoutput()
        fmt = (j, k, clock, q, qn)
        fmtstr = "\rJ:%s K:%s clock:%s Q:%s Qn:%s"
        sys.stdout.write(fmtstr % fmt)
        char = getch()
Ejemplo n.º 8
0
def testGatedLatch():
    from Circuits import GatedLatch
    latch = GatedLatch()
    enabled = 0
    print("gated s-r latch: ")
    while (True):
        answer = raw_input("Input (S)et (R)eset (E)nable (Q)uit: \n").lower()
        if answer == "q":
            break
        elif answer == "s":
            latch.setinput((1, 0, enabled))
            print(latch.getoutput())
        elif answer == "r":
            latch.setinput((0, 1, enabled))
            print(latch.getoutput())
        elif answer == "e":
            enabled = logic.Not(enabled)