PIC 18F4520 + DS1307

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

PIC 18F4520 + DS1307

Postby dum123 » Mon Feb 13, 2012 10:32 am

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
dum123
Freshie
 
Posts: 4
Joined: Mon Feb 13, 2012 10:16 am

Re: PIC 18F4520 + DS1307

Postby ABSF » Tue Feb 14, 2012 12:40 pm

Please show us your "WriteC(a);" subroutine. Was it expecting a 16 bit value?

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: PIC 18F4520 + DS1307

Postby dum123 » Tue Feb 14, 2012 8:37 pm

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;
}
dum123
Freshie
 
Posts: 4
Joined: Mon Feb 13, 2012 10:16 am

Re: PIC 18F4520 + DS1307

Postby shahrul » Tue Feb 14, 2012 9:55 pm

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.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: PIC 18F4520 + DS1307

Postby dum123 » Tue Feb 14, 2012 10:59 pm

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???
dum123
Freshie
 
Posts: 4
Joined: Mon Feb 13, 2012 10:16 am

Re: PIC 18F4520 + DS1307

Postby shahrul » Tue Feb 14, 2012 11:57 pm

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.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: PIC 18F4520 + DS1307

Postby dum123 » Wed Feb 15, 2012 6:17 pm

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
dum123
Freshie
 
Posts: 4
Joined: Mon Feb 13, 2012 10:16 am


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 0 guests

cron