Exemplo n.º 1
0
class IC_7400:
	"""
	This is a Quad 2 input NAND gate IC
	"""
	def __init__(self):
		self.pins = [None,0,0,None,0,0,None,0,None,0,0,None,0,0,0]
		self.gates = Gates()

	def setIC(self,pin_conf):
		'''
		This method takes a dictionary with key:pin_no and value:pin_value
		'''
		for i in pin_conf:
			self.pins[i] = pin_conf[i]

	def setPin(self, pin_no, pin_value):
		if pin_no<1 or pin_no>14:
			sys.exit("ERROR: there are only 14 pins in this IC")
		self.pins[pin_no] = pin_value

	def run(self):
		output = {}
		output[3] = self.gates.NAND(self.pins[1],self.pins[2])
		output[6] = self.gates.NAND(self.pins[4],self.pins[5])
		output[8] = self.gates.NAND(self.pins[9],self.pins[10])
		output[11] = self.gates.NAND(self.pins[12],self.pins[13])
		if self.pins[7] == 0 and self.pins[14] == 1:
			return output
		else:
			print "Ground and VCC pins have not been configured correctly."
Exemplo n.º 2
0
class IC_741G03:
	'''
	This is a single 2 input NAND gate IC
	'''
	def __init__(self):
		self.pins = [None,0,0,0,None,0]
		self.gates = Gates()

	def setIC(self,pin_conf):
		'''
		This method takes a dictionary with key:pin_no and value:pin_value
		'''
		for i in pin_conf:
			self.pins[i] = pin_conf[i]

	def setPin(self, pin_no, pin_value):
		if pin_no<1 or pin_no>5:
			sys.exit("ERROR: there are only 5 pins in this IC")
		self.pins[pin_no] = pin_value

	def run(self):
		output = {}
		output[4] = self.gates.NAND(self.pins[1],self.pins[2])
		if self.pins[3] == 0 and self.pins[5] == 1:
			return output
		else:
			print "Ground and VCC pins have not been configured correctly."
Exemplo n.º 3
0
class IC_7444:
    '''
	This is an excess-3 gray code to Decimal decoder
	Excess-3 gray code digits are in order of A B C D, where pin 15 = A and pin 12 = D
	'''

    #Datasheet here, http://www.datasheetarchive.com/dlmain/Datasheets-8/DSA-151326.pdf

    def __init__(self):
        self.pins = [
            None, None, None, None, None, None, None, 0, None, None, None, 0,
            0, 0, 0, 0, 0
        ]
        self.gates = Gates()

    def setIC(self, pin_conf):
        '''
		This method takes a dictionary with key:pin_no and value:pin_value
		'''
        for i in pin_conf:
            self.pins[i] = pin_conf[i]

    def setPin(self, pin_no, pin_value):
        if pin_no < 1 or pin_no > 16:
            raise Exception("ERROR: There are only 16 pins in this IC")
        self.pins[pin_no] = pin_value

    def run(self):

        output = {}

        inputlist = []
        for i in xrange(12, 16, 1):
            inputlist.append(self.pins[i])

        invalidlist = [[0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 1], [1, 0, 0, 0],
                       [1, 0, 0, 1], [1, 0, 1, 1]]

        if inputlist in invalidlist:
            raise Exception("ERROR: Invalid Pin configuration")

        output[1] = self.gates.NAND(self.gates.NOT(self.pins[15]),
                                    self.pins[14],
                                    self.gates.NOT(self.pins[13]),
                                    self.gates.NOT(self.pins[12]))

        output[2] = self.gates.NAND(self.gates.NOT(self.pins[15]),
                                    self.pins[14], self.pins[13],
                                    self.gates.NOT(self.pins[12]))

        output[3] = self.gates.NAND((self.pins[15]),
                                    self.pins[14], self.pins[13],
                                    self.gates.NOT(self.pins[12]))

        output[4] = self.gates.NAND(self.pins[15],
                                    self.gates.NOT(self.pins[14]),
                                    self.pins[13],
                                    self.gates.NOT(self.pins[12]))

        output[5] = self.gates.NAND(self.gates.NOT(self.pins[15]),
                                    self.gates.NOT(self.pins[14]),
                                    self.pins[13],
                                    self.gates.NOT(self.pins[12]))

        output[6] = self.gates.NAND(self.gates.NOT(self.pins[15]),
                                    self.gates.NOT(self.pins[14]),
                                    self.pins[13], self.pins[12])

        output[7] = self.gates.NAND(self.pins[15],
                                    self.gates.NOT(self.pins[14]),
                                    self.pins[13], self.pins[12])

        output[9] = self.gates.NAND(self.pins[15], self.pins[14],
                                    self.pins[13], self.pins[12])

        output[10] = self.gates.NAND(self.gates.NOT(self.pins[15]),
                                     self.pins[14], self.pins[13],
                                     self.pins[12])

        output[11] = self.gates.NAND(self.gates.NOT(self.pins[15]),
                                     self.pins[14],
                                     self.gates.NOT(self.pins[13]),
                                     self.pins[12])

        if self.pins[8] == 0 and self.pins[16] == 1:
            return output
        else:
            print "Ground and VCC pins have not been configured correctly. "
Exemplo n.º 4
0
class IC_7442:
    '''
	This is a BCD to Decimal decoder
	BCD Digits are in order of A B C D where pin 15 = A, pin 12 = D
	'''

    #Datasheet here, http://pdf1.alldatasheet.com/datasheet-pdf/view/126658/TI/SN7443.html

    def __init__(self):
        self.pins = [
            None, None, None, None, None, None, None, 0, None, None, None, 0,
            0, 0, 0, 0, 0
        ]
        self.gates = Gates()

    def setIC(self, pin_conf):
        '''
		This method takes a dictionary with key:pin_no and value:pin_value
		'''
        for i in pin_conf:
            self.pins[i] = pin_conf[i]

    def setPin(self, pin_no, pin_value):
        if pin_no < 1 or pin_no > 16:
            raise Exception("ERROR: There are only 16 pins in this IC")
        self.pins[pin_no] = pin_value

    def run(self):

        output = {}

        inputlist = []
        for i in xrange(12, 16, 1):
            inputlist.append(self.pins[i])

        invalidlist = [[1, 0, 1, 0], [1, 0, 1, 1], [1, 1, 0, 0], [1, 1, 0, 1],
                       [1, 1, 1, 0], [1, 1, 1, 1]]

        if inputlist in invalidlist:
            raise Exception("ERROR: Invalid BCD number")

        output[1] = self.gates.NAND(self.gates.NOT(self.pins[15]),
                                    self.gates.NOT(self.pins[14]),
                                    self.gates.NOT(self.pins[13]),
                                    self.gates.NOT(self.pins[12]))

        output[2] = self.gates.NAND(self.pins[15],
                                    self.gates.NOT(self.pins[14]),
                                    self.gates.NOT(self.pins[13]),
                                    self.gates.NOT(self.pins[12]))

        output[3] = self.gates.NAND(self.gates.NOT(self.pins[15]),
                                    self.pins[14],
                                    self.gates.NOT(self.pins[13]),
                                    self.gates.NOT(self.pins[12]))

        output[4] = self.gates.NAND(self.pins[15], self.pins[14],
                                    self.gates.NOT(self.pins[13]),
                                    self.gates.NOT(self.pins[12]))

        output[5] = self.gates.NAND(self.gates.NOT(self.pins[15]),
                                    self.gates.NOT(self.pins[14]),
                                    self.pins[13],
                                    self.gates.NOT(self.pins[12]))

        output[6] = self.gates.NAND(self.pins[15],
                                    self.gates.NOT(self.pins[14]),
                                    self.pins[13],
                                    self.gates.NOT(self.pins[12]))

        output[7] = self.gates.NAND(self.gates.NOT(self.pins[15]),
                                    self.pins[14], self.pins[13],
                                    self.gates.NOT(self.pins[12]))

        output[9] = self.gates.NAND(self.pins[15],
                                    self.pins[14], self.pins[13],
                                    self.gates.NOT(self.pins[12]))

        output[10] = self.gates.NAND(self.gates.NOT(self.pins[15]),
                                     self.gates.NOT(self.pins[14]),
                                     self.gates.NOT(self.pins[13]),
                                     self.pins[12])

        output[11] = self.gates.NAND(self.pins[15],
                                     self.gates.NOT(self.pins[14]),
                                     self.gates.NOT(self.pins[13]),
                                     self.pins[12])

        if self.pins[8] == 0 and self.pins[16] == 1:
            return output
        else:
            print "Ground and VCC pins have not been configured correctly. "