Gabe's Gadgets

PIC 16F84A Clock and Calendar

While on a vacation in 2011, I started reading about microcontrollers in hopes of incorporating them into future projects. At that time, I had a fairly solid understanding of analog circuit design but lacked formal training in software development and digital design. In order to get myself started, I chose the relatively simple PIC 16F84A as a platform. While basic, this microcontroller was established, well documented, and powerful enough for my needs.

Implementing the real-time functionality of a clock on such a bare-bones chip wound up requireing more creativity than I had expecteded. Here, I will outline some of the challenges I faced in designing my clock and how I used software techniques in combination with discrete peripheral components in order to bring my concept to fruition.

Overview of the 16F84A:

  • 35 single-word instructions, each 14 bits wide
  • Program memory for only 1024 instructions
  • 64 bytes of RAM and 1 working register
  • 1 counter/timer with prescaler and overflow interrupt capability
Datasheet

Firmware:

Because the 16F84A supports only 1 clock source, I was forced to use 32.768 kHz crystal oscillator for the system clock as well as the real-time clock. This resulted in extremely strict timing requirements. Due to timing constraints and the 16F84A’s highly-limited program memory bank, I coded my clock's entire firmware in assembly. My final firmware consisted of 754 instructions (which consumed 75% of the PICs 1k of program memory).