Interfacing DS1307
Moderator: Benj
Interfacing DS1307
Hi,
I am trying to interface real time clock (RTC, i.e. DS1307) with PIC16F877A. I want microcontroller to read the data from RTC and display it in LCD. I also want to add six input switches with microcontroller so that user can modify the data in RTC. I am adding six switches in port A. LCD will be connected in port B. I know that DS1307 can be connected using I2C. DS1307 has 7-bit address 1101000.
Any kind of guidance will be helpful.
I am trying to interface real time clock (RTC, i.e. DS1307) with PIC16F877A. I want microcontroller to read the data from RTC and display it in LCD. I also want to add six input switches with microcontroller so that user can modify the data in RTC. I am adding six switches in port A. LCD will be connected in port B. I know that DS1307 can be connected using I2C. DS1307 has 7-bit address 1101000.
Any kind of guidance will be helpful.
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
Re: Interfacing DS1307
Hi kalim!
Try to have a look here http://www.matrixmultimedia.com/mmforum ... 307#p46580 This could be a good start.
Jorgen..
Try to have a look here http://www.matrixmultimedia.com/mmforum ... 307#p46580 This could be a good start.

Jorgen..
Re: Interfacing DS1307
Hi Jorgen and all,
I looked at your link and found lot of information. Enamul uploaded a file for RTC, I am uploading that file here too. I was lost in RTC_INIT macro. Can anyone explain it to me? Specially, the functions of "send byte, expression" in MI2C function are very confusing to me.
I looked at your link and found lot of information. Enamul uploaded a file for RTC, I am uploading that file here too. I was lost in RTC_INIT macro. Can anyone explain it to me? Specially, the functions of "send byte, expression" in MI2C function are very confusing to me.
- Attachments
-
- RTC_SET_16f877a_V5.fcf
- (118.97 KiB) Downloaded 393 times
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
Re: Interfacing DS1307
Hi again!
Unfortunately, I would have helped, but I am not a specialist in this issue. I gave you only link because I could remember it had been a topic.
Best regard
Jorgen
Unfortunately, I would have helped, but I am not a specialist in this issue. I gave you only link because I could remember it had been a topic.

Best regard
Jorgen
Re: Interfacing DS1307
Jorgen,
I understand. Thank you though. I looked at few programs in that link and I wrote a small program to write time information in DS1307. This is not a whole program to write and read in Real Time Clock (RTC). I am sharing my program here to get some feedback.
Thanks in advance.
I understand. Thank you though. I looked at few programs in that link and I wrote a small program to write time information in DS1307. This is not a whole program to write and read in Real Time Clock (RTC). I am sharing my program here to get some feedback.
Thanks in advance.
- Attachments
-
- RTC_temp.fcf
- (17 KiB) Downloaded 312 times
Re: Interfacing DS1307
Hello,
Before writing the final code, I want to share few information from Real Time Clock (RTC) DS1307 data sheet.
After reseting the RTC, the registers are typically set to 01/01/00 01 00:00:00 which refers to MM/DD/YY DOW HH:MM:SS
Time keeping registers (of RTC) are located from 00h to 06h. In 00h address value of second is stored, in 01h, minutes....... in 06h year. Bit 7 of register 0 (which is CH bit) needs to be '0' in order to enable clock.
Base address of RTC is 1101000 (this is 7 bit). If you want to write data to RTC from master (i.e. microcontroller), you have to add '0' as last bit. So the address becomes 1101000 = 0xD0.
If you want to write any data to RTC, you have to start the communication first. In that case you can select start MI2C module first. Then send this address first. After that you have to send one byte at a time. Every time, master will receive acknowledgement from slave (i.e. RTC).
If anyone has any comment or suggestions, please let me know.
Before writing the final code, I want to share few information from Real Time Clock (RTC) DS1307 data sheet.
After reseting the RTC, the registers are typically set to 01/01/00 01 00:00:00 which refers to MM/DD/YY DOW HH:MM:SS
Time keeping registers (of RTC) are located from 00h to 06h. In 00h address value of second is stored, in 01h, minutes....... in 06h year. Bit 7 of register 0 (which is CH bit) needs to be '0' in order to enable clock.
Base address of RTC is 1101000 (this is 7 bit). If you want to write data to RTC from master (i.e. microcontroller), you have to add '0' as last bit. So the address becomes 1101000 = 0xD0.
If you want to write any data to RTC, you have to start the communication first. In that case you can select start MI2C module first. Then send this address first. After that you have to send one byte at a time. Every time, master will receive acknowledgement from slave (i.e. RTC).
If anyone has any comment or suggestions, please let me know.
Re: Interfacing DS1307
Hello,
I like to share more information about writing data in RTC. At first one need to send RTC address+0 in expression of I2C component macro. You need one variable to return value for acknowledgement.
Second you need to send '0' in order to set pointer of DS1307 register. This information is very important. Then you should send second, min, .... etc one by one. After sending year, you need to stop the I2C macro.
If you like to share your experiences here, you are most welcome.
I like to share more information about writing data in RTC. At first one need to send RTC address+0 in expression of I2C component macro. You need one variable to return value for acknowledgement.
Second you need to send '0' in order to set pointer of DS1307 register. This information is very important. Then you should send second, min, .... etc one by one. After sending year, you need to stop the I2C macro.
If you like to share your experiences here, you are most welcome.
Re: Interfacing DS1307
hello,
I have written the first program that only reads value from DS1307 and display it in LCD. But when it runs, I see following information and does not change.
Time 45/0/0
Date S 45/25/165
I am attaching my flowcode file here, if anyone can help me to fix the problem.
Thanks in advance.
Khan Alim
I have written the first program that only reads value from DS1307 and display it in LCD. But when it runs, I see following information and does not change.
Time 45/0/0
Date S 45/25/165
I am attaching my flowcode file here, if anyone can help me to fix the problem.
Thanks in advance.
Khan Alim
- Attachments
-
- RTC_temp.fcf
- (29.57 KiB) Downloaded 332 times
Re: Interfacing DS1307
Hello all;
I have completed the small project. Everything is working the way I planned. If you have any questions, let me know. Here is the youtube link: http://youtu.be/4UQUBb8BuvU
Best wishes,
Khan Alim
I have completed the small project. Everything is working the way I planned. If you have any questions, let me know. Here is the youtube link: http://youtu.be/4UQUBb8BuvU
Best wishes,
Khan Alim