18.11.2014 Views

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Clocks and Calendars<br />

10<br />

Clocks and Calendars<br />

Many 8052-BASIC systems can make use of a real-time clock that keeps track of seconds,<br />

minutes, hours, and even days, months, and years. You can use the clock to trigger operations<br />

at specified intervals, such as every five minutes, hourly, daily, on the first of the month, or<br />

whatever. Or, a data logger might record the time and date of each measurement it takes, or<br />

the times when it detects selected events.<br />

BASIC-52 includes its own real-time clock that counts in 5-millisecond increments. For<br />

many timing tasks, this is all you’ll need. Another approach is to add a timekeeping chip<br />

that automatically keeps track of time and calendar information. Many clocks perform<br />

functions beyond simple timekeeping, such as generating periodic interrupts or acting as a<br />

watchdog that resets the microprocessor in case of program crashes. Plus, using a separate<br />

timekeeping chip means that you don’t have to devote any of the 8052-BASIC’s resources<br />

to the task.<br />

This chapter describes how to use both BASIC-52’s real-time clock and Dallas Semiconductor’s<br />

DS1286 Watchdog Timekeeper chip.<br />

BASIC-52’s Real-time Clock<br />

<strong>The</strong> 8052-BASIC, like other computers, has a timing crystal or another frequency source<br />

connected to its XTAL pins. In fact, the chip will do nothing at all without this input, since<br />

it is what clocks instructions into the chip’s CPU for execution. While this clock provides<br />

<strong>The</strong> <strong>Microcontroller</strong> <strong>Idea</strong> <strong>Book</strong> 171

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!