Mercurial > public > mk2
comparison code_part1/OSTC_code_asm_part1/sync_clock.asm @ 0:96a35aeda5f2
Initial setup
author | heinrichsweikamp |
---|---|
date | Tue, 12 Jan 2010 15:05:59 +0100 |
parents | |
children | 73014f788032 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:96a35aeda5f2 |
---|---|
1 | |
2 | |
3 ; OSTC - diving computer code | |
4 | |
5 ; Copyright (C) 2008 HeinrichsWeikamp GbR | |
6 | |
7 | |
8 | |
9 ; This program is free software: you can redistribute it and/or modify | |
10 | |
11 ; it under the terms of the GNU General Public License as published by | |
12 | |
13 ; the Free Software Foundation, either version 3 of the License, or | |
14 | |
15 ; (at your option) any later version. | |
16 | |
17 | |
18 | |
19 ; This program is distributed in the hope that it will be useful, | |
20 | |
21 ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | |
23 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | |
25 ; GNU General Public License for more details. | |
26 | |
27 | |
28 | |
29 ; You should have received a copy of the GNU General Public License | |
30 | |
31 ; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 ; Syncs RTC with PC | |
38 | |
39 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com | |
40 | |
41 ; written: 13/10/07 | |
42 | |
43 ; last updated: 08/08/31 | |
44 | |
45 ; known bugs: | |
46 | |
47 ; ToDo: | |
48 | |
49 | |
50 | |
51 ; routine echoes the "b" command as ready signal | |
52 | |
53 ; PC has to send 6 bytes | |
54 | |
55 ; Byte1: hours | |
56 | |
57 ; Byte2: minutes | |
58 | |
59 ; Byte3: seconds | |
60 | |
61 ; Byte4: month | |
62 | |
63 ; Byte5: day | |
64 | |
65 ; Byte6: year | |
66 | |
67 ; All bytes will be checked for plausibility and the clock will be set | |
68 | |
69 ; after a timeout of about 20ms, the routine ends | |
70 | |
71 | |
72 | |
73 sync_clock: | |
74 | |
75 bcf uart_settime ; clear flag | |
76 | |
77 bcf PIE1,RCIE ; no interrupt for UART | |
78 | |
79 call set_LEDusb ; LEDusb ON | |
80 | |
81 bcf PIR1,RCIF ; clear flag | |
82 | |
83 | |
84 | |
85 movlw "b" ; send echo | |
86 | |
87 movwf TXREG | |
88 | |
89 call rs232_wait_tx ; wait for UART | |
90 | |
91 | |
92 | |
93 call rs232_get_byte ; hours | |
94 | |
95 movff RCREG, hours | |
96 | |
97 | |
98 | |
99 movlw d'24' | |
100 | |
101 cpfslt hours | |
102 | |
103 clrf hours | |
104 | |
105 | |
106 | |
107 call rs232_get_byte ; minutes | |
108 | |
109 movff RCREG, mins | |
110 | |
111 | |
112 | |
113 movlw d'60' | |
114 | |
115 cpfslt mins | |
116 | |
117 clrf mins | |
118 | |
119 | |
120 | |
121 call rs232_get_byte ; seconds | |
122 | |
123 movff RCREG, secs | |
124 | |
125 | |
126 | |
127 movlw d'60' | |
128 | |
129 cpfslt secs | |
130 | |
131 clrf secs | |
132 | |
133 | |
134 | |
135 call rs232_get_byte ; month | |
136 | |
137 movff RCREG, month | |
138 | |
139 | |
140 | |
141 movlw d'12' | |
142 | |
143 cpfsgt month | |
144 | |
145 bra sync_clock0 | |
146 | |
147 movwf month | |
148 | |
149 | |
150 | |
151 sync_clock0: | |
152 | |
153 call rs232_get_byte ; day | |
154 | |
155 movff RCREG, day | |
156 | |
157 | |
158 | |
159 movff month,lo ; new month | |
160 | |
161 dcfsnz lo,F | |
162 | |
163 movlw .31 | |
164 | |
165 dcfsnz lo,F | |
166 | |
167 movlw .28 | |
168 | |
169 dcfsnz lo,F | |
170 | |
171 movlw .31 | |
172 | |
173 dcfsnz lo,F | |
174 | |
175 movlw .30 | |
176 | |
177 dcfsnz lo,F | |
178 | |
179 movlw .31 | |
180 | |
181 dcfsnz lo,F | |
182 | |
183 movlw .30 | |
184 | |
185 dcfsnz lo,F | |
186 | |
187 movlw .31 | |
188 | |
189 dcfsnz lo,F | |
190 | |
191 movlw .31 | |
192 | |
193 dcfsnz lo,F | |
194 | |
195 movlw .30 | |
196 | |
197 dcfsnz lo,F | |
198 | |
199 movlw .31 | |
200 | |
201 dcfsnz lo,F | |
202 | |
203 movlw .30 | |
204 | |
205 dcfsnz lo,F | |
206 | |
207 movlw .31 | |
208 | |
209 cpfsgt day ; day ok? | |
210 | |
211 bra sync_clock1 ; OK | |
212 | |
213 movlw .1 ; not OK, set to 1st | |
214 | |
215 movwf day | |
216 | |
217 | |
218 | |
219 sync_clock1: | |
220 | |
221 call rs232_get_byte ; year | |
222 | |
223 movff RCREG, year | |
224 | |
225 | |
226 | |
227 movlw d'100' | |
228 | |
229 cpfslt year | |
230 | |
231 clrf year | |
232 | |
233 | |
234 | |
235 call clear_LEDusb ; LEDusb OFF | |
236 | |
237 bcf PIR1,RCIF ; clear flag | |
238 | |
239 bsf oneminupdate ; set flag, so new time and date will be updated in surfacemode at once | |
240 | |
241 bsf PIE1,RCIE ; enable interrupt for UART | |
242 | |
243 goto surfloop_loop ; return to surface loop | |
244 | |
245 | |
246 | |
247 | |
248 |