forked from tanchou/Verilog
Refactor UART testbench and top-level modules; remove old testbench files, enhance UART communication in top_ultrason_uart, and implement LED control via UART in top_led_uart. Add Python scripts for UART communication and data reading.
This commit is contained in:
30
Semaine 1/Python_UART/led_uart.py
Normal file
30
Semaine 1/Python_UART/led_uart.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import serial
|
||||
import time
|
||||
|
||||
# Ouvre le port série (à adapter si nécessaire)
|
||||
ser = serial.Serial('COM6', 115200, timeout=0.5) # timeout non bloquant
|
||||
|
||||
print("Entrez un chiffre entre 0 et 5 pour toggler une LED.")
|
||||
|
||||
try:
|
||||
while True:
|
||||
user_input = input("> ")
|
||||
if user_input.isdigit() and 0 <= int(user_input) <= 64:
|
||||
value = int(user_input)
|
||||
ser.write(bytes([value])) # envoie en binaire brut
|
||||
print(f"Envoyé : {value} -> {value:08b}")
|
||||
|
||||
# Lecture de la réponse UART (1 octet)
|
||||
response = ser.read(1)
|
||||
if response:
|
||||
led_state = response[0]
|
||||
print(f"État reçu du FPGA : {led_state:08b}")
|
||||
else:
|
||||
print("⚠️ Aucune réponse reçue.")
|
||||
else:
|
||||
print("Veuillez entrer un chiffre entre 0 et 63.")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\nFermeture.")
|
||||
finally:
|
||||
ser.close()
|
Reference in New Issue
Block a user