-
Notifications
You must be signed in to change notification settings - Fork 1
/
rtc.z80
77 lines (70 loc) · 1.46 KB
/
rtc.z80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
; Basic driver for TI BQ4845 RTC
; Register definitions
.SEC: equ RTCBASE + 0x00 ; Seconds
.SECALM: equ RTCBASE + 0x01 ; Seconds alarm
.MIN: equ RTCBASE + 0x02 ; Minutes
.MINALM: equ RTCBASE + 0x03 ; Minutes alarm
.HR: equ RTCBASE + 0x04 ; Hours
.HRALM: equ RTCBASE + 0x05 ; Hours alarm
.DAY: equ RTCBASE + 0x06 ; Day
.DAYALM: equ RTCBASE + 0x07 ; Day alarm
.DOW: equ RTCBASE + 0x08 ; Day of week
.MTH: equ RTCBASE + 0x09 ; Month
.YR: equ RTCBASE + 0x0A ; Year
.RATES: equ RTCBASE + 0x0B ; Programmable rates
.IE: equ RTCBASE + 0x0C ; Interrupt enables
.FLGS: equ RTCBASE + 0x0D ; Flags
.CTRL: equ RTCBASE + 0x0E ; Control
.UNSD: equ RTCBASE + 0x0F ; Unused
SetUpdateInhibit:
ld a, 00001110b
out (.CTRL), a
ret
UnsetUpdateInhibit:
ld a, 00000110b
out (.CTRL), a
ret
SetPeriodicIntRate:
and 00001111b ; Mask off non-rate bits
out (.RATES), a
ret
EnablePeriodicInt:
ld a, 00000100b
out (.IE), a
ret
DisablePeriodicInt:
ld a, 00000000b
out (.IE), a
ret
SetRTC:
call SetUpdateInhibit
ld a, b
out (.SEC), a
ld a, c
out (.MIN), a
ld a, d
out (.HR), a
ld a, e
out (.DAY), a
ld a, h
out (.MTH), a
ld a, l
out (.YR), a
call UnsetUpdateInhibit
ret
GetRTC:
call SetUpdateInhibit
in a, (.SEC) ; Read seconds
ld b, a
in a, (.MIN) ; Read minutes
ld c, a
in a, (.HR) ; Read hours
ld d, a
in a, (.DAY) ; Read day
ld e, a
in a, (.MTH) ; Read month
ld h, a
in a, (.YR) ; Read year
ld l, a
call UnsetUpdateInhibit
ret