Embedded Systems Building Blocks, Second Edition

The management of time is important in many microprocessor-based embedded systems. For instance, what would VCRs (Video Cassette Recorders) be without clock/calendars to schedule the recording of television programs?
In this chapter, I will describe how I implemented a Y2K-compliant clock/calendar module. The clock/calendar module offers the following features:
Maintains hours, minutes, and seconds.
Contains a calendar which keeps track of: month, day, year (including leap-years), and day-of-week.
Allows your application to obtain a timestamp to mark the occurrence of events. A timestamp is the current date and time packed into a 32-bit integer.
A clock/calendar is a useful module for an embedded system. If you need a clock/calendar, you have to decide whether to implement it in hardware or software.
Clock/calendar chips are readily available and most can directly interface with microprocessors. These chips accurately maintain the time-of-day, and some chips even provide a built-in calendar. Some chips include a battery and can continue to keep track of date and time even when power is removed from the unit. Clock/calendar chips generally require a crystal, which further increases the recurring cost of your system. Clock/calendar chips are manufactured by a large number of semiconductor companies such as Motorola, National Semiconductor, Maxim, Dallas Semiconductor, etc. Just because you have a clock/calendar chip doesn't mean you don't need to write any software. Your application software will still need to:
program the clock/calendar chip with the correct date and time,
program any alarm clock functions, and
read...