RTC Problem using DS1302


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2005
    Posts
    53

    Smile RTC Problem using DS1302

    Hi All,

    I have placed my code below, does anyone know how can I put milli-second's in the tmer as well?,
    as currently I have seconds, minutes and hours but I need to show miilisconds as well, any help
    would be appreciated ;-)

    Include "modedefs.bas" ' Include shift modes

    Define OSC 10 ' Set Xtal Frequency
    ' ** Setup the Debug Defines **
    Define LCD_DREG PORTD ' Define LCD connections
    Define LCD_DBIT 0
    Define LCD_RSREG PORTH
    Define LCD_RSBIT 4
    Define LCD_EREG PORTH
    Define LCD_EBIT 5
    DEFINE LCD_BITS 4 'LCD bus size 4 or 8
    DEFINE LCD_LINES 2 'Number lines on LCD
    DEFINE LCD_COMMANDUS 2000 'Command delay time in us
    DEFINE LCD_DATAUS 50 'Data delay time in us
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 0 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS


    ' ** Declare the Variables **


    B0 VAR BYTE
    B1 VAR BYTE
    B2 VAR BYTE


    RST var PORTJ.2
    IO var PORTJ.1
    SCLK var PORTJ.0

    ' Allocate variables
    rtcyear var byte
    rtcday var byte
    rtcmonth var byte
    rtcdate var byte
    rtchr var byte
    rtcmin var byte
    rtcsec var BYTE
    rtcssec var BYTE
    rtccontrol var byte


    ADCON1 = 15 ' PORTA and E digital
    ADCON2.7 = 1
    Low RST ' Reset RTC
    Low SCLK

    pause 100

    st:
    Lcdout $fe, 1, "Waiting..."
    rtchr = 0
    rtcmin = 0
    rtcsec = 0
    rtcssec = 00
    pause 100

    pause 500
    start:

    if portb.2 = 0 then goto main
    if portb.2 = 1 then goto start


    main:

    Gosub settime ' Set the time

    Goto mainloop ' Skip subroutines


    ' Subroutine to write time to RTC
    settime:

    RST = 1 ' Ready for transfer
    ' Enable write
    Shiftout IO, SCLK, LSBFIRST, [$8e, 0]

    RST = 0 ' Reset RTC

    RST = 1 ' Ready for transfer

    ' Write all 8 RTC registers in burst mode
    Shiftout IO, SCLK, LSBFIRST, [$be, rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, 0]

    RST = 0 ' Reset RTC
    Return

    ' Subroutine to read time from RTC
    gettime:
    RST = 1 ' Ready for transfer

    Shiftout IO, SCLK, LSBFIRST, [$bf] ' Read all 8 RTC registers in burst mode
    Shiftin IO, SCLK, LSBPRE, [rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, rtccontrol]

    RST = 0 ' Reset RTC
    Return

    ' Main program loop - in this case, it only updates the LCD with the time
    mainloop:

    Gosub gettime ' Read the time from the RTC

    ' Display time on LCD
    Lcdout $fe, 1, hex2 rtchr, ":", hex2 rtcmin, ":", hex2 rtcsec
    PAUSE 500
    ' Do it about 3 times a second

    if portb.2 = 1 then goto loop1
    if portb.2 = 0 then goto mainloop

    Goto mainloop ' Do it forever


    loop1:


    Low RST ' Reset RTC
    Low SCLK

    ' Display time on LCD
    Lcdout $fe, 1, hex2 rtchr, ":", hex2 rtcmin, ":", hex2 rtcsec

    PAUSE 250

    goto loop3

    loop3:

    pause 500

    if portb.3 = 1 then goto loop3
    if portb.3 = 0 then goto st

    goto loop3

    end

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default

    Gavo,

    Code:
    Shiftin IO, SCLK, LSBPRE, [rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, rtccontrol]
    Where are you reading your time from? What device are you using?

    Robert

  3. #3
    Join Date
    Sep 2005
    Posts
    53


    Did you find this post helpful? Yes | No

    Default DS Problem

    Hi Rob,

    I am using Dallas 1302, I thought I could use the "clock time" and just add a milliseconds, I have not defined any of the other variables like date and year as I do not need them...

    Regards,

    Gavin

  4. #4
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default

    Gavin,

    Just a quick look at the datasheet and it doesn't mention milliseconds .

    Robert
    Name:  DS1302.JPG
Views: 797
Size:  82.2 KB

  5. #5
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Depending on your application, you might be able to use one of the timers, such as the Olympic timer, or the high resolution timer. All without a RTC chip. A few shown here:

    http://www.picbasic.co.uk/forum/content.php?r=77
    Or DT_INTS for 1/100 of a second http://darreltaylor.com/DT_INTS-18/elapsed.html

    Walter
    Last edited by ScaleRobotics; - 5th July 2010 at 19:50.

Members who have read this thread : 1

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

Posting Permissions

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