Jameco Electronics 3000 User Manual

Page of 349
244
Rabbit 3000 Microprocessor
ld hl,PDDDRShadow    ; point to shadow register
ld de,PDDDR          ; set de to point to I/O reg
set 5,(hl)           ; set bit 5 of shadow register
; use ldd instruction for atomic transfer
ioi ldd              ; (io de)<-(hl)  side effect: hl--, de--
In this case, the 
ldd
 instruction when used with an I/O prefix provides a convenient data 
move from a memory location to an I/O location. Importantly, the 
ldd
 instruction is an 
atomic operation so there is no danger that an interrupt routine could change the shadow 
register during the move to the PDDDR register. 
18.3.2.2  Non-atomic Instructions
If the following two instructions were used instead of the 
ldd
 instruction,
ld a,(hl)
ld (PDDDR),a  ; output to PDDDR
then an interrupt could take place after the first instruction, change the shadow register and 
the PDDDR register, and then after a return from the interrupt, the second instruction 
would execute and store an obsolete copy of the shadow register in the PDDDR, setting it 
to a wrong value.
18.3.3  Write-only Registers Without Shadow Registers
Shadow register are not needed for many of the registers that can be written to. In some 
cases, writing to registers is used as a handy way of changing a peripheral’s state, and the 
data bits written are ignored. For example, a write to the status register in the Rabbit serial 
ports is used to clear the transmitter interrupt request, but the data bits are ignored, and the 
status register is actually a read-only register except for the special functionality attached 
to the act of writing the register. An illustration of a write-only register for which a shadow 
is unnecessary is the transmitter data register in the Rabbit serial port. The transmitter data 
register is a write-only register, but there is little reason to have a shadow register since 
any data bits stored are transmitted promptly on the serial port.
18.4  Timer and Clock Usage
The battery-backable real-time clock is a 48 bit counter that counts at 32768 counts per 
second. The counting frequency comes from the 32.768 kHz oscillator which is separate 
from the main oscillator. Two other important devices are also powered from the 32.768 
kHz oscillator: the periodic interrupt and the watchdog timer. It is assumed that all mea-
surements of time will derive from the real-time clock and not the main processor clock 
which operates at a much higher frequency (e.g. 22.1184 MHz). This allows the main pro-
cessor oscillator to use less expensive ceramic resonators rather than quartz crystals. 
Ceramic resonators typically have an error of 5 parts in 1000, while crystals are much 
more accurate, to a few seconds per day.