TROUBLE FINDING INFO ON USING DS1307 - Page 1
Forum section: electronics / beginners

author: neko efecktz
author_rank: Regular Contributor
timestamp: August 07, 2017, 11:39:44 pm
content: THIS IS A RE-POST.I first uploaded this post about 2 months ago but received no replies.Had plenty of views but no replies.I have been away for a month with my family and am now ready to tackle this problem again.ORIGINAL POST FOLLOWS.Good afternoon every one.For a couple of weeks now I have been trying to download a workable code for PIC16F877A and LCD to set and display a DS1307 RTC.I'm using PIC16F877A because that is what I have.Not working at it full time.I am using MPLAB and am still basically a beginner.A lot of code on line is written in micro C or some other language called ASSY. Actually I know what ASSY is but I don't want to learn that as well as C.I use MPLAB because it works with PicKit 3I use Pickit 3 Because it works with MPLAB,I use PIC's because they work with MPLAB and Pickit 3if you get the way I've drifted so far. Quote Henry Blake (M*A*S*H)I managed to find some code written in MPLAB C and looked like it might get me started.I downloaded the code that included i2c.h RTC.h & RTC.CI added my own LCD Display Code.As can be seen i2c.h has Processor: PIC32MXDoes that mean this version is no good for PIC16F877A or just has some features that are not available in PIC16F877A but should still work.Where can I find the file i2c_legacyI'm not sure where I found the code.I have tried to find it again to add links to this post but it eludes me for now.i2c.h has/*******************************************************************************FileName: i2c.hProcessor: PIC32MXCompiler: Microchip MPLAB XC32 v1.00 or higherCopyright © 2008-2009 released Microchip Technology Inc. All rightsreserved.*/#ifndef _I2C_H_#define _I2C_H_#include <xc.h>#include <GenericTypeDefs.h>#ifndef _PLIB_DISABLE_LEGACY#include <peripheral/legacy/i2c_legacy.h> // Legacy definitions, do not use#endifRTC.h has/** File: RTC.h* Author: B.BINDU* ST Number: 206017553* Created on 03 May 2013, 1:26 PM*/#include <xc.h>RTC.C has/** File: RTC.c* Author: Student Companion SA:www.studentcompanion.co.za* Real Time Clock Using DS1307 on I2C Bus* To simulate in Proteus, The I2C debugger must be connected on the I2C Bus.*/#include <xc.h>#include "LCD_PORTS_V2.h" // my own LCD Display code#include "RTC.h"#include <stdio.h>#include <stdlib.h>#include "i2c.h"I am unable to find i2c_legacy.h online.I have tried to find it in MPLABs download site but nothing obvious comes up.If anyone can help me out It would be appreciated.Thank you.BILL.

author: rcowboy78
author_rank: Contributor
timestamp: August 08, 2017, 12:00:38 am
content: If you posted that as your first post 2 months ago I can see why no one has helped you. You obviously haven't done any leg work, and no one is going to help you if you haven't. First of all, your not going to be able to use a 32MX's code with a 16F, all of the pins are different and many other things such as timing, etc. 2nd, your going to have to use the XC8 compiler as I believe the 16F is a 8-bit chip.Your going to have to start reading some data sheets, and start learning to code in C. Universities have courses on this stuff that last for months, and it's not going to be something that you pick up in a couple of nights.Most of the LCD's data sheets comes with the setup code for initializing it so that you can get them up and running via parallel, SPI, I2C, or whatever it may be.My other suggestion would be to also check out the microchip forum.Sorry if i'm sounding harsh, I'm not trying to be.

author: neko efecktz
author_rank: Regular Contributor
timestamp: August 08, 2017, 12:46:55 am
content: rcowboy78No offence taken.I had already reconfigured the the code to use a PIC16F877AInputs, Outputs, LCD Display.Getting a massive amount of errors that I think relate to the missing header file.My main problem is that I am unable to findi2c_legacy.honline.I have tried to find it in MPLABs download site but nothing obvious comes up.I believe once I find this elusive file most of my problems will be solved.That is if it works with a PIC16F877AApart from that I will as you say read as mush as i can on the subject and have another go at it from ground up.ThankyouBILL.

author: alm
author_rank: Super Contributor
timestamp: August 08, 2017, 01:20:04 am
content: Go find I2C sample code that was actually written for the micro-controller and compiler you are using. Adapting some generic I2C code to work with the DS1307 with help of the datasheet will likely be much easier for a newbie than porting code between micro-controller families.

author: JoeO
author_rank: Frequent Contributor
timestamp: August 08, 2017, 01:21:16 am
content: Did you try to search for i2c_legacy.h ?It was in the second line when I searched.https://github.com/balazsracz/mr-misc/blob/master/pic32/includes/peripheral/legacy/i2c_legacy.h

author: rcowboy78
author_rank: Contributor
timestamp: August 08, 2017, 02:17:05 am
content: Neko,The other issue that I see that your going to have is that you are using 2 different devices on the same protocol. I am not an ECE or an embedded systems expert, I am sure this can be programmed around, but I would suggest using the LCD in parallel via either 8-bit mode, or 4 bit mode while your clock is ran on I2C. 2 devices on the same data lines are going to cause you problems unless they can be multiplexed or something. You can do as I suggested, or you can get another chip with 2 I2C ports. Your PIC16F877A only has 1. Might as well make it easier for yourself.Maybe someone will correct me if I'm wrong about the above, as I don't do a ton of embedded stuff, but I've done enough to get myself in trouble.Guess I need to correct myself here, looks like you can run multiple slaves on I2C. Found a good paper by Ti on it.http://www.ti.com/lit/an/slva704/slva704.pdf

author: neko efecktz
author_rank: Regular Contributor
timestamp: August 08, 2017, 04:54:30 am
content: rcowboy78I'm not sure how you came to the conclusion I was going to run the clock and LCD on the same data lines.The LCD will be running from Port D while the clock is running on the I2c port of port C.The LCD is running in 4 bit mode.Joe0I had found thehttps://github.com/balazsracz/mr-misc/blob/master/pic32/includes/peripheral/legacy/i2c_legacy.hyou recomended I look atIt has a include to another file#include <peripheral/int.h>How many layers of includes can you use.almyou recommendedQuoteThis is where I started and got nowhere fast.I spent hours trying to find something that looked like a complete code but there seems to be bits missing from that code supplied or missing header files etc.When I first started out about a year ago I was able to, once guided in the right direction, create lcd driver and then I was able to do analog inputs etc.The clock is not important for my current project but it would be nice to be able to build it into other future projects.Google Chrome search engine is not selective enoughSEARCH FOR... ds1307 PIC16F877AUsually gives me any clock chip used with any PIC programmed with any programmer in any language. MicroC, ASSY, even found a full working version? in HEX.No idea where anything is connected. just code.if i add MPLAB into the search field I wind up with a lot more rubbish to filter through.I haven't given up on being able to get a clock working but was hoping to find a simple working code that I could adapt.Thanks for your help and suggestions

author: CJay
author_rank: Super Contributor
timestamp: August 08, 2017, 10:21:33 am
content: I have code, in C, written for 18F4550, should be fairly easy to change.PM me

author: neko efecktz
author_rank: Regular Contributor
timestamp: August 08, 2017, 10:26:51 am
content: CJayAre you able to attach the codeThankyouBILL/

author: CJay
author_rank: Super Contributor
timestamp: August 08, 2017, 10:40:44 am
content: Quote from: neko efecktz on August 08, 2017, 10:26:51 amAh, my bad, it's written for MPLABX/XC8 and is designed to drive a TM1638 to display the time held in the DS1307, it's proof of concept code (I.E. it sets up the DS1307 with a fixed time and then reads it before sending it to the display) so you'd need to add LCD routines, time setting routines and generally make it suitable for your needs but it does work.Not really prepared to make it public (though anyone who asks could have a copy) as it's not something I want to have to support forever but if you'd like a copy i can PM it later?

author: alm
author_rank: Super Contributor
timestamp: August 08, 2017, 11:58:38 am
content: Quote from: neko efecktz on August 08, 2017, 04:54:30 amTry to find code that was written for the same compiler and micro family that you are using. And I was suggesting finding sample code that does just the I2C master part. Something likethismight work. Search terms: pic16 xc8 i2c sample code. The DS1307 part you might have to code yourself from the datasheet. This is in my opinion an absolute bare minimum skill for embedded development.If that is too complicated, then maybe something easier like Arduino might be a better solution? That should provide more hand-holding and there will be more sample code available from the likes of Adafruit.

author: rcowboy78
author_rank: Contributor
timestamp: August 08, 2017, 03:30:27 pm
content: QuoteSorry, just from the way you wrote the OP it sounded like that was what you were going to do. You didn't mention anything about how you were trying to program the LCD, so I assumed thats what it was.But you can to do both using I2C from the little bit of reading that I have done.

author: StillTrying
author_rank: Super Contributor
timestamp: August 08, 2017, 03:50:52 pm
content: By the time you've got someone else's code working you could set up the PIC16F877A's I2C, and the DS1307's registers yourself.

author: tooki
author_rank: Super Contributor
timestamp: August 08, 2017, 10:58:48 pm
content: FWIW, I'd ditch the DS1307 and use the DS3231 instead, unless cost (via official distributors) is a huge issue. It's far more accurate, and doesn't need external components.