PIC16F877A - DS1302 RTC - LCD DISPLAY - Page 1
Forum section: electronics / beginners

author: neko efecktz
author_rank: Regular Contributor
timestamp: April 25, 2017, 12:39:23 am
content: Good Morning everyone.I am on the scrounge for some help on a current project I am working on.It has been an on going pic project for about a year.Don't get me wrong, I am not working on it all of the time and sometimes take a looong break of a couple of months.Basically to clear my head and to do other things.I'm also playing about with a Raspberry Pi 3.64 years old, still working 10 hours a day on night shift.Only started "C" programming about a year ago.Only a couple of projects done but I'm still learning.Most people on this forum have been a great help, and I have made a few minor contributions myself.The project is basically a power supply with Micro controller monitoring many of it's performance parameters.I would like to add a clock to it if there is enough space left in the chip.I am using MPLAB Ver 2.10My chip is PIC16F877AUsing a 1602 generic LCD display. May change to a 1604 or 2004 display before committing to making the front panel for the case.I bought some DS1302 RTC modules on line($1.00 each)(don't want to wast them)and I now find that there are big differences between DS1302 and DS1307 RTC modulesI didn't realize that the DS1032 is not I2C compatable. Didn't look up the specs.Most of the sample code I have found is either for DS1307 or written for some other compiler or pic18xxxx chip or worse still in ASSY. (shudder)Even the sample code is not always complete.One I found requires a couple custom header files, and some others just have snippets of the code and no information on how to connect up switches etc.(look at what I've made but I'm not giving away how to do it.)Some are OK to look at but I will need to go over the code with a fine tooth comb before starting. If I can find them again. some are Picture files that would need to be re-typed.Never thought to save them when I first found them.I am thinking of using analog switching ADKEY. Just to save the IO pins of ports C and D.I have Ports A & E set up as analog input. only using 4 analog inputs at the moment.I would like to first do the Code as a stand alone module then incorporate it into the PSU program.Thank you.BILL.

author: Ian.M
author_rank: Super Contributor
timestamp: April 25, 2017, 01:47:32 am
content: The DS1302 has a SPI interface with a single bidiretional data pin. You've got three choices - either bit-bang the interface using two output pins for CE and SCLK, and for I/O swap a pin between output and input modes as required, or use the hardware MSSP module with a 10K resistor from SDO to SDI so a single bidirectional dataline connected to SDI can be used, or get a DS1307 RTC module so you can use I2C.Due to your very old choice of PIC, finding sample code that can be ported may be difficult. Its componded by the fact that unlike standard midrange parts like your PIC, the PIC18 and PIC16F1xxx ranges have code-accessible LAT registers for each port and their use when bit-banging stuff is strongly advised to avoid glitches and un-commanded changes of other pins on the same port. To avoid problems bit-banging pins on a midrange PIC, the code has to be specially written to work around their limitations. SeeRMW and solutions for iton the Microchip forum.TLDR: expect to have to write your own code for this MCU/RTC combo.

author: neko efecktz
author_rank: Regular Contributor
timestamp: April 25, 2017, 02:11:54 am
content: IAN.Thanks for your reply.I would probably be better off buying some DS1307 modules instead of using the DS1302.There is a bit more info on DS1307 - PIC16F877A combo on line.I don't want to change the micro as I have 3 pcs PIC16F877A and the bulk of my project is written and working.The RTC's only cost $1 each.You Mentioned BIT BANG.I've heard the term before but have no idea what it means.Will look it up.Thank youBILL.

author: Ian.M
author_rank: Super Contributor
timestamp: April 25, 2017, 02:17:08 am
content: https://en.wikipedia.org/wiki/Bit_bangingIf you don't want to write your own midrange PIC access functions for your DS1302 modules, save them fo other projects - there's plenty of code available for the Arduino and Raspberry PI.

author: neko efecktz
author_rank: Regular Contributor
timestamp: April 25, 2017, 05:06:09 am
content: Thanks Ian.its not that In don't want to write my own functions, It is at the moment far beyond my abilaties.I have only 2 or three projects to my credit using basic code and adapting it to my needs.I will try to find some code that I can adapt to my requirements.You have been a great help from day one.Thankyou.I had the same thought of using the RTC's for my Raspberry Pi although at the moment I just use it as a third computer to play about with and I have downloaded acouple of routines to get the time from the internet whenever it is turned on.Accurate enough may loose / gain a bit of time if left turned on for a long time but I'm not worried about that.Or it my update the time every few minutes.I will be later on, perhaps be creating a portable tablet type device or alarm system or something, who knows.Wouldn't mind having a go with Arduino as well.

author: ggchab
author_rank: Frequent Contributor
timestamp: April 25, 2017, 09:08:01 am
content: If found some old code I wrote for a PIC16F877 running at 4.194304 MHz and a DS1302. I hope this might help you. This is in assembly but should not be to difficult to translate into C.

author: neko efecktz
author_rank: Regular Contributor
timestamp: April 25, 2017, 09:53:19 am
content: ggchab.Thank you for the code but unfortunately I know nothing about ASSY code except that I know nothing about it.There are little bits that I recognize the instruction but have no idea on how to convert it.I have tried to learn ASSY but I'v never been able to grasp more than the bear basics.I've only been doing C for about a year.I think I'm getting a little too old to be trying to learn a new language.once againThank You for your kind offer.BILL.

author: neko efecktz
author_rank: Regular Contributor
timestamp: April 26, 2017, 12:53:23 am
content: Good morning every one.I've just been looking at some DS1307's to replace the DS1302's I received the other day.IAN.M advised they are harder to code and there is less chance of finding usable MPLAB C code to modify.I know nothing of ASSY.I have also modified bits of C code from other compilers but nothing too severe.I'm looking athttp://www.ebay.com.au/itm/5PCS-I2C-Tiny-RTC-DS1307-Real-Time-Clock-Module-AT24C32-Board-for-Arduino-TE187-/172590020944?hash=item282f2ab950:g:XlcAAOSwWxNY063oThere is a big difference in price from $1.00 to $3.40 per single item.Can someone tell me the purpose of the ATMEL AT24C32 chip and support on board?Are they required as part of the clock or are they just support for when using with Arduino Raspberry Pi etc?Would they effect the operation of the unit if being run from a PIC16F877A?Why do the DS1302 sellers state that the DS1302 replaces Ds1307?http://www.ebay.com.au/itm/RTC-DS1302-Real-Time-Clock-Module-For-Arduino-AVR-ARM-PIC-SMD-Replace-DS1307-/262698633733?hash=item3d2a0f0a05:g:RmwAAOSwal5YFqdkI figure if I buy 5 modules I might not blow them all up.Some sellers advertise that the batteries are fitted and the clock is set to local time. CHINA TIME.There is an unpopulated component on the board.Probably a small transistor or voltage regulator.Any Ideas.The middle leg runs off to DS at each end of the board.the outer leg looks to to be going to a pad that hold the crystal then on to pins 1 to 4 of the AT24C32FOUND ITQuoteAll the bestThank youBILL

author: ebclr
author_rank: Super Contributor
timestamp: April 26, 2017, 01:01:17 am
content: It's very easyhttp://microcontrollerslab.com/spi-communication-pic-microcontroller/

author: Ian.M
author_rank: Super Contributor
timestamp: April 26, 2017, 01:17:16 am
content: I'm not saying DS1302 is harder to code for. In fact coding from scratch, bit-banging SPI is generally easier than bit-banging I2C. However you don't want to write your own code for it, you want to find a library to handle it, and due to the bidirectional data pin, there are some issues interfacing with the PIC MSSP in SPI mode, and it will use up four pins whereas an I2C interface RTC only needs two pins and can share them with many other I2C devices.The 24C32 is just EEPROM memory. Why they bundle it, I don't know. Obviously some application originally needed it and many cheap module sellers are now copying that.I haven't got the foggiest why anyone would want to put a DS18B20 on the same board. If it had an unpopulated footprint for an I2C temperature sensor it would make more sense.

author: neko efecktz
author_rank: Regular Contributor
timestamp: April 26, 2017, 03:43:56 am
content: Thanks Ian.Got to get ready for work in a few minutes.Shift worker.As I said I'm looking at getting some DS1307 modules.Are these easier to work with along with PIC16F877A?I will also keep looking for a usable library file that I can adapt.ebclr...the link you posted ended up with a messagesite cant be reached, took too longmay be just busy or out of bounds to Australians.