hola, buenas tardes,
estoy programando con XC8 en el MPLAB X IDE, el pic es un 16F887 conectado a un DS1307,
el PIC con el DS1307 en el proteus andan, me tira un par de errores pero funciona,
el cristal interno está a 8Mhz
/************** FRECUENCIA DEL OSCILADOR **************
*
* IRCF<2:0>: Internal Oscillator Frequency Select bits
* 111 = 8 MHz
* 110 = 4 MHz (default)
* 101 = 2 MHz
* 100 = 1 MHz
* 011 = 500 kHz
* 010 = 250 kHz
* 001 = 125 kHz
* 000 = 31 kHz (LFINTOSC)
*/
OSCCONbits.IRCF0 = 1;
OSCCONbits.IRCF1 = 1;
OSCCONbits.IRCF2 = 1;
en el main, inicializo el 1307 así
TRISCbits.TRISC3 = 1; /* SDA and SCL as input pin */
TRISCbits.TRISC4 = 1; /* these pins can be configured either i/p or o/p */
SSPSTATbits.SMP = 1; /* Slew rate disabled */
SSPCONbits.SSPEN = 1; /* Enables the serial port and configures the SDA and
* SCL pins as the source of the serial port pins */
SSPCON = 0x28; /* SSPEN = 1, I2C Master mode, clock = FOSC/(4 * (SSPADD + 1)) */
/*
* Velocidad=Fosc/(4*(SSPADD+1))
* SSPADD=(Fosc/(4*Velocidad))-1
* SSPADD=(8000000/(4*100000))-1
*/
SSPADD = 0x13; /* 100Khz @ 8Mhz Fosc */
y más adelante, inicio el pulso de 1Hz desde el 1307 así
for ( unsigned char i=0; i<10; i++ )
__delay_ms(100);
SEN = 1; /* Start condition enabled */
while (SEN); /* automatically cleared by hardware */
/* wait for start condition to finish */
SSPBUF = 0xD0; /* Move data to SSPBUF */
while (BF); /* wait till complete data is sent from buffer */
SSPBUF = 0x07; /* Move data to SSPBUF */
while (BF); /* wait till complete data is sent from buffer */
SSPBUF = 0b00010000; /* Move data to SSPBUF */
while (BF); /* wait till complete data is sent from buffer */
PEN = 1; /* Stop condition enabled */
while (PEN); /* Wait for stop condition to finish */
/* PEN automatically cleared by hardware */
los errores del proteus creo que son por las resistencias de 10k que deben ser reemplazadas por unas pullup, pero funciona, el tema es que en el proto no,
el pulso del 1307 lo mando a un RB y cuando salta la int de flanco asc o desc enciendo o apago un led de acuerdo al flanco del pulso de 1 seg generado por el 1307,
en el proto el cristal de 32768 es un smd, pero eso no creo que afecte,
¿alguna recomendación?
Muchas gracias,
Saludos,