class IC_7402: ''' This is a Quad 2 input NOR gate IC ''' def __init__(self): self.pins = [None,None,0,0,None,0,0,0,0,0,None,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>14: sys.exit("ERROR: there are only 14 pins in this IC") self.pins[pin_no] = pin_value def run(self): output = {} output[1] = self.gates.NOR(self.pins[2],self.pins[3]) output[4] = self.gates.NOR(self.pins[5],self.pins[6]) output[10] = self.gates.NOR(self.pins[8],self.pins[9]) output[13] = self.gates.NOR(self.pins[11],self.pins[12]) if self.pins[7] == 0 and self.pins[14] == 1: return output else: print "Ground and VCC pins have not been configured correctly."
class IC_7451: ''' This is a dual 2-wide 2-input AND-OR Invert gate ''' #Datasheet here, http://www.unitechelectronics.com/7451-7497data.htm def __init__(self): self.pins = [0, 0, 0, 0, 0, None, 0, None, 0, 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 > 14: raise Exception("ERROR: there are only 14 pins in this IC") self.pins[pin_no] = pin_value def run(self): output = {} output[6] = self.gates.NOR(self.gates.AND(self.pins[2], self.pins[3]), self.gates.AND(self.pins[4], self.pins[5])) output[8] = self.gates.NOR( self.gates.AND(self.pins[1], self.pins[13], self.pins[12]), self.gates.AND(self.pins[11], self.pins[10], self.pins[9])) if self.pins[7] == 0 and self.pins[14] == 1: return output else: print "Ground and VCC pins have not been configured correctly."