RTC PIC16F877A without ds1302

Status
Not open for further replies.

Bertec

Newbie level 1
Joined
Feb 12, 2019
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
15
I have this school project of making a RTC but only using the PIC and assembler code in mplab, the problem is that I don't fully understand how to do it and I need to use as less code as I can.
Could you help me recommending a book, or blog, or something really good to learn. If you could also give me the code would be great, because I have very few time.
Thank you very much for your support
 

I have already passed my school courses so I'm certainly not interested in passing your!
Just to check the terminology - by RTC you mean Real Time Clock?
The MCU you have does not have a built-in RTCC function so you will need to create something yourself from the devices it does have.
What other restrictions do you have? Can you use an external crystal? How accurate does it have to be.
I suggest you look at the data sheet and read up on how the timers work - the MCU has 3 timers but for your situation (as long as you don't need it for some other function) I'd suggest that you use TIMER2.
Also try to use a crystal if you can as it will be far more accurate than an RC oscillator.
How are you to display the output time?
(By the way, they are really making it hard for you to only use assembler. If your class is all about how to code in assembler then that is fair enough, but if it is how do you create a real-world embedded device then I woudl think this an unnecessary restriction.)
Susan
 

Hi,

There may be books, but you can do without.

Basically it's just counting numbers, compare numbers, and on compare match...reset the number and increment the next number.

Start with a flowchart. For this you don't need a book, no assembler, you don't even need to know about a microcontroller.
A sheet of paper and a pencil will do.

Klaus
 

Code without a DS1302 is probably easier than code with it, especially if you are not familiar with it's quirky bi-directional data pin. Having said that, I use them and they work extremely well.

Think about how a clock works, it is nothing more than counting at a fixed rate and carrying when the limit for each time unit is reached. The trick is to get the one second count as accurate as possible and you can use the hardware timers for that (TMR1 for example). Then:
at one second intervals count up to 60, add one to the minutes and reset the seconds to zero,
when minutes reach 60, add one to the hours and reset the minutes to zero,
when hours reaches 24, add one to the date and reset the hours.

You don't have to use the date if you don't want to but if you do, remember to reset the day to one at the end of the month, not zero! Also, if you use months you will have to cater for different lengths. That is also very easy, just make an array of number of days in each month and use it's contents to decide when to reset and carry to the next month or year.

With a good crystal (16F877A does not have an internal timing source) you should be able to keep accuracy better than one second per day quite easily.

Brian.
 
Using T1OSC with a 32 kHz watch crystal is the next best solution, however PIC16F877 has not low power features to operate the RTC battery powered. Even PIC processors with dedicated RTC unit can't compete with the sub µA consumption of an external RTC.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…