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