+ Post New Thread
Results 1 to 5 of 5
  1. #1
    Newbie level 1
    Points: 20, Level: 1

    Join Date
    Feb 2019
    Posts
    1
    Helped
    0 / 0
    Points
    20
    Level
    1

    RTC PIC16F877A without ds1302

    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

    •   AltAdvertisment

        
       

  2. #2
    Advanced Member level 4
    Points: 7,187, Level: 20

    Join Date
    Jan 2015
    Posts
    1,004
    Helped
    320 / 320
    Points
    7,187
    Level
    20

    Re: RTC PIC16F877A without ds1302

    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



    •   AltAdvertisment

        
       

  3. #3
    Super Moderator
    Points: 69,659, Level: 64
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    14,236
    Helped
    3253 / 3253
    Points
    69,659
    Level
    64

    Re: RTC PIC16F877A without ds1302

    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
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



    •   AltAdvertisment

        
       

  4. #4
    Super Moderator
    Points: 76,769, Level: 67
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    12,554
    Helped
    4187 / 4187
    Points
    76,769
    Level
    67

    Re: RTC PIC16F877A without ds1302

    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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.


    2 members found this post helpful.

  5. #5
    Super Moderator
    Points: 251,591, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    43,815
    Helped
    13322 / 13322
    Points
    251,591
    Level
    100

    Re: RTC PIC16F877A without ds1302

    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.



--[[ ]]--