Shop OBEX P1 Docs P2 Docs Learn Events
1302 vs 1307? — Parallax Forums

1302 vs 1307?

cavelambcavelamb Posts: 720
edited 2011-01-22 10:55 in Propeller 1
I'm collecting parts for my Proto board and wanted to ask those who know if there is a preference for
the real time clock chip? Parralax stocks the 1302, but most examples I've seen are for the 1307.
Are they code compatible?
Any serious differences?

Thanks

Richard

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2010-12-05 23:32
    Apparently they are NOT the same.

    http://www.8051projects.net/forum-t8997.html

    You can Google 'DS1302 versus DS1307' for more discussions.


    Personally, I would use the 1-wire I-Button RTO unit as it has an internal battery that is supposed to provide 10 years service and uses only one pin for i/o.
  • TubularTubular Posts: 4,717
    edited 2010-12-06 00:39
    Don't forget to consider the DS1337, which is 3v3 compatible.
  • Nick McClickNick McClick Posts: 1,003
    edited 2010-12-06 01:16
    @loopy, the DS1307 is i2c, so it uses the same pins your EEPROM are already using.

    Both the 1307 & 1337 are 3.3v compatible (i2c is open drain). The 1307 requires 5v vcc, but that's no problem with the Protoboard.
  • Kal_ZakkathKal_Zakkath Posts: 72
    edited 2010-12-06 12:42
    I've used the 1338, which is similar to the 1337 (but with a batt backup pin and only one alarm, also doesn't come in DIP8 sadly)
    As for code compatibility - I can't speak for 1302-1307, but for the 1338 I took Kye's 1307 driver and modified it.
    Obivoulsy the I2C commands are the same, but the RAM addresses and control registers are different.
  • Jay B. HarlowJay B. Harlow Posts: 79
    edited 2010-12-06 15:39
    I've used the 1338, which is similar to the 1337 (but with a batt backup pin and only one alarm, also doesn't come in DIP8 sadly)
    As for code compatibility - I can't speak for 1302-1307, but for the 1338 I took Kye's 1307 driver and modified it.
    Obivoulsy the I2C commands are the same, but the RAM addresses and control registers are different.

    The 1302 is not code compatible with the 1307. I recently took Kye's 1307 driver and modified it for 1302. As I finally finished by SD card adapter over Thanksgiving. I'm using the 1302 that is built into Parallax's Propeller Professional Development Board.

    Basically I took code from one of the OBEX 1302 objects and adopted it to Kye's 1307 interface.

    I need to go back and add support for burst mode. I dropped it just to get the code to work...

    Jay
  • cavelambcavelamb Posts: 720
    edited 2010-12-06 17:21
    Thanks for the info, guys.

    One of my intended projects is a "ships bell" function.
    So a custom board will be used in the end.
    Not needing the 5v supply might be a plus.
    I'll dig into the 1338 as well.
  • bpragerbprager Posts: 22
    edited 2011-01-03 07:47
    I am currently trying to use Kye's SD code and have the PPDB. Could you possibly post your modded code? That way I could at least get started learning the object while I figure out what to do next.

    Thanks for your consideration.

    Bruce Prager
  • Jay B. HarlowJay B. Harlow Posts: 79
    edited 2011-01-22 10:55
    bprager wrote: »
    I am currently trying to use Kye's SD code and have the PPDB. Could you possibly post your modded code? That way I could at least get started learning the object while I figure out what to do next.

    Thanks for your consideration.

    Bruce Prager

    Here's my modified code "as is"
    ''┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐               
    ''│ DS1302 Real Time Clock Engine                                                                                               │
    ''│                                                                                                                             │
    ''│ Author: Jay B. Harlow                                                                                                       │                              
    ''│ Updated: 11/27/2010                                                                                                         │
    ''│ Designed For: P8X32A @ 80Mhz                                                                                                │
    ''│ Version: 1.0                                                                                                                │
    ''│                                                                                                                             │
    ''│ Copyright (c) 2010 Jay B. Harlow                                                                                            │              
    ''│ See end of file for terms of use.                                                                                           │
    ''│                                                                                                                             │
    ''│ Update History:                                                                                                             │
    ''│                                                                                                                             │
    ''│ v1.0 - Original release - 11/27/2010.                                                                                       │
    ''│                                                                                                                             │
    ''│ Modified version of Kwabena W. Agyeman's DS1307 Real Time Clock Engine                                                      │
    ''│                                                                                                                             │
    ''│ For each included copy of this object only one spin interpreter should access it at a time.                                 │
    ''│                                                                                                                             │
    ''│ Jay,                                                                                                                        │
    ''└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ 
    
    CON
                             
      #1, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
      
      #1, January, February, March, April, May, June, July, August, September, October, November, December
    
    CON
      #0, secondsRegister, minutesRegister, hoursRegister, daysRegister, monthsRegister, dayOfWeekRegister, yearsRegsiter, _ctrl, _tc, #31, _burst
    
    VAR
    
      byte time[7]
      byte datar
    
    PUB checkSecond
    '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
    '' │ Returns the cached second (0 - 59) from the real time clock.                                                             │
    '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
      return time[secondsRegister]
      
    PUB checkMinute
    '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
    '' │ Returns the cached minute (0 - 59) from the real time clock.                                                             │
    '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
      return time[minutesRegister]
      
    PUB checkHour
    '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
    '' │ Returns the cached hour (0 - 23) from the real time clock.                                                               │ 
    '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
      return time[hoursRegister]
      
    PUB checkDay
    '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
    '' │ Returns the cached day (1 - 7) from the real time clock.                                                                 │ 
    '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
      return time[dayOfWeekRegister]
    
    PUB checkDate
    '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
    '' │ Returns the cached date (1 - 31) from the real time clock.                                                               │
    '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
      return time[daysRegister]
      
    PUB checkMonth
    '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
    '' │ Returns the cached month (1 - 12) from the real time clock.                                                              │
    '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
      return time[monthsRegister]
    
    PUB checkYear
    '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
    '' │ Returns the cached year (2000 - 2099) from the real time clock.                                                          │
    '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
      return time[yearsRegsiter] + 2000
    
    PUB checkMeridiemHour
    '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
    '' │ Returns the meridiem cached hour (12 - 11) from the real time clock.                                                     │
    '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
      result := (checkHour // 12)
      ifnot(result)
        result += 12
    
    PUB checkMeridiemTime
    '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
    '' │ Returns true if the meridiem cached hour is post meridiem and false if the meridiem cached hour is ante meridiem.        │
    '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
      return (checkHour => 12)
    
    
    PUB checkTime
    '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
    '' │ Caches the current real time clock settings. Returns true on success and false on failure.                               │
    '' │                                                                                                                          │
    '' │ Call "checkSecond" to get the real time clock second after calling this function first.                                  │
    '' │ Call "checkMinute" to get the real time clock minute after calling this function first.                                  │
    '' │ Call "checkHour" to get the real time clock hour after calling this function first.                                      │
    '' │ Call "checkDay" to get the real time clock day after calling this function first.                                        │
    '' │ Call "checkDate" to get the real time clock date after calling this function first.                                      │
    '' │ Call "checkMonth" to get the real time clock month after calling this function first.                                    │
    '' │ Call "checkYear" to get the real time clock year after calling this function first.                                      │
    '' │ Call "checkMeridiemHour" to get the real time clock meridiem hour after calling this function first.                     │
    '' │ Call "checkMeridiemTime" to get the real time clock meridiem time after calling this function first.                     │
    '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
      time[yearsRegsiter] := bcd2bin( readClock( yearsRegsiter ) ) ' year
      time[dayOfWeekRegister] := bcd2bin( readClock( dayOfWeekRegister ) ) ' day
      time[monthsRegister] := bcd2bin( readClock( monthsRegister ) ) ' month
      time[daysRegister] := bcd2bin( readClock( daysRegister ) ) ' date
      time[hoursRegister] := bcd2bin( readClock( hoursRegister ) ) ' hour
      time[minutesRegister] := bcd2bin( readClock( minutesRegister ) ) ' minute
      time[secondsRegister] := bcd2bin( readClock( secondsRegister ) ) ' second
      return true
    
    PUB changeTime(second, minute, hour, day, date, month, year)
    '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
    '' │ Changes the current real time clock time settings. Returns true on success and false on failure.                         │
    '' │                                                                                                                          │
    '' │ Second - Number to set the second to between 0 - 59.                                                                     │
    '' │ Minute - Number to set the minute to between 0 - 59.                                                                     │
    '' │ Hour - Number to set the hour to between 0 - 23.                                                                         │
    '' │ Day - Number to set the day to between 1 - 7.                                                                            │
    '' │ Date - Number to set the date to between 1 - 31.                                                                         │
    '' │ Month - Number to set the month to between 1 - 12.                                                                       │ 
    '' │ Year - Number to set the year to between 2000 - 2099.                                                                    │
    '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
      writeClock( yearsRegsiter, bin2bcd( ((year <# 2099) #> 2000) - 2000 ) )
      writeClock( dayOfWeekRegister, (day <# 7) #> 1 )
      writeClock( monthsRegister, bin2bcd( (month <# 12) #> 1) )
      writeClock( daysRegister, bin2bcd( (date <# 31) #> 1) ) 
      writeClock( hoursRegister, bin2bcd( (hour <# 23) #> 0) ) 
      writeClock( minutesRegister, bin2bcd( (minute <# 59) #> 0) )
      writeClock( secondsRegister, bin2bcd( (second <# 59) #> 0) )
      return true
      
    PUB checkSRAM(index)
    '' &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    '' &#9474; Returns the selected SRAM value at the specified index on sucess and false on failure.                                   &#9474;                                     
    '' &#9474;                                                                                                                          &#9474;
    '' &#9474; Index - The byte location in SRAM to check. (0 - 30).                                                                    &#9474; 
    '' &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
      return readRam((index <# 30) #> 0)
    
    PUB changeSRAM(index, value)
    '' &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    '' &#9474; Changes the selected SRAM value at the specified index to the specified value.                                           &#9474;
    '' &#9474;                                                                                                                          &#9474;
    '' &#9474; Returns true on success and false on failure.                                                                            &#9474;
    '' &#9474;                                                                                                                          &#9474;
    '' &#9474; Index - The byte location in SRAM to change. (0 - 30).                                                                   &#9474;
    '' &#9474; Value - The value to change the byte location to. (0 - 255).                                                             &#9474;
    '' &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
      writeRam((index <# 30) #> 0, (value <# 255) #> 0)
       
    PUB pauseForSeconds(number)
    '' &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    '' &#9474; Pauses execution for a number of seconds.                                                                                &#9474;
    '' &#9474;                                                                                                                          &#9474;
    '' &#9474; Number - Number of seconds to pause for between 0 and 2,147,483,647.                                                     &#9474;
    '' &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
      result := cnt
      
      repeat (number #> 0)
        result += clkfreq
        waitcnt(result)   
    
    PUB pauseForMilliseconds(number)
    '' &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    '' &#9474; Pauses execution for a number of milliseconds.                                                                           &#9474;
    '' &#9474;                                                                                                                          &#9474;
    '' &#9474; Number - Number of milliseconds to pause for between 0 and 2,147,483,647.                                                &#9474;
    '' &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
      result := cnt
      
      repeat (number #> 0)
        result += (clkfreq / 1000)
        waitcnt(result)      
    
    PUB RTCEngineStart(dataPinNumber, clockPinNumber, chipEnablePinNumber)
    '' &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    '' &#9474; Checks out a lock for the driver and changes the I2C Circuit pins. Returns true on success and false on failure.         &#9474;
    '' &#9474;                                                                                                                          &#9474;
    '' &#9474; DataPinNumber - Pin to use to drive the IO data line circuit.                                                           &#9474;
    '' &#9474; ClockPinNumber - Pin to use to drive the SCLK clock line circuit.                                                         &#9474;
    '' &#9474; ChipEnablePinNumber - Pin to use to drive the CE clock line circuit.                                                         &#9474;
    '' &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
      RTCEngineStop
      
      dataPin := ((dataPinNumber <# 31) #> 0)
      clockPin := ((clockPinNumber <# 31) #> 0)
      chipEnablePin := ((chipEnablePinNumber <# 31) #> 0)
      
      if((dataPin <> clockPin) and (clockPin <> chipEnablePin) and (chipver == 1)) 
        lockNumber := locknew
        result or= ++lockNumber
    
      dira[chipEnablePin]~~                           'configure chip enable pin
      outa[chipEnablePin]~            
      dira[clockPin]~~                                'configure clock pin
      outa[clockPin]~           
    
    PUB RTCConfig
      writeClock(_ctrl, 0)                                  'clear write-protect bit
      writeClock(secondsRegister, readClock(secondsRegister) & %0111_1111)        'clear halt bit
      writeClock(hoursRegister, readClock(hoursRegister) & %0111_1111)          'set 24hr mode
      writeClock(_tc, 0)                                    'disable trickle charger
    
    PUB RTCEngineStop
    '' &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    '' &#9474; Returns the lock used by the driver.                                                                                     &#9474;
    '' &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
    
      if(lockNumber)
        lockret(-1 + lockNumber~)
    
    PRI setLock ' 3 Stack Longs
    
      repeat while lockset (lockNumber - 1)
    
    PRI clearLock ' 3 Stack Longs
    
      lockclr (lockNumber - 1)
    
    PRI readClock(register)
      return read(constant((1<<7) + (0<<6)) + (register<<1) + 1)
    
    PRI writeClock(register, data)
      write(constant((1<<7) + (0<<6)) + (register<<1) + 0, data)
    
    PRI readRam(register)
      return read(constant((1<<7) + (1<<6)) + (register<<1) + 1)
    
    PRI writeRam(register, data)
      write(constant((1<<7) + (1<<6)) + (register<<1) + 0, data)
    
    PRI read( cmd )
    'Read a byte of data per command byte
    
      setLock
      
      outa[chipEnablePin]~~           
      writeByte( cmd )
      dira[dataPin]~             'set to input
      readByte
      outa[chipEnablePin]~
    
      clearLock
           
      return(datar)
    
    
    PRI write( cmd, data ) 
    'Write a byte of data per cmd byte
    
      setLock
      
      outa[chipEnablePin]~~           
      writeByte( cmd )
      writeByte( data )
      outa[chipEnablePin]~            
    
      clearLock
    
    PRI readByte | i
    
      datar~                           
      repeat i from 0 to 7          
         if ina[dataPin] == 1
          datar |= |< i     ' set bit
        outa[clockPin]~~          
        outa[clockPin]~
    
    
    PRI writeByte( cmd ) | i  
    
      dira[dataPin]~~              'set to output 
      repeat i from 0 to 7    
        outa[dataPin] := cmd       
        outa[clockPin]~~          
        cmd >>= 1
        outa[clockPin]~
    
              
    PRI bin2bcd(dataIn) : result | tmp
    'Convert a byte of binary data to binary coded decimal
    
      tmp:= dataIn/10
      result := dataIn - ( tmp * 10 ) + ( tmp << 4 )
    
      return result
    
    PRI bcd2bin(dataIn) : result
    'Convert a byte of binary coded decimal data to binary
    
      result := (dataIn & %00001111) +  ((dataIn >> 4) & %00001111)*10
    
      return result
      
    DAT
    
    ' //////////////////////Variable Array/////////////////////////////////////////////////////////////////////////////////////////
    
    dataPin                 byte 29 ' Default data pin.
    clockPin                byte 28 ' Default clock pin.
    chipEnablePin           byte 27 ' Default chip enable pin. 
    lockNumber              byte 00 ' Driver lock number.
    
    DAT
    
    ''&#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    ''&#9474;                                                   TERMS OF USE: MIT License                                                 &#9474;                                                            
    ''&#9500;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9508;
    ''&#9474;Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation   &#9474; 
    ''&#9474;files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,   &#9474;
    ''&#9474;modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the        &#9474;
    ''&#9474;Software is furnished to do so, subject to the following conditions:                                                         &#9474;         
    ''&#9474;                                                                                                                             &#9474;
    ''&#9474;The above copyright notice and this permission notice shall be included in all copies or substantial portions of the         &#9474;
    ''&#9474;Software.                                                                                                                    &#9474;
    ''&#9474;                                                                                                                             &#9474;
    ''&#9474;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE         &#9474;
    ''&#9474;WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR        &#9474;
    ''&#9474;COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,  &#9474;
    ''&#9474;ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                        &#9474;
    ''&#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
    

    I modified it to the point of getting to work, I haven't flushed it out enough to warrent posting it to the OBEX...

    Jay
Sign In or Register to comment.