he aqui el codigo, espero me podais ayudar:
int escribe_ds1302(int numero1);//FUNCION
int lee_ds1302(int );//FUNCION
int DATO=0;
int cont=0;
int resultado,numero1,numero2,temp=0;
int local=0;
void main() {
ADCON1=0X07;
TRISB=0;
TRISD=0;
TRISE=0;
TRISC=0;
cont=8;
PORTB=0;
PORTD=0;
PORTE=0;
PORTC=0;
//PORTE BIT0=SCLK
//PORTE BIT1=IO
//PORTE BIT2=RST
numero1=0x8E; //direcciona el registro de control
escribe_ds1302(numero1);
numero1=0x00; //permite futuras escrituras
escribe_ds1302(numero1);
numero1=0x80; //direcciona el registro de escritura segundos
escribe_ds1302(numero1);
numero1=0x35; //direcciona el registro de escritura segundos
escribe_ds1302(numero1);
PORTE.F2=0;//DESABILITA COMUNICACIONES
numero1=0x81; //direcciona el registro de escritura segundos
escribe_ds1302(numero1);
cont=7;
temp=lee_ds1302(numero2);//da lectura al registro de segundos
temp=local;
PORTD=temp;//imprime el registro segundos en portd
fin:
PORTC.F6=1;//CUALQUIER LED PARA VER QUE TODO FUNCIONA OK
goto fin;
}
///////////RUTINA ENVIAR DATO AL DS1302////////
int escribe_ds1302(int valor1)//FUNCION
{
DATO=numero1; //Carga en dato el valor a escribir
asm {
bsf STATUS,RP0 //;Setear IO como salida
bcf TRISE,1 //CONFIGURA COMO SALIDA
bcf STATUS,RP0
bsf PORTE,2 //;Entablar comunicación
ENVIANDO:
bcf PORTE,1 //;Apagar IO
btfsc DATO,0 //;Si DATO,0 es 1, entonces
bsf PORTE,1 //;poner IO en 1
bsf PORTE,0 //;Un Clock
bcf PORTE,0
rrf DATO,F //;Rotar DATO hacia la derecha
decfsz CONT,F //;Decrementa CONT y salta si es 0
goto ENVIANDO ////;Volver si CONT no era 0
movlw 8 //;Redefinir contador
movwf CONT
//;No olvidar resetear comunicación manualmente.
}
return;
} /////////////FIN DE LA FUNCIÓN
///////////RUTINA RECIBIR DATO DEL DS1302////////
int lee_ds1302(int valor2)
{
asm {
bsf STATUS,RP0 // ;Setear IO como entrada
bsf TRISE,1
bcf STATUS,RP0
bsf PORTE,2 //;Entablar comunicación
RECIBIENDO:
bcf DATO,0 // ;Resetear DATO,0
btfsc PORTE,1 // ;Si IO es 1, entonces
bsf DATO,0 // ;poner DATO,0 en 1
bsf PORTE,0 // ;Un Clock
bcf PORTE,0
rlf DATO,F // ;Rotar DATO a la izquierda
decfsz CONT,F // ;Decrementa CONT y salta si es 0
goto RECIBIENDO //;Volver si CONT no era 0
bcf PORTE,2 // ;Terminar comunicación
movlw 7 //;Redefinir contador
movwf CONT
movf DATO,W // ;Enviar DATO recibido a W
movwf local
}
return local;
} /////////////FIN DE LA FUNCIÓN
cual es la diferencia entre mandar un comando o un dato? es decir lo puedo enviar por la misma rutina?