import machine from machine import Pin import utime CP = Pin(12, Pin.OUT) CE = Pin(13, Pin.OUT) PL = Pin(14, Pin.OUT) Q7 = Pin(15, Pin.IN) data=[] p18=Pin(18, Pin.OUT) p18.on() # 禁用时钟 CE.on() # 接收外部信号到芯片 PL.off() # 给1毫秒时间让信号传输进芯片,防止锁定太快 utime.sleep(0.001) # 锁定信号数据 PL.on() # 启用时钟 CE.off() # 数据长度 74HC165级联数*8 data_len=2*8 for i in range(data_len): # 读取当前串口信号 data_tmp=Q7.value() data.append(data_tmp) # 给时钟发射一个脉冲,准备下一位串口信号 CP.on() CP.off() print(data) # [1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]