Hi Oli, On Fri, Feb 18, 2011 at 6:43 PM, Oli Glaser wrote= : > Hi Manu, > > Had a quick glance and saw a couple of problems - doing a Project->Clean > might be a good idea if you haven't already. I almost do a Project->Clean, before flashing the pic, each time. > Are there any more source files besides the MCHP ones referenced? No, that's all. > 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 =A0 =A0 =A0 =A0 PORTBbits.RB7 >> >> void ds1307_write(unsigned char reg, unsigned char data) >> { >> =A0 =A0 =A0 =A0 =A0unsigned char stat; >> >> >> =A0 =A0 =A0 =A0 =A0IdleI2C(); /* wait for an idle bus */ >> =A0 =A0 =A0 =A0 =A0StartI2C(); /* send START bit */ >> =A0 =A0 =A0 =A0 =A0while (SSPCON2bits.SEN); /* wait till START is sent *= / >> =A0 =A0 =A0 =A0 =A0WriteI2C(0xd0); /* DS1307 I2C address */ >> =A0 =A0 =A0 =A0 =A0AckI2C(); /* Slave ACK */ >> =A0 =A0 =A0 =A0 =A0WriteI2C(reg); /* Slave register address */ >> =A0 =A0 =A0 =A0 =A0AckI2C(); >> =A0 =A0 =A0 =A0 =A0WriteI2C(data); /* data */ >> =A0 =A0 =A0 =A0 =A0AckI2C(); >> =A0 =A0 =A0 =A0 =A0StopI2C(); >> =A0 =A0 =A0 =A0 =A0while (SSPCON2bits.PEN); /* wait till STOP is sent */ >> } >> >> void ds1307_read(unsigned char reg, unsigned char *data) >> { >> =A0 =A0 =A0 =A0 =A0unsigned char i; >> >> >> =A0 =A0 =A0 =A0 =A0IdleI2C(); >> =A0 =A0 =A0 =A0 =A0StartI2C(); >> =A0 =A0 =A0 =A0 =A0while (SSPCON2.bits.SEN); > > Dot in between SSPCON2 and bits is wrong, should be SSPCON2bits.SEN Actually a error in copy-paste, while trying to add in spaces instead of ta= bs This is the same as all other SSPCON2bits.SEN as referenced other in the same function. >> =A0 =A0 =A0 =A0 =A0WriteI2C(0xd0); >> =A0 =A0 =A0 =A0 =A0AckI2C(); >> =A0 =A0 =A0 =A0 =A0WriteI2C(0x00); >> =A0 =A0 =A0 =A0 =A0AckI2C(); >> >> >> =A0 =A0 =A0 =A0 =A0StartI2C(); >> =A0 =A0 =A0 =A0 =A0while (SSPCON2bits.SEN); >> =A0 =A0 =A0 =A0 =A0WriteI2C(0xd1); >> =A0 =A0 =A0 =A0 =A0AckI2C(); >> >> =A0 =A0 =A0 =A0 =A0while (!SSPSTATbits.BF) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0LED_PIN =3D 0; >> =A0 =A0 =A0 =A0 =A0} >> =A0 =A0 =A0 =A0 =A0LED_PIN =3D 1 > > No semicolon to end statement above The semicolon also exists, but just got vanished in the process.. >> =A0 =A0 =A0 =A0 =A0*data =3D ReadI2C(); >> =A0 =A0 =A0 =A0 =A0StopI2C(); >> =A0 =A0 =A0 =A0 =A0while (SSPCON2bits.PEN); >> } >> >> #define DS1307_CTL_OUT =A0 =A0 =A0 =A0(1<< =A07) >> #define DS1307_CTL_SQWE =A0 =A0(1<< =A04) >> >> #define DS1307_1Hz =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(DS1307_CTL_OUT | DS13= 07_CTL_SQWE) >> >> void ds1307_init(void) >> { >> =A0 =A0 =A0 =A0 =A0ds1307_write(0x00, 0x00); /* enable oscillator*/ >> =A0 =A0 =A0 =A0 =A0ds1307_write(0x07, DS1307_1Hz); >> } >> >> >> void main(void) >> { >> =A0 =A0 =A0 =A0 =A0TRISB =3D 0x00; >> =A0 =A0 =A0 =A0 =A0TRISD =3D 0x00; >> =A0 =A0 =A0 =A0 =A0TRISE =3D 0x00; >> =A0 =A0 =A0 =A0 =A0ADCON1 =3D 0x0f; >> =A0 =A0 =A0 =A0 =A0LED_PIN =3D 1; /* LED off */ >> >> =A0 =A0 =A0 =A0 =A0lcd_init(); >> =A0 =A0 =A0 =A0 =A0send_cmd(0x0c); /* turn OFF cursor */ >> >> =A0 =A0 =A0 =A0 =A0OpenI2C(MASTER, SLEW_OFF); /* I2C Master */ >> =A0 =A0 =A0 =A0 =A0SSPADD =3D 49; /* 100khz @ 20MHz */ >> >> =A0 =A0 =A0 =A0 =A0ds1307_init(); >> >> =A0 =A0 =A0 =A0 =A0set_cursor(1, 1); /* set cursor to R:1 C:1 */ >> =A0 =A0 =A0 =A0 =A0printf("-- DS1307 --"); >> >> =A0 =A0 =A0 =A0 =A0set_cursor(2, 1); >> =A0 =A0 =A0 =A0 =A0while(1) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ds1307_read(0x00,&val); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printf("S:%d ", val); > > Where is val declared? It's there in main itself.. unsigned char val =3D 0; but went missing >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0LED_PIN =3D ~LED_PIN; /* blink LED */ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0delay250ms(); >> =A0 =A0 =A0 =A0 =A0} >> } > > Additionally, I put the same source here as well. http://202.88.242.108:8000/test/main.c Any other thoughts ? Thanks, Manu --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .