Hola
es un poco tarde pero mas vale tarde que nunca.
Yo utilizo estas lineas para leer y escrivir un reloj ds1307 y alfinal esta el conversor bcd a bin y a la inversa.
Espero que te sirva. lo estoy usando igual que tu.
un saludo
LEERRELOJ:
I2CREAD PINSDA,PINSCL,%11010000,0, [SEGUNDOS] ;leer los datos de mem. 0,
bcd_to_bin=segundos
gosub conv_to_bin
segundos=bcd_to_bin
I2CREAD PINSDA,PINSCL,%11010000,1,[MINUTOS] ;1,2,..y guardarlos en sus
bcd_to_bin=minutos
gosub conv_to_bin
minutos=bcd_to_bin
I2CREAD PINSDA,PINSCL,%11010000,2,[hora] ;respectivas variables
bcd_to_bin=hora
gosub conv_to_bin
hora=bcd_to_bin
I2CREAD PINSDA,PINSCL,%11010000,4,[DIAM]
bcd_to_bin=diam
gosub conv_to_bin
diam=bcd_to_bin
I2CREAD PINSDA,PINSCL,%11010000,5,[mes]
bcd_to_bin=mes
gosub conv_to_bin
mes=bcd_to_bin
I2CREAD PINSDA,PINSCL,%11010000,6,[ANIO]
bcd_to_bin=anio
gosub conv_to_bin
anio=bcd_to_bin
RETURN
GRAVARRELOJ:
bcd_to_bin=segundos
gosub convert_to_bcd
segundos=bcd_to_bin
I2CWRITE PINSDA, PINSCL,%11010000,0, [SEGUNDOS] ;setear segundos
Pause 10 ;retardo para finalizar grabación
bcd_to_bin=MINUTOS
gosub convert_to_bcd
MINUTOS=bcd_to_bin
I2CWRITE PINSDA, PINSCL,%11010000,1, [MINUTOS] ;setear minutos
Pause 10
bcd_to_bin=HORA
gosub convert_to_bcd
HORA=bcd_to_bin
I2CWRITE PINSDA, PINSCL,%11010000,2, [HORA] ;setear horas
Pause 10
bcd_to_bin=DIAM
gosub convert_to_bcd
DIAM=bcd_to_bin
I2CWRITE PINSDA, PINSCL,%11010000,4, [DIAM] ;setear día mes
Pause 10
bcd_to_bin=MES
gosub convert_to_bcd
MES=bcd_to_bin
I2CWRITE PINSDA, PINSCL,%11010000,5, [MES] ;setear mes
Pause 50
bcd_to_bin=ANIO
gosub convert_to_bcd
ANIO=bcd_to_bin
I2CWRITE PINSDA, PINSCL,%11010000,6, [ANIO] ;setear año
Pause 10
I2CWRITE PINSDA, PINSCL,%11010000,7,[$10] ;control %00010000 para
Pause 10
;encender el led cada 1 seg.
RETURN
conv_to_bin:
select case bcd_to_bin
case 16,17,18,19,20,21,22,23,24,25
bcd_to_bin=bcd_to_bin-6
case 32,33,34,35,36,37,38,39,40,41
bcd_to_bin=bcd_to_bin-12
case 48,49,50,51,52,53,54,55,56,57
bcd_to_bin=bcd_to_bin-18
case 64,65,66,67,68,69,70,71,72,73
bcd_to_bin=bcd_to_bin-24
case 80,81,82,83,84,85,86,87,88,89
bcd_to_bin=bcd_to_bin-30
case 96,97,98,99,100,101,102,103,104,105
bcd_to_bin=bcd_to_bin-36
case 112,113,114,115,116,117,118,119,120,121
bcd_to_bin=bcd_to_bin-42
case 128,129,130,131,132,133,134,135,136,137
bcd_to_bin=bcd_to_bin-48
case 144,145,146,147,148,149,150,151,152,153
bcd_to_bin=bcd_to_bin-54
end select
return
convert_to_bcd:
low_bits=bcd_to_bin//10 'get lsb,same for Bin and BCD
high_bits=bcd_to_bin/10 'get msb
bcd_to_bin=high_bits*16 'convert msb to BCD
bcd_to_bin=bcd_to_bin+low_bits 'add BCD msb and lsb together
return