Working clock example using 32K watch crystal


Results 1 to 20 of 20

Threaded View

  1. #13
    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 00:11. Reason: Repair CODE tag's

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