# Ebauche de Testeur de CI logiques
# P. Mariano
# Lycée PE Martin
# le 16/11/2023
# Doc Raspberry Pi Pico :  https://webge.fr/dokuwiki/doku.php?id=microc:uc:rp2

from machine import Pin
import time
time.sleep(0.1) # Attente nécessaire pour l'affichage en console

# GPIO
S_E2 = Pin(20, Pin.OUT) # Ecriture sur l'entrée E2 de la porte XOR
S_E1 = Pin(21, Pin.OUT) # Ecriture sur l'entrée E1 de la porte XOR 
E_S = Pin(22, Pin.IN) # Lecture de la sortie S de la porte XOR

# Table de vérité d'une XOR
#    [E2,E1] ->  S
# V0 [0 , 0] ->  0
# V1 [0 , 1] ->  1
# V2 [1 , 0] ->  1
# V3 [1 , 1] ->  0

# Une liste de tuples matérialise la table des vecteurs de test
# Illustration d'une erreur sur le vecteur V0
Vecteurs_XOR = [(0, 0, 0), (0, 1, 1), (1, 0, 1), (1, 1, 0)] 

# Test
print("[E2,E1] -> S ")
for E2, E1, Sa in Vecteurs_XOR: # Sa : sortie attendue
    if E2 == 0 :
        S_E2.off()
    else:
        S_E2.on()
    if E1 == 0 :
        S_E1.off()
    else:
        S_E1.on()

    So = E_S.value() # So : sortie obtenue

    if Sa == So: 
        print(f"[{E2},{E1}] -> {So}")
    else:
        print(f"[{E2},{E1}] -> Erreur")
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
xor1:A
xor1:B
xor1:OUT
S_E2 (20)
S_E1 (21)
E_S (22)