Skip to content

Lab 1 Tasks

Requested Functions

  • uint8_t bit_clear(uint8_t value, uint8_t bit)
  • uint8_t bit_set(uint8_t value, uint8_t bit)
  • int bit_is_set(uint8_t value, uint8_t bit)
  • uint8_t bit_lsb(uint16_t value)
  • uint8_t bit_msb(uint16_t value)
  • uint8_t bit_mask(unsigned first_bit, ...)
  • int rtc_read_date(lcom_rtc_date_t *date)
  • int rtc_read_time(lcom_rtc_time_t *time)

Guided Gaps

  • Build masks from bit positions.
  • Decide how to handle out-of-range bit numbers.
  • Use a sentinel to stop the variadic bit_mask list.
  • Poll RTC_REG_A until RTC_UIP is clear.
  • Keep BCD conversion small and inspectable.
  • Check output pointers before writing.

IMPORTANT

Do not change RTC configuration. Interpret the mode reported by the device instead of forcing the device into the mode you prefer.

Common Mistakes

  • Treating BCD as binary.
  • Forgetting that bit positions start at zero.
  • Returning a mask value when the API asks for boolean-like output.
  • Writing a partial date/time structure after one read failed.

Next: checks and references.

Course/docs licensed CC BY 4.0. Code licensed MIT.