# rtc_common

Common RealTime Clock routines and RTC user interface

Author | Rob Hamerling, Copyright © 2013..2015, all rights reserved
Adapted-by |
Compiler | 2.4q3

Description

    Library with common code and data for all rtc libraries.
    .
    Supported values:
    .
       - Elementary values of date and time (and alarm):
          * year:         byte 00..99
          * month:        byte 01..12
          * day of month: byte 01..31
          * hour:         byte 00..23
          * minute:       byte 00..59
          * second:       byte 00..59
    .
       - Derived values (in binary notation):
          * day of the year:    word    1..366
          * day of the week:    byte    1..7      (1 = Sunday)
          * minute of the day:  word    1..1440
          * second of the hour: word    1..3600
          * second of the day:  byte*3  1..86400

Notes

    - variables in bcd notation can be printed conveniently with print_..._hex()

Dependencies

No dependency found

## Summary

### Global variables/contants

### Procedures

- `rtc_second_bin'put(byte in s)`
- `rtc_year_bcd'put(byte in y)`
- `rtc_get_time_bin(byte out hh, byte out mm, byte out ss)`
- `rtc_minute_bcd'put(byte in m)`
- `rtc_second_bcd'put(byte in s)`
- `rtc_year_bin'put(byte in y)`
- `rtc_set_date_bin(byte in yy, byte in mm, byte in dd)`
- `rtc_hour_bcd'put(byte in h)`
- `rtc_month_bcd'put(byte in m)`
- `rtc_minute_bin'put(byte in m)`
- `rtc_get_date_bcd(byte out yy, byte out mm, byte out dd)`
- `rtc_set_time_bin(byte in hh, byte in mm, byte in ss)`
- `rtc_dayofmonth_bcd'put(byte in d)`
- `rtc_get_time_bcd(byte out hh, byte out mm, byte out ss)`
- `rtc_get_date_bin(byte out yy, byte out mm, byte out dd)`
- `rtc_dayofmonth_bin'put(byte in d)`
- `rtc_hour_bin'put(byte in h)`
- `rtc_set_time_bcd(byte in hh, byte in mm, byte in ss)`
- `rtc_month_bin'put(byte in m)`
- `rtc_set_date_bcd(byte in yy, byte in mm, byte in dd)`

### Functions

- `rtc_bin2bcd(byte in bin) return byte`
- `rtc_calc_dayofweek(byte in yy, byte in mm, byte in dd) return byte`
- `rtc_secondofhour'get() return word`
- `rtc_month_bcd'get() return byte`
- `rtc_mult60(word in x) return byte*3`
- `rtc_month_bin'get() return byte`
- `rtc_dayofyear'get() return word`
- `rtc_secondofday'get() return byte*3`
- `rtc_dayofweek'get() return byte`
- `rtc_second_bin'get() return byte`
- `rtc_bcd2bin(byte in bcd) return byte`
- `rtc_second_bcd'get() return byte`
- `rtc_calc_dayofyear(byte in yy, byte in mm, byte in dd) return word`
- `rtc_year_bcd'get() return byte`
- `rtc_minute_bcd'get() return byte`
- `rtc_minuteofday'get() return word`
- `rtc_year_bin'get() return byte`
- `rtc_hour_bcd'get() return byte`
- `rtc_minute_bin'get() return byte`
- `rtc_dayofmonth_bin'get() return byte`
- `rtc_hour_bin'get() return byte`
- `rtc_dayofmonth_bcd'get() return byte`

## API details

### Global variables/contants

### Procedures

- `rtc_second_bin'put(byte in s)`

  No documentation found

- `rtc_year_bcd'put(byte in y)`

  No documentation found

- `rtc_get_time_bin(byte out hh, byte out mm, byte out ss)`

      Title: get time (hour, minute, second) in binary notation

- `rtc_minute_bcd'put(byte in m)`

  No documentation found

- `rtc_second_bcd'put(byte in s)`

  No documentation found

- `rtc_year_bin'put(byte in y)`

  No documentation found

- `rtc_set_date_bin(byte in yy, byte in mm, byte in dd)`

      Title: set date (year, month, dayofmonth) in binary notation

- `rtc_hour_bcd'put(byte in h)`

  No documentation found

- `rtc_month_bcd'put(byte in m)`

  No documentation found

- `rtc_minute_bin'put(byte in m)`

  No documentation found

- `rtc_get_date_bcd(byte out yy, byte out mm, byte out dd)`

      Title: get date (year, month, dayofmonth) in bcd notation

- `rtc_set_time_bin(byte in hh, byte in mm, byte in ss)`

      Title: set time (hour, minute, second) in binary notation

- `rtc_dayofmonth_bcd'put(byte in d)`

  No documentation found

- `rtc_get_time_bcd(byte out hh, byte out mm, byte out ss)`

      Title: get time (hour, minute, second) in bcd notation

- `rtc_get_date_bin(byte out yy, byte out mm, byte out dd)`

      Title: get date (year, month, dayofmonth) in binary notation

- `rtc_dayofmonth_bin'put(byte in d)`

  No documentation found

- `rtc_hour_bin'put(byte in h)`

  No documentation found

- `rtc_set_time_bcd(byte in hh, byte in mm, byte in ss)`

      Title: set time (hour, minute, second) in bcd notation

- `rtc_month_bin'put(byte in m)`

  No documentation found

- `rtc_set_date_bcd(byte in yy, byte in mm, byte in dd)`

      Title: set date (year, month, dayofmonth) in bcd notation

### Functions

- `rtc_bin2bcd(byte in bin) return byte`

      Convert one byte binary to bcd notation.
      input:   byte with binary value
      output:  none
      returns: byte with bcd notation of binary value
      notes:   Algorithm without division by 10, by iteration
      bcd = (16 * tens) + ones
      bcd = (tens * (10 + 6)) + ones
      Works correctly for binary values 0..99
      (values outside this range are not expected with rtc).

- `rtc_calc_dayofweek(byte in yy, byte in mm, byte in dd) return byte`

      Title:   Calculate day of the week
      input:   year, month, day-of-month in bcd noation
      returns: day of week number in range 1..7  (1 is Sunday)

- `rtc_secondofhour'get() return word`

      Title: get second of hour (binary)

- `rtc_month_bcd'get() return byte`

      Title: get or set the months value of clock, bcd or bin

- `rtc_mult60(word in x) return byte*3`

      Title:   Multiply a word by 60 (e.g. minutes -> seconds, hours -> minutes)
      input:   word with binary data
      output:  none
      returns: byte*3 with product
      notes: - (x * 60) == (x * 64) - (x * 4)
       algorithm without multiplication (only bit shifting)
       word as input, byte*3 as returnvalue
      (chosen for relative second of day)

- `rtc_month_bin'get() return byte`

  No documentation found

- `rtc_dayofyear'get() return word`

      Title: get day of year value (binary)

- `rtc_secondofday'get() return byte*3`

      Title: get second of day (binary)

- `rtc_dayofweek'get() return byte`

      Title: get day of week value (binary)

- `rtc_second_bin'get() return byte`

  No documentation found

- `rtc_bcd2bin(byte in bcd) return byte`

      Convert one byte packed bcd to one byte binary.
      input:   byte with bcd data
      output:  none
      returns: byte with binary value of bcd byte
      notes: - A byte in bcd notation contains ((16 * tens) + ones).
      To convert it to a binary value: subtract (6 * tens),
      implemented as subtract (8*tens - 2*tens).
      Algorithm is modelled after an assembler version of
      Scott Dattalo at PicList (and only slightly less efficient!).

- `rtc_second_bcd'get() return byte`

      Title: get or set the seconds value of clock, bcd or bin

- `rtc_calc_dayofyear(byte in yy, byte in mm, byte in dd) return word`

      Title: calculate day of the year
      input: year, month, day-of-month in bcd notation
      returns: number of the day of this year (binary word 1..366)

- `rtc_year_bcd'get() return byte`

      Title: get or set the years value of clock, bcd or bin

- `rtc_minute_bcd'get() return byte`

      Title: get or set the minutes value of clock, bcd or bin

- `rtc_minuteofday'get() return word`

      Title: get minute of day (binary)

- `rtc_year_bin'get() return byte`

  No documentation found

- `rtc_hour_bcd'get() return byte`

      Title: get or set the hours value of clock, bcd or bin

- `rtc_minute_bin'get() return byte`

  No documentation found

- `rtc_dayofmonth_bin'get() return byte`

  No documentation found

- `rtc_hour_bin'get() return byte`

  No documentation found

- `rtc_dayofmonth_bcd'get() return byte`

      Title: get or set the day-of-month value of clock, bcd or bin

## Related samples

No sample found