--- This is a test - only visible to admins ---
--- advertisement may go here ---
  • PicŪ Basic

  • DS1307 Real Time Clock Interfacing with Proton

    The DS1307 is quite an aged device, however, in my opinion, it is one of the best RTCs around. It is easy to interface with, easy to build into a project, and is quite inexpensive and plentiful.

    The Proton code presented here is suitable for 18F devices, Enhanced 14-bit core devices, dsPIC devices, and PIC24 devices, so it's quite versatile.

    A suitable circuit for the DS1307 RTC is shown below. As can be seen, it uses an I2C interface, so only takes two valuable pins from the microcontroller.

    Click here for a larger image of the circuit

    A video of the circuit simulating is shown below. It is using a PIC18F25K20 devices, which is the one used on the Amicus18 board.

    The routines within the code are quite straightforward.

    In order to use the routines, add the DS1307.inc file to the program:
        Include "Amicus18.inc"              ' Configure the compiler to use a PIC18F25K20 at 64MHz. i.e. An Amicus18 board
        Declare SDA_Pin = PORTB.1           ' SDA connected to this pin for use with Busin and Busout
        Declare SCL_Pin= PORTB.0            ' SCL connected to this pin for use with Busin and Busout
        Include "DS1307.inc"                ' Load the DS1307 routines into the program
    DS1307_WriteTime(pHour, pMinute, pSecond)
    Write the current time to the DS1307

    • pHour holds the hour to set.
    • pMinute holds the minute to set.
    • pSecond holds the second to set.
    DS1307_WriteDate(pDayOfWeek, pDay, pMonth, pYear)
    Write the current date to the DS1307

    • pDayOfWeek holds a value for the current day. i.e. Sunday to Saturday(1 to 7).
    • pDay holds the day to set.
    • pMonth holds the month to set.
    • pYear holds the year to set. i.e. 16, 17, 18 etc...
    Read the time from the DS1307

    Once the DS1307_ReadTime() routine is called, the hours/minutes/seconds values will be loaded into several variables as decimal integers:
    • RTC_Hour holds the hours read from the device.
    • RTC_Minute holds the minutes read from the device.
    • RTC_Second holds the seconds read from the device.
    Read the date from the DS1307

    Once the DS1307_ReadDate() routine is called, the Year/Month/Day values will be loaded into several variables as decimal integers:
    • RTC_Year holds the year read from the device.
    • RTC_Month holds the month read from the device.
    • RTC_Day holds the day read from the device.
    • RTC_DayOfWeek holds the weekday read from the device.
    DS1307_Get_DayName(pDayOfWeek, pResult)
    Converts the RTC_DayOfWeek value into a string holding the name of the day. i.e. "Sunday", "Monday", "Tuesday", to "Saturday".

    The name of the day is returned in the variable RTC_DayName, and whatever variable is used as pResult.

    DS1307_Get_MonthName(pMonth, pResult)
    Converts the Month value into a string holding the name of the month. i.e. "January" to "December".

    The name of the month is returned in the variable RTC_MonthName, and whatever variable is used as pResult.

    The DS1307 source code, and the above simulation file suitable for the proteus simulator can be downloaded from here:

  • Recent Activity


    PIC iPod wav player

    Thread Starter: normnet

    Coming in the next month or two a PIC iPod wav player. Plays 44k, 8 bit, stereo wav files from an SD card. Displays BMP pictures on a NOKIA 6100...

    normnet Today, 13:59 Go to last post

    Frequency counter

    Thread Starter: teo

    Hello everybody Can someone help me with a piece of code to measure a frequency (1Hz to 160 Hz) precision two decimals. The result is transmitted...

    teo Yesterday, 17:43 Go to last post

    Multiple functions by a single switch

    Thread Starter: amod

    Hi, How can I use multiple function by a single switch.I want to use 4 functions by a single switch.

    joesaliba Today, 09:19 Go to last post

    PickitPlus for Pickit2 and Pickit3 works well

    Thread Starter: leonj

    Hi Everyone, I have always had issues with Pickit2/Pickit3 and I'm glad to say they seem to all be solved now. I obtained PickitPlus from Even at...

    steyn Today, 09:34 Go to last post

    SD routines for 18F series

    Thread Starter: charliecoultas

    I've used the SD routines very successfully for the P24 chips, but now I need to attach an SD card to a 18F26K22. Do such routines exist and if...

    RGV250 Yesterday, 19:40 Go to last post