• 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:
    Code:
        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

    Parameters:
    • 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

    Parameters:
    • 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...
    DS1307_ReadTime()
    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.
    DS1307_ReadDate()
    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:
    Proton_DS1307.zip


  • Recent Activity

    joesaliba-353

    Pulse counter memory problem

    Thread Starter: amod

    Please tell me my faults.My pulse counter memory does not store.When i switch on device after 5 second ,memory exist by after 30 seconds it is washed...

    joesaliba Today, 16:24 Go to last post