Mercurial > public > mk2
annotate code_part1/OSTC_code_asm_part1/sync_clock.asm @ 813:c87b9f2fb2f6
wakeup from deep sleep mode automatically upon USB connect
author | heinrichsweikamp |
---|---|
date | Tue, 14 Apr 2015 14:50:11 +0200 |
parents | c50296c3059e |
children | 2a0e5d884fc3 |
rev | line source |
---|---|
21 | 1 |
2 ; OSTC - diving computer code | |
807
c50296c3059e
BUGFIX: Divetime had unwanted "." behind the minutes
heinrichsweikamp
parents:
21
diff
changeset
|
3 ; Copyright (C) 2015 HeinrichsWeikamp GbR |
21 | 4 |
5 ; This program is free software: you can redistribute it and/or modify | |
6 ; it under the terms of the GNU General Public License as published by | |
7 ; the Free Software Foundation, either version 3 of the License, or | |
8 ; (at your option) any later version. | |
9 | |
10 ; This program is distributed in the hope that it will be useful, | |
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 ; GNU General Public License for more details. | |
14 | |
15 ; You should have received a copy of the GNU General Public License | |
16 ; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | |
18 | |
19 ; Syncs RTC with PC | |
20 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com | |
21 ; written: 13/10/07 | |
22 ; last updated: 08/08/31 | |
23 ; known bugs: | |
24 ; ToDo: | |
25 | |
26 ; routine echoes the "b" command as ready signal | |
27 ; PC has to send 6 bytes | |
28 ; Byte1: hours | |
29 ; Byte2: minutes | |
30 ; Byte3: seconds | |
31 ; Byte4: month | |
32 ; Byte5: day | |
33 ; Byte6: year | |
34 ; All bytes will be checked for plausibility and the clock will be set | |
35 ; after a timeout of about 20ms, the routine ends | |
36 | |
37 sync_clock: | |
38 bcf uart_settime ; clear flag | |
39 bcf PIE1,RCIE ; no interrupt for UART | |
40 bsf LED_blue ; LEDusb ON | |
41 bcf PIR1,RCIF ; clear flag | |
42 | |
43 movlw "b" ; send echo | |
44 movwf TXREG | |
45 call rs232_wait_tx ; wait for UART | |
46 | |
47 call rs232_get_byte ; hours | |
48 movff RCREG, hours | |
49 | |
50 movlw d'24' | |
51 cpfslt hours | |
52 clrf hours | |
53 | |
54 call rs232_get_byte ; minutes | |
55 movff RCREG, mins | |
56 | |
57 movlw d'60' | |
58 cpfslt mins | |
59 clrf mins | |
60 | |
61 call rs232_get_byte ; seconds | |
62 movff RCREG, secs | |
63 | |
64 movlw d'60' | |
65 cpfslt secs | |
66 clrf secs | |
67 | |
68 call rs232_get_byte ; month | |
69 movff RCREG, month | |
70 | |
71 movlw d'12' | |
72 cpfsgt month | |
73 bra sync_clock0 | |
74 movwf month | |
75 | |
76 sync_clock0: | |
77 call rs232_get_byte ; day | |
78 movff RCREG, day | |
79 | |
80 movff month,lo ; new month | |
81 dcfsnz lo,F | |
82 movlw .31 | |
83 dcfsnz lo,F | |
84 movlw .28 | |
85 dcfsnz lo,F | |
86 movlw .31 | |
87 dcfsnz lo,F | |
88 movlw .30 | |
89 dcfsnz lo,F | |
90 movlw .31 | |
91 dcfsnz lo,F | |
92 movlw .30 | |
93 dcfsnz lo,F | |
94 movlw .31 | |
95 dcfsnz lo,F | |
96 movlw .31 | |
97 dcfsnz lo,F | |
98 movlw .30 | |
99 dcfsnz lo,F | |
100 movlw .31 | |
101 dcfsnz lo,F | |
102 movlw .30 | |
103 dcfsnz lo,F | |
104 movlw .31 | |
105 cpfsgt day ; day ok? | |
106 bra sync_clock1 ; OK | |
107 movlw .1 ; not OK, set to 1st | |
108 movwf day | |
109 | |
110 sync_clock1: | |
111 call rs232_get_byte ; year | |
112 movff RCREG, year | |
113 | |
114 movlw d'100' | |
115 cpfslt year | |
116 clrf year | |
117 | |
118 bcf LED_blue ; LEDusb OFF | |
119 bcf PIR1,RCIF ; clear flag | |
120 bsf oneminupdate ; set flag, so new time and date will be updated in surfacemode at once | |
121 bsf PIE1,RCIE ; enable interrupt for UART | |
122 goto surfloop_loop ; return to surface loop |