Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Using a PIC microcontroller to interface with a DS1302 real time clock

Status
Not open for further replies.
Where does the code look like I'm clearing the whole register.
On the other note, I'm not aware of the ability to change the register content without stopping the clock. I probably never want to stop the clock. I don't recall reading anything about the datasheet whether I have to stop the clock before modifying the contents before they change again.
 
Shouldn't

writebyte(WRITESEC, current_time & (0xfe << 7));

be

writebyte(WRITESEC, current_time & 0x7f);

Mike.
 
I think they are the same. However, your function call is more efficient since there is one less operation. My function call included an extra operation of shifting the 0 in bit 0 to the left seven times.
 
0xfe shifted left 7 times is 0x7f00, I assume WRITESEC requires a byte and therefore it will get passed zero.

Mike.
 
You're still writing over the seconds register no matter how you figure it. You should write the seconds last and let it run. It does all the MDY calcs on its own till year 2100. Are you trying to make it a stopwatch?
 
I'm not trying to make it a stopwatch. Once I set it, I'm probably setting it for good. Using it as a timestamp.
 
Isn't the best way to use burst mode then the registers all get updated at the same time - once the 8th register is written.

Or, write the seconds first. As long as the value written is not 59 then there is no chance of the minutes/hours etc. rolling over during the update.

Mike.
 
It's not that it is faster. Burst mode has the advantage that none of the registers are written until you write the eight one, therefore ensuring that a register can't rollover during the update.

Alternatively, writing the seconds register first with a value other than 0x59 will make sure that rollover can't happen during the update.

Mike.
 
hi,
I downloaded the attached asm file from the web yesterday.
Recently got a couple of DS1307's, used the asm file as a quick test with a 16F628A, worked OK.

Time set/read is via RS232.

I will re-search the web so I can credit the author..:)

EDIT:
The full description is here:
https://www.electro-tech-online.com/custompdfs/2008/01/AN3921.pdf
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top