The following is a description of the Real-Time clock section of the D.A.M. board article which appeared in Time Designs Magazine ( March/April ’87 page 23 ). The board features a full-function real-time clock with battery back-up and is mappable into eight I/O port blocks. See attached schematic diagram.
8255 PPI
The 8255 PPI is used to interface the MSM5832 clock to the Z80 buss. This is needed because the MSM5832 is too slow of a device to attach directly to the Z80 buss.
The 8255 has three ports called “A”, “B”, and “C”. The module uses port “A” to xfer data to the MSM5832, port “B” to select the proper register in the MSM5832, and port “C” to toggle the control signals to the MSM5832. These three ports are accessed by writing or reading one of four registers in the 8255. Port “C” is also bit-addressable by writing a special code via the CONTROL register. This allows us to toggle a single control signal to the MSM5832 without having to “remember” what state the other three MSM5832 control signals were. The following is the table showing which registers control what in the 8255:
REGISTER PORT 0 A 1 B 2 C 3 CONTROL
The first action that should occure in your BASIC or machine language routine is to initialize the 8255 by clearing port “C” and then setting up the 8255 to write, or read the MSM5832 clock chip. This is done via register 3; the CONTROL register. To write to the MSM5832 you need to initialize the 8255 so that ports A,B, and C are all “output” ports. This is done by writing the control register in the 8255 with an 80HEX ( 128DEC ). To read the MSM5832 we’ll need to initialize the 8255 so that port A is an input port and ports B, and C are output ports. This is done by writing the CONTROL register in the 8255 with a 90HEX ( 144DEC ). A one-time action after powering up the computer is to initialize the 8255 ( to read or write the MSM5832) then “clear” port “C” by writing a ZERO to register 2. This resets the active-high control signals HOLD, RD, and WR to the MSM5832, and causes the MSM5832’s CS to go active via the inverter.
The 74HC138 is used to select a “block” of I/O ports to be used with the clock module. The HEX address of the ports always end in 3, 7, B, or F. So if the 74HC138 is strapped for “block five”, the I/O ports would be 53, 57, 5B, and 5F for 8255 registers 0, 1, 2, and 3, respectively. The following table summerizes the relationships:
8255 8255 reg TIMEX MSM5832 FUNCTION PORT ADDRESS HEX DEC A 0 53 83 DATA port B 1 57 87 REGISTER ADDRESS port C 2 5B 91 CONTROL port CNT 3 5F 95 ----------------------
The above table assumed a “block” of 5. You can re-strap to any of the eight blocks to avoid conflict with other devices attached to your computer.
We use a special function in the 8255 that allows us to change single bits in port “C” rather than “remembering” what all the bits should be in port “C”. This is done by writting a special code via the 8255’s CONTROL port 5F₁₆. The syntax of this code is as follows:
D7 D6 D5 D4 D3 D2 D1 D0
0 0 0 0 X X X SR
\ / 1 = SET
\ SELECTED / 0 = RESET
\ BIT /
000 = 0
001 = 1
etc.
MSM5832 CLOCK CHIP
The following table describes the various registers in the MSM5832 and their limits:
REGISTER COUNTER DATA I/O LIMITS NOTES ADDRESS D3 D2 D1 D0 0 S1 X X X X 0 - 9 1 1 S10 X X X 0 - 5 1 2 MI1 X X X X 0 - 9 3 MI10 X X X 0 - 5 4 H1 X X X X 0 - 9 5 H10 + + X X 0 - 2 2 6 W X X X 0 - 6 3 7 D1 X X X X 0 - 9 8 D10 + X X 0 - 3 4 9 MO1 X X X X 0 - 9 A MO10 X 0 - 1 B YR1 X X X X 0 - 9 C YR10 X X X X 0 - 9
NOTES
(1) Register set to zero when written to.
(2) D3=1 for 24hr or D3=0 for 12hr clock
D2=1 for PM or D2=0 for AM
(3) Days from Sunday. Sunday = 0, Monday =1, etc.
(4) D2=1 for leap year.
AN EXAMPLE
The following is an example showing how to read the day of the week from the clock module. Assume the module is mapped in block #5 ( ports 53, 57, 5B, 5F ).
(1) After powering up the computer write a 90₁₆ to the 8255 CONTROL port, 5F₁₆. This sets up the module to read the MSM5832 clock chip.
(2) As a one-time operation clear port “C” in the 8255 by writing a 0 to port 5B₁₆. This need only be done one time after powering up.
(3) Write the desired MSM5832 register address to port “B” of the 8255 by writting a 6 ( 6 = day of the week)to port 57₁₆.
(4) Strobe the MSM5832 RD signal active by writting a 0B₁₆ to the 8255’s CONTROL port 5F₁₆.
(5) Read the day of the week by executing an input instruction on port 53₁₆.
(6) Return the MSM5832 RD signal inactive by writting a 0A₁₆ to port 5F₁₆.
(7) You can now read any other MSM5832 register by following steps 3, 4, 5, and 6 using the desired MSM5832 register address in step 3.
To change the day of the week to Saturday (6):
(1) Initialize the 8255 to write the MSM5832 by writting an 80₁₆ to the 8255’s CONTROL port 5F₁₆.
(2) Select the day of the week register in the MSM5832 by writting a 6 to port 57₁₆.
(3) Latch the new day of the week in the 8255’s port A by writting a 6 ( Saturday) to port 53₁₆.
(4) Store this new data in the MSM5832 by toggeling the WR signal. This is done by writting a 0D₁₆ to port 5F₁₆. Then imediately follow by writting a 0C₁₆ to port 5F₁₆.
(5) You can now change any other MSM5832 register by writting the new register address to port 57₁₆, latching the new data via port 53₁₆, and toggling the MSM5832’s WR signal as in step 4.

