Attribute VB_Name = "Module2" Sub I2CInit() RTS 1 'SCL = 1 DTR 1 'SDA = 1 End Sub Sub Depart() RTS 1 ' SCL = 1 DTR 1 ' SDA = 1 DTR 0 ' SDA = 0 'RTS 0 ' SCL = 0 End Sub Sub Arret() 'RTS doit être déjà à 1 RTS 1 ' SCL = 0 DTR 0 ' SDA = 0 'RTS 1 ' SCL = 1 DTR 1 ' SDA = 1 'DELAYUS 50 ' temporisation 50µs End Sub Sub Confirmer() 'RTS 0 ' SCL = 0 DTR 0 ' SDA = 0 mise à "zéro" de la ligne SDA RTS 1 ' SCL = 1 DELAYUS 10 ' Attente 10µs RTS 0 ' SCL = 0 End Sub Sub SansConfirmer() 'RTS 0 ' SCL = 0 DTR 1 ' SDA = 1 mise à "un" de la ligne SDA RTS 1 ' SCL = 1 DELAYUS 10 ' Attente 10µs RTS 0 ' SCL = 0 DTR 0 RTS 1 End Sub Function Sortie(Valeur As Byte) As Boolean Sortie = True ' Initialisation de l'erreur de transmission ValeurBit = 128 ' traitement du bit de poid fort en 1° RTS 0 For n = 1 To 8 If (Valeur And ValeurBit) = ValeurBit Then ' masque de sélection des bits DTR 1 ' SDA=1 transmission d'un "1" Else DTR 0 ' SDA=0 transmission d'un "0" End If RTS 1 ' SCL=1 DELAYUS 10 ' temporisation 10µs RTS 0 ' SCL=0 DELAYUS 10 ' temporisation 10µs ValeurBit = ValeurBit \ 2 ' passage au bit de rang inférieur Next n DTR 1 ' SDA=1 RTS 1 ' SCL=1 DELAYUS 10 ' Boucle de temporisation If CTS = 1 Then Sortie = False ' si SDA=1 alors pas de confirmation du récepteur RTS 0 ' SCL=0 'RTS 1 ' préparation START End Function Function Lecture() As Byte 'RTS 0 ' SCL=0 DTR 1 ' SDA=1 ligne SDA au niveau haut ValeurBit = 128 ' traitement du bit de poid fort en 1° Valeur = 0 ' initialisation variable Valeur For n = 1 To 8 RTS 1 ' SCL=1 DELAYUS 10 ' Boucle de temporisation Valeur = Valeur + ValeurBit * CTS ' Lecture CTS transmis par l'esclave RTS 0 ' SCL=0 DELAYUS 10 ' Boucle de temporisation ValeurBit = ValeurBit \ 2 ' passage au bit de rang inférieur Next n Lecture = Valeur ' affectation de l'octet reçu à la fonction End Function