• PicŪ Basic


  • DS1307 Real Time Clock(2)

    This library is based on the Les's article which can be seen HERE.
    It is a simple RTC but always works well.

    For a future project, I added a few extra features.
    - ACK control that can be disabled.
    - Protection against interrupts (option).
    - The days/months can be printed in several languages.
    - The I2C pins are automatically placed in digital mode (pins ANSELx = 0).
    - 3 types of commands with Hardware of Software I2C (HBusOut/HBusIn, BusOut/BusIn or I2COut/I2Cin)
    - New DS1307_Present() command that lets you know the device is properly connected and working.
    - A Command to compress the RTC data to write it to an external eeprom.

    To see the basic commands please see Les's article.

    RTC variables:
    The declaration of RTC variables are made different.
    Code:
    ' Time variables BCD & Decimal values
    '
    Dim DS1307_Array[8] As Byte
    Dim RTC_Second    As DS1307_Array#0     ' Second (0..59)
    Dim RTC_Minute    As DS1307_Array#1     ' Minute (0..59)
    Dim RTC_Hour      As DS1307_Array#2     ' Hour   (0..11 or 0..23)
    Dim RTC_DayOfWeek As DS1307_Array#3     ' Day of the week (1..7)
    Dim RTC_Day       As DS1307_Array#4     ' Date   (0..31)
    Dim RTC_Month     As DS1307_Array#5     ' Month  (1..12)
    Dim RTC_Year      As DS1307_Array#6     ' Year   (0..99)
    New commands:

    DS1307_Present(ReturnACK)
    This command interrogates the device to know if it works correctly.
    If the control acknowledge is enabled then it is very easy just checking the return acknowledge.
    If the control acknowledge is disabled by the user then a predetermined value is written to the DS1307 NVRAM. If reading this value is correct then a compatible acknowledge will be sent.

    DS1307_ZipPage8(Humidity, Temperature)
    This command allows to organize the RTC data to save two free positions in the array to obtain an 8 byte page that will be writable to the EEPROM. The two byte variables are entered directly with the command and placed in the correct position in the array. (Humidity, Temperature)

    As an example the RTC data can be written to an EEPROM in this way.
    Code:
    DS1307_ZipPage8(Humidity, OrgTemperature)
    WritePage_E2P8(DeviceNumber, E2PArray, E2P_Page)
    DS1307_UnZipPage8(Humidity, Temperature)
    This command allows to decompress the data from the array and to rebuild the original position of the data and extracting the 2 bytes saved.

    As an example the RTC data can be restored in this way.
    Code:
    ReadPage_E2P8(DeviceNumber, E2PArray, E2P_Page)
    DS1307_UnZipPage8(Humidity, Temperature)
    Some options could be enabled/disabled by the user.
    Code:
    $define _French_
    $define _EnableGIE_Save_
    $define _DisableNACK_
    Include "DS1307-H.inc"
    TC74 Temperature sensor.
    By placing several devices on the same I2C bus, the TC74 sensor gives some trouble again. See the article about TC74 temperature sensor. Thanks to the double reading and autocorrect of the TC74_ReadSeCTemp() command, it works well and I did not realize the issue. The TC74 sensor is put into standby mode when seeing an I2C header that is not yours. In this way each time the temperature is read the sensor must be activated to Normal Mode first.
    No problem already planned!


    3 Files are available:

    Include "DS1307-H.inc" using the hardware I2C of the PIC (HBusOut/HBusIn commands) with acknowledge control.
    Include "DS1307-S.inc" using the software I2C (BusOut/BusIn commands) with acknowledge control.
    Include "DS1307-S2.inc" using the software I2C (I2COut/I2CIn commands) without acknowledge control.

    The file "Test1_DS1307.bas" allows to test the DS1307 commands.
    The files "Test2_DS1307.bas" and "Test3_DS1307.bas" are a mini DataLogger to see the possibilities to use different libraries that can be found in the WIKI.

    12/04/2017 Update DS1307 library
    Enjoy the datalogger.
    Alberto

    Download the code from the Files Server.
  • Recent Activity

    John Drew-26

    Mysterious PORTB problem

    Thread Starter: xldaedalus

    I'm using Proton+ to develop firmware for a product with switches. The MCU is an 18F26K22. Most of the switches reside on PORTB. I am NOT using a...

    John Drew Yesterday, 23:30 Go to last post
    Mellbreak-21950

    Watchdog timer

    Thread Starter: joesaliba

    I have a code that basically looks for four input and four outputs, depends on various timing and input conditions. I use interrupt and some delays...

    Mellbreak Yesterday, 11:30 Go to last post