Working clock example using 32K watch crystal


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    There's a couple good examples. I like Bruce's.
    But it uses in-line assembly language instead of straight PBP.

    The Elapsed Timer modification is nice too ... but ...

    Nobody wins the LCD's.
    DT

  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 was playing with TimC RTC code, and I found 1 problem...
    If the interrupt occurs between these lines
    Code:
          GoSub get_time      ' Update minutes and seconds
          TOGGLE LED_0
          LCDOut $fe,2,"Time: ",DEC hours, ":", DEC2 minutes, ":", DEC2 seconds, "   "
    There is a chance to show 60 seconds.
    It happened to me, so I then wondered what was going on...
    Solution:
    Code:
    seconds        VAR BYTE bankA  ' variables within myint must be in bank 0.
    minutes        VAR Byte bankA       ' Elapsed minutes
    hours          var byte bankA
    :
    :
    :
    @myint                  ; create myint label
       TMR1H.7=1
        seconds = seconds+1  ' Increment second
        if seconds > 59 then
            seconds = seconds - 60    ' better then making seconds=0
            minutes = minutes + 1
            if minutes > 59 then
                minutes = 0
                hours = hours + 1
                if hours > 12 then hours = 1    ' simple 12 hour clock format
            endif
        endif 
     PIR1.0=0             ' Clear TMR1 int flag
       @ retfie  FAST
    And remove get_time procedure
    Last edited by pedja089; - 25th May 2011 at 01:11. Reason: Repair CODE tag's

  3. #3
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Working clock example using 32K watch crystal

    I'm trying to add the calendar.
    Does anyone have an idea how to make a calculation of leap year.
    I tried this
    If day>30+month.0 or (Month=2 and day>28 and year//4<>0) or (Month=2 and day>29 and year//4=0)then
    month=month+1
    but the code is 300b larger then this
    If day>30+month.0 or (Month=2 and day>28)then
    month=month+1
    Is there a more efficient way?

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,172


    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

  5. #5
    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.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,172


    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 12:13.

  7. #7
    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.

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