Hi Manu, Had a quick glance and saw a couple of problems - doing a Project->Clean=20 might be a good idea if you haven't already. Are there any more source files besides the MCHP ones referenced? Anyway, I have marked the things I found in the code below. On 18/02/2011 10:59, Manu Abraham wrote: > Any Ideas, as to what could possibly be wrong in my code ? > > Thanks, > Manu > > > > #include > #include > #include > #include "delay.h" > #include "LCD.h" > > > #pragma config OSC =3D HS > #pragma config PWRT =3D ON > #pragma config WDT =3D OFF > #pragma config LVP =3D OFF > > > #define LED_PIN PORTBbits.RB7 > > void ds1307_write(unsigned char reg, unsigned char data) > { > unsigned char stat; > > > IdleI2C(); /* wait for an idle bus */ > StartI2C(); /* send START bit */ > while (SSPCON2bits.SEN); /* wait till START is sent */ > WriteI2C(0xd0); /* DS1307 I2C address */ > AckI2C(); /* Slave ACK */ > WriteI2C(reg); /* Slave register address */ > AckI2C(); > WriteI2C(data); /* data */ > AckI2C(); > StopI2C(); > while (SSPCON2bits.PEN); /* wait till STOP is sent */ > } > > void ds1307_read(unsigned char reg, unsigned char *data) > { > unsigned char i; > > > IdleI2C(); > StartI2C(); > while (SSPCON2.bits.SEN); Dot in between SSPCON2 and bits is wrong, should be SSPCON2bits.SEN > WriteI2C(0xd0); > AckI2C(); > WriteI2C(0x00); > AckI2C(); > > > StartI2C(); > while (SSPCON2bits.SEN); > WriteI2C(0xd1); > AckI2C(); > > while (!SSPSTATbits.BF) { > LED_PIN =3D 0; > } > LED_PIN =3D 1 No semicolon to end statement above > *data =3D ReadI2C(); > StopI2C(); > while (SSPCON2bits.PEN); > } > > #define DS1307_CTL_OUT (1<< 7) > #define DS1307_CTL_SQWE (1<< 4) > > #define DS1307_1Hz (DS1307_CTL_OUT | DS1307_CTL_SQWE) > > void ds1307_init(void) > { > ds1307_write(0x00, 0x00); /* enable oscillator*/ > ds1307_write(0x07, DS1307_1Hz); > } > > > void main(void) > { > TRISB =3D 0x00; > TRISD =3D 0x00; > TRISE =3D 0x00; > ADCON1 =3D 0x0f; > LED_PIN =3D 1; /* LED off */ > > lcd_init(); > send_cmd(0x0c); /* turn OFF cursor */ > > OpenI2C(MASTER, SLEW_OFF); /* I2C Master */ > SSPADD =3D 49; /* 100khz @ 20MHz */ > > ds1307_init(); > > set_cursor(1, 1); /* set cursor to R:1 C:1 */ > printf("-- DS1307 --"); > > set_cursor(2, 1); > while(1) { > ds1307_read(0x00,&val); > printf("S:%d ", val); Where is val declared? > LED_PIN =3D ~LED_PIN; /* blink LED */ > delay250ms(); > } > } --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .