• 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


    PCB Stencils

    Thread Starter: SimonJA

    I've made a lot of PCB's but never used stencils so thought I would give them a try. I usually use a syringe to dispense the solder paste but it's...

    Tim Yesterday, 19:51 Go to last post
    John Drew-26

    Hx711 calibration

    Thread Starter: amod

    Iam using load cell amplifier HX711 module.I have got raw values from module but iam not able to calibrate with load cell.I want make a universal...

    John Drew Yesterday, 23:40 Go to last post

    Modification of program code by data in external memory

    Thread Starter: geoff_c

    For the past several years farmers have been using a product I designed for a customer to measure moisture in grain. Within the code there are...

    geoff_c Today, 15:51 Go to last post