Mercurial > public > hwos_code
comparison src/rtc.asm @ 634:4050675965ea
3.10 stable release
author | heinrichsweikamp |
---|---|
date | Tue, 28 Apr 2020 17:34:31 +0200 |
parents | 185ba2f91f59 |
children | 75e90cd0c2c3 |
comparison
equal
deleted
inserted
replaced
633:690c48db7b5b | 634:4050675965ea |
---|---|
1 ;============================================================================= | 1 ;============================================================================= |
2 ; | 2 ; |
3 ; File rtc.asm combined next generation V3.08.8 | 3 ; File rtc.asm * combined next generation V3.09.4k |
4 ; | 4 ; |
5 ; | 5 ; |
6 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | 6 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. |
7 ;============================================================================= | 7 ;============================================================================= |
8 ; HISTORY | 8 ; HISTORY |
9 ; 2011-08-08 : [mH] moving from OSTC code | 9 ; 2011-08-08 : [mH] moving from OSTC code |
10 | 10 |
11 #include "hwos.inc" | 11 #include "hwos.inc" |
12 #include "math.inc" | 12 #include "math.inc" |
13 | 13 #include "convert.inc" |
14 rtc CODE | 14 |
15 | 15 |
16 ;============================================================================= | 16 ;============================================================================= |
17 | 17 rtc1 CODE |
18 ;============================================================================= | |
19 | |
20 | |
21 ;----------------------------------------------------------------------------- | |
22 ; Initialize RTC to Firmware creation Date | |
23 ; | |
18 global rtc_init | 24 global rtc_init |
19 rtc_init: | 25 rtc_init: |
20 banksel isr_backup ; select bank ISR data | 26 banksel isr_backup ; select bank ISR data |
21 movlw .0 ; reset time to 12:00:00 | 27 movlw .0 ; reset time to 12:00:00 |
22 movwf rtc_latched_secs ; ... | 28 movwf rtc_latched_secs ; ... |
30 movwf rtc_latched_month ; ... | 36 movwf rtc_latched_month ; ... |
31 movlw firmware_creation_year ; ... | 37 movlw firmware_creation_year ; ... |
32 movwf rtc_latched_year ; ... | 38 movwf rtc_latched_year ; ... |
33 ;bra rtc_set_rtc ; set the real time clock | 39 ;bra rtc_set_rtc ; set the real time clock |
34 | 40 |
41 | |
42 ;----------------------------------------------------------------------------- | |
43 ; Set new Time & Date | |
44 ; | |
35 global rtc_set_rtc | 45 global rtc_set_rtc |
36 rtc_set_rtc: | 46 rtc_set_rtc: |
37 banksel isr_backup ; select bank ISR data | 47 banksel isr_backup ; select bank ISR data |
38 movlw d'24' ; safeguard hour | 48 movlw d'24' ; safeguard hour |
39 cpfslt rtc_latched_hour ; hour < 24 ? | 49 cpfslt rtc_latched_hour ; hour < 24 ? |
103 | 113 |
104 bcf block_rtc_access ; allow the ISR to access the RTC again | 114 bcf block_rtc_access ; allow the ISR to access the RTC again |
105 return ; done | 115 return ; done |
106 | 116 |
107 | 117 |
118 ;----------------------------------------------------------------------------- | |
119 ; Helper Function - convert from decimal to BCD | |
120 ; | |
108 rtc_dec2bcd: | 121 rtc_dec2bcd: |
109 banksel common ; switch to bank common | 122 banksel common ; switch to bank common |
110 movwf lo ; input in decimal | 123 movwf lo ; input in decimal |
111 setf hi ; 10s | 124 setf hi ; 10s |
112 rtc_dec2bcd2: | 125 rtc_dec2bcd2: |
113 incf hi,F ; count 10's | 126 incf hi,F ; count 10's |
114 movlw d'10' | 127 movlw d'10' ; ... |
115 subwf lo,F | 128 subwf lo,F ; ... |
116 btfss STATUS,N ; result negative? | 129 btfss STATUS,N ; result negative? |
117 bra rtc_dec2bcd2 ; NO - loop | 130 bra rtc_dec2bcd2 ; NO - loop |
118 movlw d'10' ; YES - | 131 movlw d'10' ; YES - |
119 addwf lo,F ; - 1s | 132 addwf lo,F ; - 1s |
120 swapf hi,W ; - swap to bit 7-4 -> WREG | 133 swapf hi,W ; - swap to bit 7-4 -> WREG |
121 addwf lo,W ; - result in BCD | 134 addwf lo,W ; - result in BCD |
122 banksel 0xF16 ; - switch back to bank for I/O registers | 135 banksel 0xF16 ; - switch back to bank for I/O registers |
123 return ; - done | 136 return ; - done |
124 | 137 |
125 | 138 |
139 ;----------------------------------------------------------------------------- | |
140 ; Helper Function - check Validity of Day according to Month | |
141 ; | |
126 ; wrap-around the month depending on the number of days per month | 142 ; wrap-around the month depending on the number of days per month |
143 ; | |
127 ; Attention: needs to be called in bank isr_backup! | 144 ; Attention: needs to be called in bank isr_backup! |
145 ; | |
128 rtc_check_day: | 146 rtc_check_day: |
129 movlw .28 ; the default February has 28 days | 147 movlw .28 ; the default February has 28 days |
130 btfsc rtc_latched_year,0 ; is the year an even year? | 148 btfsc rtc_latched_year,0 ; is the year an even year? |
131 bra rtc_check_day_1 ; NO - keep the 28 days | 149 bra rtc_check_day_1 ; NO - keep the 28 days |
132 btfss rtc_latched_year,1 ; YES - is it a multiple of 4 years? | 150 btfss rtc_latched_year,1 ; YES - is it a multiple of 4 years? |
163 movlw .1 ; YES - wrap around to 1st day in month | 181 movlw .1 ; YES - wrap around to 1st day in month |
164 movwf rtc_latched_day ; - ... | 182 movwf rtc_latched_day ; - ... |
165 retlw .0 ; - done, signal a correction was made | 183 retlw .0 ; - done, signal a correction was made |
166 | 184 |
167 | 185 |
168 ; Add minutes in mpr:2 to the time/date in in rtc_latched and rounds up/down to next full minute | 186 ;============================================================================= |
169 ; | 187 rtc2 CODE |
170 ; Attention: This code works for a maximum of 1439 minutes to add (23 hours, 59 minutes)! | 188 ;============================================================================= |
189 | |
190 ;----------------------------------------------------------------------------- | |
191 ; Add minutes in mpr:2 to the time/date in in rtc_latched and rounds up/down | |
192 ; to next full minute | |
193 ; | |
194 ; Attention: | |
195 ; This code works for a maximum of 1439 minutes to add (23 hours, 59 minutes)! | |
171 ; | 196 ; |
172 global rtc_add_minutes | 197 global rtc_add_minutes |
173 rtc_add_minutes: | 198 rtc_add_minutes: |
174 call convert_time ; convert minutes in hi:lo to hours (up:hi) and minutes (lo) | 199 call convert_time ; convert minutes in hi:lo to hours (up:hi) and minutes (lo) |
175 banksel isr_backup ; switch to bank isr_backup | 200 banksel isr_backup ; switch to bank isr_backup |
196 subwf rtc_latched_hour ; - ... | 221 subwf rtc_latched_hour ; - ... |
197 bsf STATUS,C ; - set carry bit | 222 bsf STATUS,C ; - set carry bit |
198 rtc_add_minutes_2: | 223 rtc_add_minutes_2: |
199 clrf WREG ; create a zero | 224 clrf WREG ; create a zero |
200 addwfc rtc_latched_day,F ; add the carry bit | 225 addwfc rtc_latched_day,F ; add the carry bit |
201 rcall rtc_check_day ; check & correct the resulting day with respect to #days in month | 226 call rtc_check_day ; check & correct the resulting day with respect to #days in month |
202 tstfsz WREG ; was the day beyond the last day of the month before correction? | 227 tstfsz WREG ; was the day beyond the last day of the month before correction? |
203 bra rtc_add_minutes_3 ; NO - done | 228 bra rtc_add_minutes_3 ; NO - done |
204 banksel isr_backup ; YES - select bank isr_backup again | 229 banksel isr_backup ; YES - select bank isr_backup again |
205 incf rtc_latched_month,F ; - increment month | 230 incf rtc_latched_month,F ; - increment month |
206 movlw .12 ; - limit for month | 231 movlw .12 ; - limit for month |