home *** CD-ROM | disk | FTP | other *** search
- ;╔══════════════════════════════════════════════════════════════════════════╗
- ;║ Routine de gestion du bus I2C de Philips ║
- ;║ Dévelloppement et réalisation : ADAM Etienne (c) 1994 ║
- ;╚══════════════════════════════════════════════════════════════════════════╝
- ; ┌──────────────┬───────────┬───────────┬──────────────────────────────────┐
- ; │ Nom │ Entree │ Sortie │ Remarques │
- ; ├──────────────┼───────────┼───────────┼──────────────────────────────────┤
- ; │ StartI2C │ Néan │ Néan │ Place une condition de départ sur│
- ; │ │ │ │ le bus I2C. Les broches utilisées│
- ; │ │ │ │ sont définies par SCL et SDA │
- ; ├──────────────┼───────────┼───────────┼──────────────────────────────────┤
- ; │ StopI2C │ Néan │ Néan │ Condition de fin sur le bus I2C │
- ; ├──────────────┼───────────┼───────────┼──────────────────────────────────┤
- ; │ SendByteI2C │ A = byte │ Néan │ Envoye le contenu de l'accu par │
- ; │ │ │ │ le bus I2C. │
- ; │ │ │ │ Si le device n'acquitte pas, │
- ; │ │ │ │ le bit Carry est positionné. C=1 │
- ; │ │ │ │ ! Le régistre R7 est modifié ! │
- ; ├──────────────┼───────────┼───────────┼──────────────────────────────────┤
- ; │ RecByteI2C │ Néan │ A = byte │ Lit un byte par le bus I2C et │
- ; │ │ │ │ renvoye la valeur dans l'accu │
- ; │ │ │ │ ! Le régistre R7 est modifié ! │
- ; ├──────────────┼───────────┼───────────┼──────────────────────────────────┤
- ; │ AckI2C │ Néan │ Néan │ Envoye un bit d'acquittement │
- ; └──────────────┴───────────┴───────────┴──────────────────────────────────┘
- ;
- ; EEPROM EQU 10100000B ; ADRESSE DE BASE D'UNE X2404
-
- SDA EQU 0B3H ; (pin 13)
- SCL EQU 0B2H ; (pin 12)
-
- StartI2C SETB SCL
- SETB SDA
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- CLR SDA
- NOP
- NOP
- NOP
- NOP
- NOP
- CLR SCL
- JB SCL,$
- NOP
- RET
-
- SendBitI2C MOV SDA,C
- NOP
- NOP
- SETB SCL
- SendWS JNB SCL,SendWS ; ATTEND FIN DE WAIT STATE DEVICE
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- CLR SCL
- NOP
- SETB SDA
- NOP
- RET
-
- ReceiveBitI2C MOV A,#0
- SETB SCL
- RecWS JNB SCL,RecWS ; ATTEND FIN WAIT STATE DEVICE
- NOP
- MOV C,SDA
- RLC A ; lit 2 fois la ligne SDA
- MOV C,SDA
- RLC A
- CLR C ; met le Carry = 0 si bit = 0
- CLR SCL
- NOP
- JZ FinReceiveBit
- SETB C ; met le carry = 1 si bit = 1
- FinReceiveBit RET
-
- StopI2C CLR SDA
- NOP
- NOP
- NOP
- SETB SCL
- StopWS JNB SCL,StopWS ; ATTEND FIN WAIT STATE DEVICE
- NOP
- NOP
- NOP
- NOP
- NOP
- SETB SDA
- NOP
- NOP
- NOP
- NOP
- NOP
- RET
-
- SendByteI2C MOV R7,#8
- SbI2C RLC A
- LCALL SendBitI2C
- DJNZ R7,SbI2C
- LCALL ReceiveBitI2C
- RET
-
- RecByteI2C MOV R7,#8
- MOV A,#0
- RbyteI2C PUSH ACC
- LCALL ReceiveBitI2C
- POP ACC
- RLC A
- DJNZ R7,RbyteI2C
- RET
-
- AckI2C CLR C
- ACALL SendBitI2C
- RET
-
-