Page 1 of 1
PIC 18F4520 + DS1307

Posted:
Mon Feb 13, 2012 10:32 am
by dum123
Dear Friends,
I having trying very hardly to get the RTC DS1307 to communicate with PIC 18F4520. The problem that i having is that my LCD display out is the register address not the value that i set from the register.The below attach is my program.Anyone can check for me where i did it wrong in my program???
LCD Display Show:
02:01:00
04/05/06
PIC OSC = 4MHz
I2C Speed = 100KHz
SDA & SCL pull-up resistor = 4.7Kohm
Re: PIC 18F4520 + DS1307

Posted:
Tue Feb 14, 2012 12:40 pm
by ABSF
Please show us your "WriteC(a);" subroutine. Was it expecting a 16 bit value?
Allen
Re: PIC 18F4520 + DS1307

Posted:
Tue Feb 14, 2012 8:37 pm
by dum123
Thank for your reply. This code below is the subroutine of WriteC
- CODE: SELECT_ALL_CODE
void WriteC(char word)
{
PORTD = (word>>4) & 0x0F;
CLCD_RS =1;
CLCD_E=1;
Delay100TCYx(10);
CLCD_E=0;
PORTD = word & 0x0F;
CLCD_RS =1;
CLCD_E=1;
Delay100TCYx(10);
CLCD_E=0;
PORTDbits.RD7 = 1;
}
Re: PIC 18F4520 + DS1307

Posted:
Tue Feb 14, 2012 9:55 pm
by shahrul
It's hard to check other people coding.
Wrong display maybe you wrong reading DS1307 or you wrong converting the BCD number into Decimal.
You can see
Lesson DS1307 and the
header here.
Re: PIC 18F4520 + DS1307

Posted:
Tue Feb 14, 2012 10:59 pm
by dum123
Thank Sharul,
I got some question want to ask you is that your i2c_wait subroutine
while (R_W==1) continue; izit the SSPSTAT read/write bit information???
Re: PIC 18F4520 + DS1307

Posted:
Tue Feb 14, 2012 11:57 pm
by shahrul
dum123 WROTE:Thank Sharul,
I got some question want to ask you is that your i2c_wait subroutine
while (R_W==1) continue; izit the SSPSTAT read/write bit information???
My subroutine modified from others. The R_W is the bit SSPSTAT.
Re: PIC 18F4520 + DS1307

Posted:
Wed Feb 15, 2012 6:17 pm
by dum123
Thank Sharul,
One more question wanted to ask u is about the SSPBUF=(address<<1)&0xFE; .
As we know that the address to write the DS1307 is 0xD0.Put in SSPBUF=(address<<1)&0xFE; the address will be shift 1 to the left AND with 0xfe,
the SSPBUF will get 1010000.May u explain to me why you shift to left 1 bit and AND with 0xfe???
Thank You
_________________________________________________________________________________________________________________________
Problem Solve...thk