| [fastpc] | [ciaide] | [geos] | [linux] | [projects] | [software] | [contact] |
DS12C887 is more than just a Y2K-compliant RTC. It has internal lithium battery which backs up the clock and internal RAM - yes it has 113 bytes of non-volatile RAM free for your usage.
For more information on how to build an additional address decoder look into CIA-IDE documentation.
Here is Chris Ward's interface for DS1687 chip (similar to DS12C887), it was taken from his page:

DS12C887 application is quite similar, but ignore Vbaux and /RCLR signals, they are not present here.
Below is the schematic of the interface. I used one gate from 74'00 as inverter but you might want to use 74'02 in the same way or 1/6th of 74'04 (a real inverter). There is also a minor change - /RTC signal (/SELECT) on the picture above) is connected to both /E1 and /E2 (G2A, G2B) inputs of '138.
Input lines (data, R/W, phi2) are easy accessible on Expansion Port or processor itself.

Click here for PDF version (better quality) and gEDA schematic source file.
Leave the rest of pins unconnected. SQW pin is an output from RTC, it can generate a square wave with given frequency there - this is only an option. The same applies to /RESET and /IRQ lines - connect them if you need them.
Here is a general photo of the RTC chip installed in my C128DCR. I used 1571 part of the board to
mount the chip on top of another one to get the power. The rest of lines is soldered to C128 parts.
Click to enlarge.

I don't want to copy whole data sheet (here is local copy). Better grab it and read it carefully.
Anyway here are some snippets of code. All of them assume that RTC base address is at $DE00 (line /IO1 used as /RTC).
; This one reads the current second LDA #$00 ; register 0 - seconds STA $DE00 ; address register LDA $DE01 ; data register
Replace 'LDA $DE01' with 'STA $DE01' to have an example for write.
Here is example for reading whole RTC RAM into C64 screen memory:
LDX #0
loop STX $DE00
LDA $DE01
STA $0400,X
INX
CPX #$80
BNE loop
RTS
Don't get confused if the clock doesn't advance. It took me some time to figure it out, but careful reading of datasheet was enough :). These chips leave the factory with clock oscillator turned off to save battery power. It needs to be enabled with following code:
LDX #$0a ; control register A
LDA #$20 ; %x010xxxx
STX $DE00
STA $DE01
RTS
Everything else concerning programming the RTC chip is included in data sheet mentioned before.
You can download a BASIC example on setting up CIA1 TOD clock from RTC data (setting RTC doesn't work from BASIC).
You can also download a GEOS Auto-Exec to set and read time from RTC. It will set the time each time you boot GEOS. You can also set the RTC time with it. It comes with source code. Use it if you want 6502 assembly example.
This circuit has been tested on C64 and finally it is installed in my C128DCR.