Setting RTC by Serial input


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2005
    Posts
    44

    Default Setting RTC by Serial input

    Hi all,
    Heres a code example that i have used to set an RTC by a serial input, its probably not the most efficient code, but it works and could help some of you out
    It converts the Decimal input to BCD for the DS1302 DS1307 RTC

    all the variables are BYTES


    Code:
    '------ SET RTC -------------------------------------------------------------------------------------------
    
    SetRTC:
    
    HSEROUT ["Enter Day" , 13,10]		' Output
    HSERIN [DEC2 r_day]
    
    RTCday=r_day DIG 1
    RTCday=RTCday <<4
    RTCday=RTCday+(r_day DIG 0) 
    
    HSEROUT ["Enter Month" , 13,10]		' Output
    HSERIN [DEC2 r_month]
    
    RTCmonth=r_month DIG 1
    RTCmonth=RTCmonth<<4
    RTCmonth=RTCmonth+(r_month DIG 0) 
    
    HSEROUT ["Enter Year 20xx" , 13,10]		' Output
    HSERIN [DEC2 r_year]
    
    RTCyear=r_year DIG 1
    RTCyear=RTCyear<<4
    RTCyear=RTCyear+(r_year DIG 0) 
    
    HSEROUT ["Enter Hour" , 13,10]		' Output
    HSERIN [DEC2 r_hour]
    
    RTChour=r_hour DIG 1
    RTChour=RTChour<<4
    RTChour=RTChour+(r_hour DIG 0) 
    
    HSEROUT ["Enter Minute" , 13,10]		' Output
    HSERIN [DEC2 r_min]
    
    RTCmin=r_min DIG 1
    RTCmin=RTCmin<<4
    RTCmin=RTCmin+(r_min DIG 0) 
    
    r_sec=$00
    
    pause 100
    HSEROUT ["Writing to RTC" , 13,10]		' Output
    
    I2CWRITE SDA,SCL,$D0,$00,[r_sec,RTCmin,RTChour,$7,RTCday,RTCmonth,RTCyear,$90] ' Write to DS1307
    
    pause 500
    goto setup
    
    
    
    '=============================================================================================================================

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Setting RTC by Serial input

    Thank you for sharing. However you may want to add more explanation for people new to this. I could see this becoming a tutorial...
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Setting Question for Hardware Serial Coms
    By rocket_troy in forum Serial
    Replies: 2
    Last Post: - 8th December 2013, 22:17
  2. Setting project RTC without switches
    By ardhuru in forum Bluetooth
    Replies: 6
    Last Post: - 17th October 2012, 15:20
  3. Replies: 1
    Last Post: - 18th February 2012, 13:27
  4. Serial Keypad Input
    By OKST8 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th April 2005, 00:49
  5. serial input buffer
    By vsingh in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 14th June 2004, 06:55

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