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.

Chapter 10<br />

Listing 10-2. Toggles a port bit and displays the result.<br />

10 REM toggles P1.7 once per second<br />

20 TIME=0<br />

30 CLOCK 1<br />

40 DO<br />

50 ONTIME 1,100<br />

60 WHILE 1=1<br />

70 END<br />

100 REM reset time<br />

110 TIME=0<br />

120 REM toggle Port 1, bit 7<br />

130 PORT1=PORT1.XOR.80H<br />

140 PRINT “Port 1, bit 7 = ”,(PORT1.AND.80H)/80H<br />

150 RETI<br />

But in reality, because of the way that BASIC-52 calculates time, small variations in XTAL<br />

usually do not effect the real-time clock. Although BASIC-52 will store a XTAL value as<br />

precise as 12000001, it uses the same time base for all XTAL values from 11963191 to<br />

12039877. If your crystal frequency is within this range, small adjustments to XTAL won’t<br />

make the real-time clock more accurate. <strong>The</strong> value that controls the time base is stored at<br />

4Ah in internal data memory. At 12 Mhz, it’s 64h. If you want to experiment, change the<br />

value of XTAL, then type PH0. DBY(4AH) to find out if the time base has changed.<br />

A Watchdog Timekeeper<br />

Dallas Semiconductor’s DS1286 Watchdog Timekeeper, shown in Figure 10-1, is another<br />

way to keep track of time. <strong>The</strong> chip is easy to use because it contains its own quartz-crystal<br />

timing reference, plus a lithium cell for backup power. Once you initialize the clock and<br />

calendar and start the oscillator, the clock keeps time for ten years or more, whether or not<br />

an external power source is present. You don’t have to reset the clock every time you power<br />

up.<br />

<strong>The</strong> DS1286 can be especially useful in battery-powered systems. Since it continues to keep<br />

time when the main power supply is off, you can use its interrupt output to power circuitry<br />

at programmed times or intervals. For example, by adding circuits to control a power supply,<br />

the DS1286’s interrupt could trigger a data logger or other instrument to power up at a<br />

programmed time. After taking data or performing other operations, the instrument could<br />

power itself down until the next interrupt from the DS1286. <strong>The</strong> longer the time between<br />

readings, the greater the power savings.<br />

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

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

Saved successfully!

Ooh no, something went wrong!