# dcf77_decoder

DCF77 Decoder Library.

Author | Rob Jansen, Copyright © 2023..2023, all rights reserved.
Adapted-by |
Compiler | 2.5r8

Description

    Library for decoding the DCF77 format. The library
                 can be configured to use either the external interrupt or an
                 IOC interrupt to decode the DCF77 Message.
                 The default is using an external interrupt. In order to switch
                 to using an IOC interrupt the user must initialize the IOC
                 to be active on both the rising and falling edge and must
                 define the following alias (example for IOC on pin A2):
                 alias dcf77_decoder_ioc_flag is IOCAF_IOCAF2

Dependencies

No dependency found

## Summary

### Global variables/contants

- `const byte _DCF77_MESSAGE_DAY_OF_WEEK = 7`
- `const word _DCF77_BIT_1_MIN = 134`
- `var byte _dcf77_minutes, _dcf77_hours`
- `var bit _dcf77_parity`
- `const byte _DCF77_MESSAGE_MONTH_NUMBER = 8`
- `var word _dcf77_bit_time`
- `var bit _dcf77_parity_ok`
- `const word _DCF77_BIT_0_MIN = 67`
- `var byte _dcf77_message_state`
- `var byte _dcf77_day_of_week, _dcf77_day_of_month`
- `var byte _dcf77_month, _dcf77_year_within_century`
- `const byte _DCF77_MESSAGE_MINUTES = 4`
- `const byte _DCF77_MULTIPLIER[8] = {1, 2, 4, 8, 10, 20, 40, 80}`
- `const word _DCF77_PAUSE_1_MAX = 1064`
- `var bit _dcf77_new_bit`
- `const _DCF77_EDGE_FALLING = FALSE`
- `var byte _dcf77_bit_count`
- `const word _DCF77_PAUSE_0_MIN = 603`
- `const byte _DCF77_BIT_PAUSE = 2`
- `const word _DCF77_PAUSE_0_MAX = 1197`
- `const byte _DCF77_BIT_PULSE = 1`
- `const _DCF77_EDGE_RISING = TRUE`
- `const byte _DCF77_MESSAGE_HOURS = 5`
- `const word _DCF77_BIT_1_MAX = 266`
- `const byte _DCF77_MESSAGE_YEAR_WITHIN_CENTURY = 9`
- `const byte _DCF77_MESSAGE_DAY_OF_MONTH = 6`
- `const word _DCF77_SEQUENCE_MAX = 2660`
- `const byte _DCF77_MESSAGE_START = 1`
- `const byte _DCF77_MESSAGE_TIME_START = 3`
- `const byte _DCF77_MESSAGE_CET = 2`
- `const word _DCF77_PAUSE_1_MIN = 536`
- `var byte _dcf77_bit_state`
- `const word _DCF77_BIT_0_MAX = 133`
- `const byte _DCF77_MESSAGE_IDLE = 0`
- `var bit _dcf77_message_received`
- `var bit _dcf77_pulse_high`
- `const word _DCF77_SEQUENCE_MIN = 1340`
- `var bit _dcf77_bit_is_1`
- `const byte _DCF77_BIT_IDLE = 0`
- `var bit _dcf77_cet_time, _dcf77_cet_summer_time`

### Procedures

- `dcf77_decoder_pulse_high()`
- `dcf77_decoder_init()`
- `dcf77_decoder_pulse_low()`

Private

- `_dcf77_reset_decoder()`
- `_dcf_interrupt()`
- `_dcf77_timer1_interrupt()`

### Functions

- `dcf77_get_year_within_century() return byte`
- `dcf77_get_day_of_month() return byte`
- `dcf77_time_is_cest() return bit`
- `dcf77_get_hours() return byte`
- `dcf77_get_day_of_week() return byte`
- `dcf77_time_is_cet() return bit`
- `dcf77_message_received() return bit`
- `dcf77_get_month() return byte`
- `dcf77_get_minutes() return byte`

Private

- `_dcf77_handle_interrupt_flag() return bit`

## API details

### Global variables/contants

- `const byte _DCF77_MESSAGE_DAY_OF_WEEK = 7`

  No documentation found

- `const word _DCF77_BIT_1_MIN = 134`

      Nominal is 200 ms.

- `var byte _dcf77_minutes, _dcf77_hours`

  No documentation found

- `var bit _dcf77_parity`

  No documentation found

- `const byte _DCF77_MESSAGE_MONTH_NUMBER = 8`

  No documentation found

- `var word _dcf77_bit_time`

      Internal decoding variables.

- `var bit _dcf77_parity_ok`

  No documentation found

- `const word _DCF77_BIT_0_MIN = 67`

      Timing constants based on a 1 ms tick-time. Included is 33% tolerance. This
      is the maximum we can use without bit-times overlapping.
      Nominal is 100 ms.

- `var byte _dcf77_message_state`

  No documentation found

- `var byte _dcf77_day_of_week, _dcf77_day_of_month`

  No documentation found

- `var byte _dcf77_month, _dcf77_year_within_century`

  No documentation found

- `const byte _DCF77_MESSAGE_MINUTES = 4`

  No documentation found

- `const byte _DCF77_MULTIPLIER[8] = {1, 2, 4, 8, 10, 20, 40, 80}`

      Mutiplier array

- `const word _DCF77_PAUSE_1_MAX = 1064`

  No documentation found

- `var bit _dcf77_new_bit`

  No documentation found

- `const _DCF77_EDGE_FALLING = FALSE`

  No documentation found

- `var byte _dcf77_bit_count`

  No documentation found

- `const word _DCF77_PAUSE_0_MIN = 603`

      Nominal is 900 ms.

- `const byte _DCF77_BIT_PAUSE = 2`

  No documentation found

- `const word _DCF77_PAUSE_0_MAX = 1197`

  No documentation found

- `const byte _DCF77_BIT_PULSE = 1`

  No documentation found

- `const _DCF77_EDGE_RISING = TRUE`

      We decode the IR bitstream on both edges for better performance.

- `const byte _DCF77_MESSAGE_HOURS = 5`

  No documentation found

- `const word _DCF77_BIT_1_MAX = 266`

  No documentation found

- `const byte _DCF77_MESSAGE_YEAR_WITHIN_CENTURY = 9`

  No documentation found

- `const byte _DCF77_MESSAGE_DAY_OF_MONTH = 6`

  No documentation found

- `const word _DCF77_SEQUENCE_MAX = 2660`

  No documentation found

- `const byte _DCF77_MESSAGE_START = 1`

  No documentation found

- `const byte _DCF77_MESSAGE_TIME_START = 3`

  No documentation found

- `const byte _DCF77_MESSAGE_CET = 2`

  No documentation found

- `const word _DCF77_PAUSE_1_MIN = 536`

      Nominal is 800 ms.

- `var byte _dcf77_bit_state`

  No documentation found

- `const word _DCF77_BIT_0_MAX = 133`

  No documentation found

- `const byte _DCF77_MESSAGE_IDLE = 0`

      Decoder message states.

- `var bit _dcf77_message_received`

  No documentation found

- `var bit _dcf77_pulse_high`

  No documentation found

- `const word _DCF77_SEQUENCE_MIN = 1340`

      Nominal is 2000 ms.

- `var bit _dcf77_bit_is_1`

  No documentation found

- `const byte _DCF77_BIT_IDLE = 0`

      Decoder bit states.

- `var bit _dcf77_cet_time, _dcf77_cet_summer_time`

  No documentation found

### Procedures

- `dcf77_decoder_pulse_high()`

      Set the decoder to decode an incomming stream that uses an active high pulse.
      Note: Only relevant when using the external interrupt, not for IOC.

- `dcf77_decoder_init()`

      Initialize the DCF77 Decoder. This will enable the required interrupts. The
      decoder is set to decode an incomming stream that uses an active high pulse.

- `dcf77_decoder_pulse_low()`

      Set the decoder to decode an incomming stream that uses an active low pulse.
      Note: Only relevant when using the external interrupt, not for IOC.

Private

- `_dcf77_reset_decoder()`

      Reset the DCF77 decoder to its initial state.

- `_dcf_interrupt()`

      Interrupt, external or IOC.

- `_dcf77_timer1_interrupt()`

      Timer1 interrupt. Occurs when the timer overflows after 1 ms.

### Functions

- `dcf77_get_year_within_century() return byte`

      Returns the year wihin the century (0..99).

- `dcf77_get_day_of_month() return byte`

      Returns the day of the month (1..31).

- `dcf77_time_is_cest() return bit`

      Returns TRUE if the time is Central European Summer Time (CEST).

- `dcf77_get_hours() return byte`

      Returns the received hours. Hours are BCD coded.

- `dcf77_get_day_of_week() return byte`

      Returns the day of the week (1..7), where day 1 is Monday and 7 is Sunday.

- `dcf77_time_is_cet() return bit`

      Returns TRUE if the time is Central European Time (CET).

- `dcf77_message_received() return bit`

      Returns TRUE when a valid DCF77 message was received. Calling this function
      will clear the message received flag and will enable the reception of the
      next DCF77 message.

- `dcf77_get_month() return byte`

      Returns the month (1..12).

- `dcf77_get_minutes() return byte`

      Returns the received minuted. Minutes are BCD coded.

Private

- `_dcf77_handle_interrupt_flag() return bit`

      This procedure handles the interupt flag. Reason for this procedure is to be
      able to use two differnt interrupt types, IOC and external.

## Related samples

Here are the list of samples which use this library:

16f1825 | 16f1825_dcf77_decoder_ssd1306.jal
16f1825 | 16f1825_dcf77_decoder_serial.jal