Working clock example using 32K watch crystal


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default Re: Working clock example using 32K watch crystal

    How about using 3 If-Then's insead of one with 3 OR's?

    Ioannis

  2. #2
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Working clock example using 32K watch crystal

    I spent all night trying to find the best way ... I think this is
    Code:
                  If month=2 then
                     If year//4<>0 then
                        DMonth=29
                     else
                        DMonth=28
                     endif
                  else
                  Dmonth=30+month.0 
                  endif   
                  If day>Dmonth then
    @                CLRF _Day
    @                INCF _Month,F
                     If month>12 then
    And everywhere there is any = 0, I replaced the @ clrf, +1 replaced with @ incf.
    The end result was the RTC which consumes about 2uA and code size about 500B.

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default Re: Working clock example using 32K watch crystal

    I think you have to change the <>0 to =0 when you test for the modulo 4.

    A better solution to cover more years (you code will not cover year 2100) is to use mod 400, mod 100 and mod 4 to test for leap year (mod 100 is NOT leap year, while 400 and 4 ARE leap years).

    Of course we may not live in year 2100, but just in case...

    Now about the @ commands, just be sure you are on page 0. Else you have to check the page bits. Or put this subroutine on top of your code.

    Ioannis
    Last edited by Ioannis; - 30th May 2011 at 11:13.

  4. #4
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Working clock example using 32K watch crystal

    Thanks for that... It was just typo... 0-99 year is fine for this aplication.
    On the top of ISR I have BSR=0, and isr routine is on top of my programm.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default Re: Working clock example using 32K watch crystal

    If I may suggest, make the minutes and hours update in your main loop and not in Interrupt. A temp variable wll be needed for this.

    Ioannis

  6. #6
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Working clock example using 32K watch crystal

    If pic loses power, it goes to sleep. And everything is shut off, only tmr1 is on. So i need that in ISR. Is there better way?

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts