i2c_rutina_slave:
;////////////////////////////////////////////////////////////
;RUTINAS I2C MODO SLAVE
;////////////////////////////////////////////////////////////
i2c_rutina:
mov #15,w0
mov w0,C_datos
i2_rutina: mov #0,w0
mov w0,cont_int ;cont_int = 1
CALL ESPERA_DIR ;ESCRIBE EN DISPLAY, ESPERA DE COINCIDENCIA DE LA DIRECCIÓN
bset PORTA,#0 ;ENVIADA POR EL MASTER
;ESCRIBE ESPDIR
esp_dirslave:
ledt:
;1. loop de espera de coincidencia de dirección
nop ; ESPERANDO QUE EL MASTER ENVIE LA DIRECCIÓN
; CUANDO SE RECIBE LA DIRECCION CORRECTA
;SALTA A LA INTERRUPCION CUANDO HAY COINCIDENCIA
;con el cont_int = 1
;ESCRIBE DIRI2C EN DISPLAY
mov cont_int,w6
mov #1,w4 ;es PRIMERA interrupcion
xor w4,w6,w4 ;cont_int es UNO??
BTSS SR,#1 ;SR, 1 DA UNO SI SON IGUALES
bra esp_dirslave ;NO, SIGUE ESPERANDO DIRECCION CORRECTA
bra dir_ok ;SI,DIRECCION CORRECTA
dir_ok: CALL DIR_OK ;ESCRIBE EN DISPLAY
CALL TPO_RET_T23_2 ;RETARDO DE 1.2 SEG
call RET_T23_GEN
sendd_dat: bclr I2C1CON,#SCLREL
CALL TPO_RET_T23_1 ;RETARDO DE 1.2 SEG
call RET_T23_GEN
;mov #15,w0
onledw: mov C_datos,w0 ;ENVIA DATO AL MASTER
mov w0,I2C1TRN
bset I2C1CON,#SCLREL
bclr PORTA,#0
CALL TPO_RET_T23_1 ;RETARDO DE 1.2 SEG
call RET_T23_GEN
mov cont_int,w6
mov #2,w4 ;es segunda interrupcion
xor w4,w6,w4 ;cont_int es UNO??
BTSS SR,#1 ;SR, 1 DA UNO SI SON IGUALES
bra bfull ;NO, SIGUE ESPERANDO DIRECCION CORRECTA
bra txx_ok ;SI,DIRECCION CORRECTA
txx_ok: CALL TX_OK ;ESCRIBE EN DISPLAY
bfull: btsc I2C1STAT,#TBF ;BIT INDICADOR DE TRANSM COMPLETA
bra bfull
; bclr I2C1CON,#SCLREL
CALL TPO_RET_T23_3 ;RETARDO DE 1.26 SEG
call RET_T23_GEN
;bra onledQ
bclr PORTA,#0
bset PORTA,#0
onledQ:
esp_ack: mov cont_int,w6
e_ack: mov #3,w4 ;es TERCERA interrupcion
xor w4,w6,w4 ;cont_int es DOS??
BTSS SR,#1 ;SR, 1 DA UNO SI SON IGUALES
bra esp_ack
; bra onledQ ;NO
bra rx_ack1 ;SI
rx_ack1: CALL ES_ACK
inc C_datos
mov #2,w0
mov w0,cont_int
bra sendd_dat