-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset_time.bsp
130 lines (95 loc) · 1.91 KB
/
reset_time.bsp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
' {$STAMP BS2p}
' {$PBASIC 2.5}
' Reset time
' {$PORT COM4}
addr VAR Word
value VAR Byte
'' Begin program
' sec, min, hour, date, month, weekday year
DATE_TIME DATA $55, $43, $12, $11, $03, $02, $19
C_SEC CON 0
C_MIN CON 1
C_HOUR CON 2
C_DATE CON 3
C_MONTH CON 4
C_DAY CON 5
C_YEAR CON 6
CONTROL CON 7
TRICKLE CON 8
BURST CON 31
rtc PIN 10
sdat PIN 11
sclk PIN 12
DEBUG "Reset clock program"
DEBUG "Reading clock", CR
GOSUB DISPLAY_DATE_TIME
'STOP
GOSUB RESET_TIME
PAUSE 300
GOSUB DISPLAY_DATE_TIME
DEBUG "All done.", CR
'GOSUB PRINT_DATA
STOP
DISPLAY_DATE_TIME:
DEBUG "The datetime is "
addr = C_YEAR
GOSUB _GET_TIME
DEBUG HEX2 value, "/"
addr = C_MONTH
GOSUB _GET_TIME
DEBUG HEX2 value, "/"
addr = C_DATE
GOSUB _GET_TIME
DEBUG HEX2 value, " "
addr = C_HOUR
GOSUB _GET_TIME
DEBUG HEX2 value, ":"
addr = C_MIN
GOSUB _GET_TIME
DEBUG HEX2 value, ":"
addr = C_SEC
GOSUB _GET_TIME
DEBUG HEX2 value
addr = C_DAY
GOSUB _GET_TIME
DEBUG "(", HEX1 value, ")", CR
RETURN
_GET_TIME:
LOW rtc
LOW sclk
HIGH rtc
SHIFTOUT sdat, sclk, LSBFIRST, [$81|(addr<<1)\8]
SHIFTIN sdat, sclk, LSBPRE, [value\8]
LOW rtc
RETURN
RESET_TIME:
DEBUG "Resetting time...", CR
LOW rtc
LOW sclk
HIGH rtc
SHIFTOUT sdat, sclk, LSBFIRST, [$80|(CONTROL<<1)\8]
SHIFTOUT sdat, sclk, LSBFIRST, [$00\8]
LOW rtc
'DEBUG "Looping now", CR
FOR addr=0 TO 6
READ DATE_TIME+addr, value
'DEBUG DEC addr, ": ", HEX2 value, CR
GOSUB _PUT_TIME
NEXT
LOW rtc
LOW sclk
HIGH rtc
SHIFTOUT sdat, sclk, LSBFIRST, [$80|(CONTROL<<1)\8]
SHIFTOUT sdat, sclk, LSBFIRST, [$80\8]
LOW rtc
DEBUG "Complete.", CR
RETURN
_PUT_TIME:
'DEBUG "Writing time", CR
LOW rtc
LOW sclk
HIGH rtc
SHIFTOUT sdat, sclk, LSBFIRST, [$80|(addr<<1)\8]
SHIFTOUT sdat, sclk, LSBFIRST, [value\8]
LOW rtc
RETURN