Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

where to find rtc programs using Dallas DS1307?

Status
Not open for further replies.

weifeng

Junior Member level 1
Joined
Dec 8, 2005
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,497
c18 ds1307

hi,

i need to find an RTC program using DS1307 chip. I am using PIC18F452, MPLAB IDE/C18 compiler. Can any one tell me where can i find it? thanx.
 

VVV

Advanced Member level 5
Joined
Nov 26, 2004
Messages
1,582
Helped
384
Reputation
768
Reaction score
87
Trophy points
1,328
Activity points
19,971
ds1307 and hitech c

I am afraid I do not understand the question.
The DS1307 is the RTC. All you need to do really is use the I2C interface to read/write the register.
 

weifeng

Junior Member level 1
Joined
Dec 8, 2005
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,497
ds1307 c18

hi. thanx for the website link. its the program i m finding. thanx a lot. :)
 

Code Warrior

Full Member level 4
Joined
Dec 30, 2004
Messages
230
Helped
10
Reputation
20
Reaction score
2
Trophy points
1,298
Activity points
1,831
ds1307 pic18f

Hello,
If you are using CCS C compiler you will get sample code for DS1307.

Bye
 

weifeng

Junior Member level 1
Joined
Dec 8, 2005
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,497
program for rtc in c

hi all. reali thanx for all the help given. :)
 

weifeng

Junior Member level 1
Joined
Dec 8, 2005
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,497
programme for i2c ,ds1307

hi,
regarding abt tis website=http://www.sixca.com/micro/pic/ds1307/
the source code in it, i got sum parts of the statements don't quite understand it.
what is the #use
#fuses
#use ????
anyway while trying to interface wif my chip, this part cums out as an error.
so does anyone know how should i modify it?
thanx.
 

darko79

Newbie level 6
Joined
Mar 15, 2005
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,417
c program real time clock ds1307

Hi,
I just now work with DS1307 on my four 7-segment clock project. Here is code. I write it in Hi-tech C for PIC.

first declare:

unsigned char rtcvalue_bin,rtcvalue_bcd,rtcreg;
unsigned char rtensec,rsec,rtenmin,rmin,rtenhour,rhour,rday,rtendate,rdate,rmonth,rtenmonth,rtenyear,ryear;

void rtc_read(unsigned char *rtc_buffer);

Then:

void read_ds(void)
{
unsigned char rtc[8];
rtc_read(rtc); // rtc read subroutine
rsec=(rtc[0]&0x0f); // seconds
rtensec=(rtc[0]>>4);
rmin=(rtc[1]&0x0f); // minutes
rtenmin=(rtc[1]>>4);
rhour=(rtc[2]&0x0f); // hours
rtenhour=(rtc[2]>>4);
rday=(rtc[3]&0x0f); // weekday
rdate=(rtc[4]&0x0f); // date
rtendate=(rtc[4]>>4);
rmonth=(rtc[5]&0x0f);
rtenmonth=((rtc[5]&0b00010000)>>4);
ryear=(rtc[6]&0x0f); // year
rtenyear=(rtc[6]>>4);
}

void rtc_set(unsigned char rtcreg)
{
SEN = 1; // send start bit START
while(SEN); // and wait for it to clear
ACKDT = 0; // acknowledge bit

SSPIF = 0;
SSPBUF = 0xD0; // set device address 0xd0 // write SLAVE ADDRESS
while(!SSPIF); // wait for interrupt
SSPIF = 0; // then clear it.

SSPBUF = rtcreg; // register select rtc WORD ADDRESS
while(!SSPIF); //
SSPIF = 0; //

SSPBUF = rtcvalue_bcd; // write data to rtc DATA 0
while(!SSPIF); // wait for interrupt
SSPIF = 0; // then clear it.

PEN = 1; // send stop bit STOP
while(PEN);
}

void rtc_read(unsigned char *rtc_buffer) // i2c rtc read 8 bytes
{
SEN = 1; // send start bit START
while(SEN); // and wait for it to clear
ACKDT = 0; // acknowledge bit

SSPIF = 0;
SSPBUF = 0xd0; // set device address 0xd0 // write SLAVE ADDRESS
while(!SSPIF); // wait for interrupt
SSPIF = 0; // then clear it.

SSPBUF = 0; // read from address 0 = register 0, rtc WORD ADDRESS - control 1
while(!SSPIF); // wait for interrupt
SSPIF = 0; // then clear it.

RSEN = 1; // send repeated start bit REPEATED START
while(RSEN); // and wait for it to clear

SSPIF = 0;
SSPBUF = 0xd1; // set device address - read WORD ADDRESS - CONTROL 2
while(!SSPIF); // wait for interrupt
SSPIF = 0; // then clear it.

RCEN = 1; // start receiving READ & ACK buffer 0
while(!STAT_BF); // wait for data
rtc_buffer[0] = SSPBUF; // and get it // buffer
ACKEN = 1; // start acknowledge sequence
while(ACKEN); // wait for ack. sequence to end


RCEN = 1; // start receiving READ & ACK buffer 1
while(!STAT_BF); // wait for data
rtc_buffer[1] = SSPBUF; // and get it // buffer
ACKEN = 1; // start acknowledge sequence
while(ACKEN); // wait for ack. sequence to end

RCEN = 1; // start receiving READ & ACK buffer 2
while(!STAT_BF); // wait for data
rtc_buffer[2] = SSPBUF; // and get it // buffer
ACKEN = 1; // start acknowledge sequence
while(ACKEN); // wait for ack. sequence to end

RCEN = 1; // start receiving READ & ACK buffer 3
while(!STAT_BF); // wait for data
rtc_buffer[3] = SSPBUF; // and get it // buffer
ACKEN = 1; // start acknowledge sequence
while(ACKEN); // wait for ack. sequence to end

RCEN = 1; // start receiving READ & ACK buffer 4
while(!STAT_BF); // wait for data
rtc_buffer[4] = SSPBUF; // and get it // buffer
ACKEN = 1; // start acknowledge sequence
while(ACKEN); // wait for ack. sequence to end

RCEN = 1; // start receiving READ & ACK buffer 5
while(!STAT_BF); // wait for data
rtc_buffer[5] = SSPBUF; // and get it // buffer
ACKEN = 1; // start acknowledge sequence
while(ACKEN); // wait for ack. sequence to end

RCEN = 1; // start receiving READ & ACK buffer 6
while(!STAT_BF); // wait for data
rtc_buffer[6] = SSPBUF; // and get it // buffer
ACKEN = 1; // start acknowledge sequence
while(ACKEN); // wait for ack. sequence to end

RCEN = 1; // start receiving READ LAST & NO ACK buffer 7
while(!STAT_BF); // wait for data
rtc_buffer[7] = SSPBUF; // and get it // buffer7
ACKDT = 1; // not acknowledge for last byte

PEN = 1; // send stop bit STOP
while(PEN);
}



In main program you must set up I2C bus and use this to start DS1307:

void main(void)
{
.
.
rtcreg=0x00;
rtcvalue_bcd=0b00000000;
rtc_set(rtcreg);
DelayMs(10);
while(1)
{
.
.
.


IT MUST WORK
 

weifeng

Junior Member level 1
Joined
Dec 8, 2005
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,497
ds1307 i2c c pic examples

hi,
the las part of the program which is to start up I2C bus, the "dot dots" in between and after must add in something rite? what must be added?
 

darko79

Newbie level 6
Joined
Mar 15, 2005
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,417
ds1307+pic+c

Hi,
I wrote you that you need to start RTC before while loop, and in while loop write what you want. And before RTC block set up I2C registers.
 

weifeng

Junior Member level 1
Joined
Dec 8, 2005
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,497
program for the ds1307 real time clock

hi,
i tried the program, but den this:

'SEN' has not been defined
C:\Documents and Settings\user\My Documents\testing.c:30:Error [1101] lvalue required
C:\Documents and Settings\user\My Documents\testing.c:31:Error [1105] symbol 'SEN' has not been defined
C:\Documents and Settings\user\My Documents\testing.c:32:Error [1105] symbol 'ACKDT' has not been defined
C:\Documents and Settings\user\My Documents\testing.c:32:Error [1101] lvalue required
C:\Documents and Settings\user\My Documents\testing.c:34:Error [1105] symbol 'SSPIF' has not been defined
C:\Documents and Settings\user\My Documents\testing.c:34:Error [1101] lvalue required
C:\Documents and Settings\user\My Documents\testing.c:36:Error [1105] symbol 'SSPIF' has not been defined
C:\Documents and Settings\user\My Documents\testing.c:37:Error [1105] symbol 'SSPIF' has not been defined
C:\Documents and Settings\user\My Documents\testing.c:37:Error [1101] lvalue required
C:\Documents and Settings\user\My Documents\testing.c:40:Error [1105] symbol 'SSPIF' has not been defined
C:\Documents and Settings\user\My Documents\testing.c:41:Error [1105] symbol 'SSPIF' has not been defined
C:\Documents and Settings\user\My Documents\testing.c:41:Error [1101] lvalue required
C:\Documents and Settings\user\My Documents\testing.c:44:Error [1105] symbol 'SSPIF' has not been defined
C:\Documents and Settings\user\My Documents\testing.c:45:Error [1105] symbol 'SSPIF' has not been defined
C:\Documents and Settings\user\My Documents\testing.c:45:Error [1101] lvalue required
C:\Documents and Settings\user\My Documents\testing.c:47:Error [1105] symbol 'PEN' has not been defined
C:\Documents and Settings\user\My Documents\testing.c:47:Error [1101] lvalue required
C:\Documents and Settings\user\My Documents\testing.c:48:Error [1105] symbol 'PEN' has not been defined
C:\Documents and Settings\user\My Documents\testing.c:53:Error [1105] symbol 'SEN' has not been defined
C:\Documents and Settings\user\My Documents\testing.c:53:Error [1101] lvalue required
C:\Documents and Settings\user\My Documents\testing.c:54:Error [1105] symbol 'SEN' has not been defined
C:\Documents and Settings\user\My Documents\testing.c:55:Error [1105] symbol 'ACKDT' has not been defined
C:\Documents and Settings\user\My Documents\testing.c:55:Error [1101] lvalue required
C:\Documents and Settings\user\My Documents\testing.c:57:Error [1105] symbol 'SSPIF' has not been defined
Halting build on first failure as requested.

came out as error....
 

NguyenHai

Member level 1
Joined
Jan 18, 2003
Messages
37
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,288
Activity points
519
ds1307 pic c18

Hi,
I have source code for keil complier (C51).
 

mmohamed15

Advanced Member level 4
Joined
Mar 23, 2005
Messages
112
Helped
5
Reputation
10
Reaction score
0
Trophy points
1,296
Activity points
2,116
ds1307 program

there is an application note in dallas web site with code
 

weifeng

Junior Member level 1
Joined
Dec 8, 2005
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,497
ds1307 rtc c program with pic18 hitech

hi,

the source code in dallas i tried already, there are still errors...
 

weifeng

Junior Member level 1
Joined
Dec 8, 2005
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,497
rtc driver source code dallas



hi,

while trying to build my program, i stil face many errors in it...
anyone knows hw shd i change this: void read_clock(byte control_reg) ???

thanx.
 

masud58

Full Member level 2
Joined
May 19, 2002
Messages
129
Helped
13
Reputation
26
Reaction score
9
Trophy points
1,308
Location
Dhaka, Bangladesh
Activity points
780
ds1307 interca code in pic

can some one find error for this code?
use proteus, keil
 

yousafzai

Full Member level 5
Joined
Jun 1, 2006
Messages
244
Helped
15
Reputation
30
Reaction score
8
Trophy points
1,298
Activity points
2,295
ds1307 i2c hi-tech pic it must work

There are some good exmples at MichrochipC.com. It also includes one for real time clock interfacing....
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top