-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
653 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import json | ||
import serial | ||
class IC74Series: | ||
def __init__(self, chip_number, logic_type,n,TruthTable=[],pin_count=14, description=None, pin_config=None): | ||
""" | ||
Initializes a 74 series IC chip. | ||
:param chip_number: The number associated with the IC (e.g., '7400', '74138'). | ||
:param logic_type: Type of logic gate/function the IC performs (e.g., 'NAND', 'Multiplexer'). | ||
:param pin_count: Number of pins on the chip, defaults to 14 for most 74 series ICs. | ||
:param description: Optional description of the IC's function. | ||
:param pin_config: A dictionary mapping each pin to its type (input, output, VCC, ground). | ||
""" | ||
self.chip_number = chip_number | ||
self.logic_type = logic_type | ||
self.pin_count = pin_count | ||
self.inputn = n | ||
self.TruthTable = TruthTable | ||
self.description = description if description else "No description provided." | ||
self.pin_config = pin_config if pin_config else {} | ||
|
||
def set_pin(self, pin_number, pin_type): | ||
""" | ||
Sets the type of a specific pin (input, output, VCC, or ground). | ||
:param pin_number: The pin number (1-based index). | ||
:param pin_type: The type of the pin ('input', 'output', 'VCC', 'ground'). | ||
""" | ||
if 1 <= pin_number <= self.pin_count: | ||
self.pin_config[pin_number] = pin_type | ||
else: | ||
raise ValueError(f"Invalid pin number. This IC has {self.pin_count} pins.") | ||
|
||
def get_pin(self, pin_number): | ||
""" | ||
Returns the type of a specific pin. | ||
:param pin_number: The pin number (1-based index). | ||
:return: The type of the pin ('input', 'output', 'VCC', or 'ground') or 'not configured'. | ||
""" | ||
return self.pin_config.get(pin_number, "not configured") | ||
|
||
def get_details(self): | ||
""" | ||
Returns the details of the IC as a string. | ||
""" | ||
return f"74{self.chip_number} IC - Logic Type: {self.logic_type}, Pins: {self.pin_count}, Description: {self.description}" | ||
|
||
def pin_configuration(self): | ||
""" | ||
Returns a formatted string with the pin configuration. | ||
""" | ||
config_str = f"Pin Configuration for 74{self.chip_number}:\n" | ||
for pin in range(1, self.pin_count + 1): | ||
pin_type = self.get_pin(pin) | ||
config_str += f"Pin {pin}: {pin_type}\n" | ||
return config_str | ||
|
||
def is_standard_pin_count(self): | ||
""" | ||
Checks if the IC has a standard pin count of 14. | ||
""" | ||
return self.pin_count == 14 | ||
|
||
def __str__(self): | ||
return f"74{self.chip_number} ({self.logic_type})" | ||
|
||
def pin_configuration_json(self): | ||
""" | ||
Returns the pin configuration as a JSON string. | ||
""" | ||
config = { | ||
"chip_number": self.chip_number, | ||
"logic_type": self.logic_type, | ||
"pin_count": self.pin_count, | ||
"description": self.description, | ||
"pins": self.pin_config | ||
} | ||
return json.dumps(config) | ||
|
||
def send_pin_configuration(self, uart_port, baudrate=250000): | ||
""" | ||
Sends the pin configuration as a JSON string over UART. | ||
:param uart_port: The UART port (e.g., 'COM3' on Windows or '/dev/ttyUSB0' on Linux). | ||
:param baudrate: The baudrate for UART communication. | ||
""" | ||
json_data = self.pin_configuration_json() | ||
#print("JSON Data to be sent:", json_data) | ||
#raw_bytes = json_data.encode('utf-8') | ||
#hex_bytes = [f"{byte:02x}" for byte in raw_bytes] # Convert bytes to hex | ||
#print("Raw Bytes (Hex) to be sent:", ' '.join(hex_bytes)) # Print hex bytes as a space-separated string | ||
with serial.Serial(uart_port, baudrate, timeout=10000000) as ser: | ||
ser.write(json_data.encode('utf-8')) | ||
print(f"Sent JSON data over UART: {json_data}") | ||
def set_truth_table(self,outputs): | ||
self.TruthTable=binary_number_list(self.inputn,outputs) | ||
|
||
def print_truth_tale(self): | ||
print(f"Chip: {self.chip_number}") | ||
print(f"Logic type: {self.logic_type}") | ||
print("INPUT BITS|OUTPUT BITS") | ||
for entry in self.TruthTable: | ||
print(f" {entry[0]} {entry[1]}") | ||
|
||
def binary_number_list(bits,outputs): | ||
list = [] | ||
bits = int(bits) | ||
for number in range(0,(2**bits)): | ||
bitslist = separate_bits(number,bits) | ||
list.append([bitslist,outputs[number]]) | ||
return list | ||
|
||
def separate_bits(num, n): | ||
bits = [(num >> i) & 1 for i in range(n)] # Extract each bit | ||
return bits[::-1] # Return in correct order | ||
|
||
def find_input_pins(ic): | ||
n = ic.inputn | ||
|
||
inputpins = [] | ||
temp = [] | ||
for pin in range(1,ic.pin_count+1): | ||
print("PIN NUMBER IS: ", pin, ic.get_pin(pin)) | ||
if(ic.get_pin(pin) == "input"): | ||
temp.append(pin) | ||
if len(temp) == n: | ||
inputpins.append(temp) | ||
temp=[] | ||
return inputpins |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Chip Number: 00 | ||
Logic Type: NAND | ||
Number of Inputs: 2 | ||
Description: Quad 2-input NAND gate | ||
Truth Table: [1,1,1,0] | ||
Pin Count: 14 | ||
1: INPUT | ||
2: INPUT | ||
3: OUTPUT | ||
4: INPUT | ||
5: INPUT | ||
6: OUTPUT | ||
7: GND | ||
8: OUTPUT | ||
9: INPUT | ||
10: INPUT | ||
11: OUTPUT | ||
12: INPUT | ||
13: INPUT | ||
14: VCC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Chip Number: 00 | ||
Logic Type: NAND | ||
Number of Inputs: 2 | ||
Description: Quad 2-input NAND gate | ||
Truth Table: [1,1,1,0] | ||
Pin Count: 14 | ||
1: INPUT | ||
2: INPUT | ||
3: OUTPUT | ||
4: INPUT | ||
5: INPUT | ||
6: OUTPUT | ||
7: GND | ||
8: OUTPUT | ||
9: INPUT | ||
10: INPUT | ||
11: OUTPUT | ||
12: INPUT | ||
13: INPUT | ||
14: VCC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Chip Number: 00 | ||
Logic Type: NAND | ||
Number of Inputs: 2 | ||
Description: Quad 2-input NAND gate | ||
Truth Table: [1,1,1,0] | ||
Pin Count: 14 | ||
1: INPUT | ||
2: INPUT | ||
3: OUTPUT | ||
4: INPUT | ||
5: INPUT | ||
6: OUTPUT | ||
7: GND | ||
8: OUTPUT | ||
9: INPUT | ||
10: INPUT | ||
11: OUTPUT | ||
12: INPUT | ||
13: INPUT | ||
14: VCC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Chip Number: 00 | ||
Logic Type: NAND | ||
Number of Inputs: 2 | ||
Description: Quad 2-input NAND gate | ||
Truth Table: [1,1,1,0] | ||
Pin Count: 14 | ||
1: INPUT | ||
2: INPUT | ||
3: OUTPUT | ||
4: INPUT | ||
5: INPUT | ||
6: OUTPUT | ||
7: GND | ||
8: OUTPUT | ||
9: INPUT | ||
10: INPUT | ||
11: OUTPUT | ||
12: INPUT | ||
13: INPUT | ||
14: VCC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Chip Number: 00 | ||
Logic Type: NAND | ||
Number of Inputs: 2 | ||
Description: Quad 2-input NAND gate | ||
Truth Table: [1,1,1,0] | ||
Pin Count: 14 | ||
1: INPUT | ||
2: INPUT | ||
3: OUTPUT | ||
4: INPUT | ||
5: INPUT | ||
6: OUTPUT | ||
7: GND | ||
8: OUTPUT | ||
9: INPUT | ||
10: INPUT | ||
11: OUTPUT | ||
12: INPUT | ||
13: INPUT | ||
14: VCC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Chip Number: 00 | ||
Logic Type: NAND | ||
Number of Inputs: 2 | ||
Description: Quad 2-input NAND gate | ||
Truth Table: [1,1,1,0] | ||
Pin Count: 14 | ||
1: INPUT | ||
2: INPUT | ||
3: OUTPUT | ||
4: INPUT | ||
5: INPUT | ||
6: OUTPUT | ||
7: GND | ||
8: OUTPUT | ||
9: INPUT | ||
10: INPUT | ||
11: OUTPUT | ||
12: INPUT | ||
13: INPUT | ||
14: VCC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Chip Number: 00 | ||
Logic Type: NAND | ||
Number of Inputs: 2 | ||
Description: Quad 2-input NAND gate | ||
Truth Table: [1,1,1,0] | ||
Pin Count: 14 | ||
1: INPUT | ||
2: INPUT | ||
3: OUTPUT | ||
4: INPUT | ||
5: INPUT | ||
6: OUTPUT | ||
7: GND | ||
8: OUTPUT | ||
9: INPUT | ||
10: INPUT | ||
11: OUTPUT | ||
12: INPUT | ||
13: INPUT | ||
14: VCC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Chip Number: 00 | ||
Logic Type: NAND | ||
Number of Inputs: 2 | ||
Description: Quad 2-input NAND gate | ||
Truth Table: [1,1,1,0] | ||
Pin Count: 14 | ||
1: INPUT | ||
2: INPUT | ||
3: OUTPUT | ||
4: INPUT | ||
5: INPUT | ||
6: OUTPUT | ||
7: GND | ||
8: OUTPUT | ||
9: INPUT | ||
10: INPUT | ||
11: OUTPUT | ||
12: INPUT | ||
13: INPUT | ||
14: VCC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Chip Number: 00 | ||
Logic Type: NAND | ||
Number of Inputs: 2 | ||
Description: Quad 2-input NAND gate | ||
Truth Table: [1,1,1,0] | ||
Pin Count: 14 | ||
1: INPUT | ||
2: INPUT | ||
3: OUTPUT | ||
4: INPUT | ||
5: INPUT | ||
6: OUTPUT | ||
7: GND | ||
8: OUTPUT | ||
9: INPUT | ||
10: INPUT | ||
11: OUTPUT | ||
12: INPUT | ||
13: INPUT | ||
14: VCC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Chip Number: 00 | ||
Logic Type: NAND | ||
Number of Inputs: 2 | ||
Description: Quad 2-input NAND gate | ||
Truth Table: [1,1,1,0] | ||
Pin Count: 14 | ||
1: INPUT | ||
2: INPUT | ||
3: OUTPUT | ||
4: INPUT | ||
5: INPUT | ||
6: OUTPUT | ||
7: GND | ||
8: OUTPUT | ||
9: INPUT | ||
10: INPUT | ||
11: OUTPUT | ||
12: INPUT | ||
13: INPUT | ||
14: VCC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Chip Number: 00 | ||
Logic Type: NAND | ||
Number of Inputs: 2 | ||
Description: Quad 2-input NAND gate | ||
Truth Table: [1,1,1,0] | ||
Pin Count: 14 | ||
1: INPUT | ||
2: INPUT | ||
3: OUTPUT | ||
4: INPUT | ||
5: INPUT | ||
6: OUTPUT | ||
7: GND | ||
8: OUTPUT | ||
9: INPUT | ||
10: INPUT | ||
11: OUTPUT | ||
12: INPUT | ||
13: INPUT | ||
14: VCC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Chip Number: 00 | ||
Logic Type: NAND | ||
Number of Inputs: 2 | ||
Description: Quad 2-input NAND gate | ||
Truth Table: [1,1,1,0] | ||
Pin Count: 14 | ||
1: INPUT | ||
2: INPUT | ||
3: OUTPUT | ||
4: INPUT | ||
5: INPUT | ||
6: OUTPUT | ||
7: GND | ||
8: OUTPUT | ||
9: INPUT | ||
10: INPUT | ||
11: OUTPUT | ||
12: INPUT | ||
13: INPUT | ||
14: VCC |
Oops, something went wrong.