Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Librera bus_I2C.INC
ZONA DE DATOS
CBKLOCK
I2C_ContadorBits
I2C_Dato
I2C_Flags;
ENDC
#Define I2C_UltimobyteLeer I2C_Flags,0
;( I2C_UltimobyteLeer) = 0, NO es el ultimo byte a leer por el maestro.
;( I2C_UltimobyteLeer) = 1, SI es el ultimo byte a leer por el maestro
; la definicin de las lneas SCL y SDA del bus I2C se pueden cambiar segn
las necesidades del hardware.
#Define SCL
PORTA,3
#Define SDA
PORTA,4
;Subrutina SDA_Bajo
SDA_Bajo
Bsf
Status,RP0
Bcf
SDA
Bcf
Status, RP0
Bcf
SDA
Return
;subrutina SDA_Altaimpedancia
SDA_Altaimpedancia
Bsf
Status,RP0
Bsf
SDA
Bcf
Status,RP0
Return
;subrutina SCL_Bajo
SCL_Bajo
Bsf
Status,RP0
Bcf
SCL
Bcf
Status,RP0
Bcf
SCL
Return
;Subrutina SCL_Altaimpedancia
SCL_Altaimpedancia
Bsf
Status,RP0
Bsf
SCL
Bcf
Status,RP0
SCL_Esperanivelalto
Btfss SCL
Goto SCL_Esperanivelalto
Return
;Subrutina I2C_Enviastart
I2C_Enviastart
Call
SDA_Altaimpedancia
Call
SCL_Altaimpedancia
Call
Retardo_4micros
Call
SDA_Bajo
Call
Retardo_4micros
Call
SCL_Bajo
Call
retardo_4micros
Return
;Subrutina I2C_Enviastop
I2C_Enviastop
Call
SDA_Bajo
Call
SCL_Altaimpedancia
Call
Retardo_4micros
Call
SDA_Altaimpedancia
Call
Retardo_4micros
Return
;Subrutina I2C_EnviaByte
I2C_Enviabyte
Movwf
I2C_dato
Movlw
0X08
Movwf
I2C_contadorbits
I2C_Enviabit
Rlf
I2C_dato,f
Btfsc
STATUS,C
Goto
I2C_Enviauno
I2C_Enviacero
Call
SDA_bajo
Goto
I2C_FlancoSCL
I2C_Enviauno
Call
SDA_altaimpedancia
I2C_FlancoSCL
Call
SCL_Altaimpedancia
Call
retardo_4micros
Call
SCL_bajo
Call
Retardo_4micros
Decsz
I2C_contadorbits,f
Goto I2C_Enviabit
Call
SDA_Altaimpedancia
Call
SCL_Altaimpedancia
Call
retardo_4micros
Call
SCL_bajo
Call
Retardo_4micros
Subrutina I2C_leebyte
I2C_Leebyte
Movlw0X08
Movwf
Call
I2C_contadorbits
SDA_Altaimpedancia
I2C_leebit
Call
SCL_altaimpedancia
Bcf
STATUS, C
Btfsc SDA
Bsf
STATUS, C
Rlf
I2C_dato,f
Call
SCL_bajo
Call
retardo_4micros
Decfsz
I2C_cintadorbits,f
Goto I2C_leebit
Btfss I2C_ultimobyteleer
Call
SDA_Bajo
Call
SCL_altaimpedancia
Call
retardo_4micros
Call
SCL_bajo
Call
Retardo_4micros
Movf I2C_dato,w
Return
Dispositivos I2C
Se fabrican multitud de dispositivos que pueden conectarse a un bus I2C.
Entre ellos destacan:
-