annotate src/rtc.asm @ 632:0347acdf6d8e

changelog updates
author heinrichsweikamp
date Sat, 29 Feb 2020 16:57:45 +0100
parents 185ba2f91f59
children 4050675965ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
3 ; File rtc.asm combined next generation V3.08.8
0
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ;
heinrichsweikamp
parents:
diff changeset
6 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
7 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
8 ; HISTORY
heinrichsweikamp
parents:
diff changeset
9 ; 2011-08-08 : [mH] moving from OSTC code
heinrichsweikamp
parents:
diff changeset
10
275
653a3ab08062 rename into hwOS
heinrichsweikamp
parents: 265
diff changeset
11 #include "hwos.inc"
0
heinrichsweikamp
parents:
diff changeset
12 #include "math.inc"
heinrichsweikamp
parents:
diff changeset
13
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 598
diff changeset
14 rtc CODE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
15
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
16 ;=============================================================================
0
heinrichsweikamp
parents:
diff changeset
17
heinrichsweikamp
parents:
diff changeset
18 global rtc_init
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
19 rtc_init:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
20 banksel isr_backup ; select bank ISR data
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
21 movlw .0 ; reset time to 12:00:00
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
22 movwf rtc_latched_secs ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
23 movlw .0 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
24 movwf rtc_latched_mins ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
25 movlw .12 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
26 movwf rtc_latched_hour ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
27 movlw firmware_creation_day ; reset date to firmware creation date
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
28 movwf rtc_latched_day ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
29 movlw firmware_creation_month ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
30 movwf rtc_latched_month ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
31 movlw firmware_creation_year ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
32 movwf rtc_latched_year ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
33 ;bra rtc_set_rtc ; set the real time clock
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
34
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
35 global rtc_set_rtc
0
heinrichsweikamp
parents:
diff changeset
36 rtc_set_rtc:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
37 banksel isr_backup ; select bank ISR data
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
38 movlw d'24' ; safeguard hour
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
39 cpfslt rtc_latched_hour ; hour < 24 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
40 clrf rtc_latched_hour ; NO - reset to 0
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
41 movlw d'60' ; safeguard minutes and seconds
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
42 cpfslt rtc_latched_mins ; minute < 60 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
43 clrf rtc_latched_mins ; NO - reset to 0
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
44 cpfslt rtc_latched_secs ; seconds < 60 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
45 clrf rtc_latched_secs ; NO - reset to 0
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
46 movlw d'100' ; safeguard year
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
47 cpfslt rtc_latched_year ; year < 100 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
48 clrf rtc_latched_year ; NO - reset to 0
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
49 movlw d'12' ; safeguard month
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
50 cpfslt rtc_latched_month ; month < 12 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
51 movwf rtc_latched_month ; NO - clip at 12
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
52
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
53 rcall rtc_check_day ; safeguard day
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
54 bsf block_rtc_access ; suspend the ISR from accessing the RTC
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
55
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
56 banksel 0xF16 ; addresses F16h through F5Fh are also used by SFRs, but are not part of the access RAM
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
57
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
58 movlw 0x55 ; | unlock sequence for RTCWREN, EECON2 is located in the access RAM
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
59 movwf EECON2 ; |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
60 movlw 0xAA ; |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
61 movwf EECON2 ; |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
62 bsf RTCCFG,RTCWREN ; | RTC write unlock, must follow directly after above unlock sequence!
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
63 bsf RTCCFG,RTCPTR1 ; |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
64 bsf RTCCFG,RTCPTR0 ; |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
65 movff rtc_latched_year,WREG ; get year
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
66 rcall rtc_dec2bcd ; IN: WREG in decimal, OUT: WREG in BCD, also sets to bank16h!
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
67 movwf RTCVALL ; write year
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
68 movwf RTCVALH ; dummy write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
69 movff rtc_latched_day,WREG ; get day
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
70 rcall rtc_dec2bcd ; IN: WREG in decimal, OUT: WREG in BCD, also sets to bank16h!
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
71 movwf RTCVALL ; write day
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
72 movff rtc_latched_month,WREG ; get month
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
73 rcall rtc_dec2bcd ; IN: WREG in decimal, OUT: WREG in BCD, also sets to bank16h!
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
74 movwf RTCVALH ; write month
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
75 movff rtc_latched_hour,WREG ; get hour
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
76 rcall rtc_dec2bcd ; IN: WREG in decimal, OUT: WREG in BCD, also sets to bank16h!
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
77 movwf RTCVALL ; write hour
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
78 movlw d'0' ; set weekday to 0 (unused)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
79 rcall rtc_dec2bcd ; IN: WREG in decimal, OUT: WREG in BCD, also sets to bank16h!
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
80 movwf RTCVALH ; (dummy) write weekday
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
81 movff rtc_latched_secs,WREG ; get seconds
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
82 rcall rtc_dec2bcd ; IN: WREG in decimal, OUT: WREG in BCD, also sets to bank16h!
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
83 movwf RTCVALL ; write seconds
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
84 movff rtc_latched_mins,WREG ; get minutes
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
85 rcall rtc_dec2bcd ; IN: WREG in decimal, OUT: WREG in BCD, also sets to bank16h!
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
86 movwf RTCVALH ; write minutes
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
87
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
88 movlw 0x55 ; | probably not needed when clearing RTCWREN
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
89 movwf EECON2 ; |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
90 movlw 0xAA ; |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
91 movwf EECON2 ; |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
92 bcf RTCCFG,RTCWREN ; lock sequence for RTCWREN
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
93
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
94 banksel common ; back to bank common
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
95
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
96 ; update the "live" RTC variables to bridge the time until the ISR reads the updated data from the RTC
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
97 movff rtc_latched_year, rtc_year
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
98 movff rtc_latched_month,rtc_month
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
99 movff rtc_latched_day, rtc_day
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
100 movff rtc_latched_hour, rtc_hour
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
101 movff rtc_latched_mins, rtc_mins
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
102 movff rtc_latched_secs, rtc_secs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
103
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
104 bcf block_rtc_access ; allow the ISR to access the RTC again
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
105 return ; done
0
heinrichsweikamp
parents:
diff changeset
106
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
107
0
heinrichsweikamp
parents:
diff changeset
108 rtc_dec2bcd:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
109 banksel common ; switch to bank common
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
110 movwf lo ; input in decimal
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
111 setf hi ; 10s
0
heinrichsweikamp
parents:
diff changeset
112 rtc_dec2bcd2:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
113 incf hi,F ; count 10's
0
heinrichsweikamp
parents:
diff changeset
114 movlw d'10'
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
115 subwf lo,F
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
116 btfss STATUS,N ; result negative?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
117 bra rtc_dec2bcd2 ; NO - loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
118 movlw d'10' ; YES -
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
119 addwf lo,F ; - 1s
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
120 swapf hi,W ; - swap to bit 7-4 -> WREG
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
121 addwf lo,W ; - result in BCD
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
122 banksel 0xF16 ; - switch back to bank for I/O registers
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
123 return ; - done
0
heinrichsweikamp
parents:
diff changeset
124
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
125
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
126 ; wrap-around the month depending on the number of days per month
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
127 ; Attention: needs to be called in bank isr_backup!
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
128 rtc_check_day:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
129 movlw .28 ; the default February has 28 days
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
130 btfsc rtc_latched_year,0 ; is the year an even year?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
131 bra rtc_check_day_1 ; NO - keep the 28 days
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
132 btfss rtc_latched_year,1 ; YES - is it a multiple of 4 years?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
133 movlw .29 ; YES - leap year, February has 29 days
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
134 rtc_check_day_1:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
135 movwf backup_hi ; store highest day in February in backup_hi
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
136 decf rtc_latched_month,W ; compute month - 1 and...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
137 movwf backup_lo ; store result in backup_lo
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
138 movlw .31 ; default highest day is 31
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
139 dcfsnz backup_lo,F ; month = February?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
140 movf backup_hi,W ; YES - highest day is 28/29
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
141 dcfsnz backup_lo,F ; month = March?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
142 movlw .31 ; YES - highest day is 31
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
143 dcfsnz backup_lo,F ; month = April?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
144 movlw .30 ; YES - highest day is 30
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
145 dcfsnz backup_lo,F ; month = May?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
146 movlw .31 ; YES - highest day is 31
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
147 dcfsnz backup_lo,F ; month = June?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
148 movlw .30 ; YES - highest day is 30
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
149 dcfsnz backup_lo,F ; month = July?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
150 movlw .31 ; YES - highest day is 31
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
151 dcfsnz backup_lo,F ; month = August?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
152 movlw .31 ; YES - highest day = 31
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
153 dcfsnz backup_lo,F ; month = September?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
154 movlw .30 ; YES - highest day = 30
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
155 dcfsnz backup_lo,F ; month = October?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
156 movlw .31 ; YES - highest day = 31
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
157 dcfsnz backup_lo,F ; month = November?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
158 movlw .30 ; YES - highest day = 30
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
159 dcfsnz backup_lo,F ; month = December?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
160 movlw .31 ; YES - highest day = 31
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
161 cpfsgt rtc_latched_day ; current day > highest day?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
162 retlw .1 ; NO - done, signal day was ok
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
163 movlw .1 ; YES - wrap around to 1st day in month
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
164 movwf rtc_latched_day ; - ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
165 retlw .0 ; - done, signal a correction was made
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
166
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
167
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
168 ; Add minutes in mpr:2 to the time/date in in rtc_latched and rounds up/down to next full minute
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
169 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
170 ; Attention: This code works for a maximum of 1439 minutes to add (23 hours, 59 minutes)!
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
171 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
172 global rtc_add_minutes
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
173 rtc_add_minutes:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
174 call convert_time ; convert minutes in hi:lo to hours (up:hi) and minutes (lo)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
175 banksel isr_backup ; switch to bank isr_backup
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
176 bcf STATUS,C ; clear carry bit
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
177 movlw .30 ; rounding point for seconds
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
178 cpfslt rtc_latched_secs ; seconds < rounding point?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
179 bsf STATUS,C ; NO - set carry bit -> round up to next full minute
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
180 clrf rtc_latched_secs ; set the second to zero
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
181 movff lo,WREG ; get minutes to add
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
182 addwfc rtc_latched_mins,F ; add minutes to add
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
183 movlw .59 ; limit for minute
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
184 cpfsgt rtc_latched_mins ; resulting minute > 59 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
185 bra rtc_add_minutes_1 ; NO - minute is ok
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
186 movlw .60 ; YES - subtract 60 from resulting minute
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
187 subwf rtc_latched_mins,F ; - ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
188 bsf STATUS,C ; - set carry bit
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
189 rtc_add_minutes_1:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
190 movff hi,WREG ; get hours to add
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
191 addwfc rtc_latched_hour,F ; add hours to add plus carry bit
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
192 movlw .23 ; limit for hour
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
193 cpfsgt rtc_latched_hour ; resulting hour > 23 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
194 bra rtc_add_minutes_2 ; NO - hour is ok
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
195 movlw .24 ; YES - subtract 24 from resulting hour
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
196 subwf rtc_latched_hour ; - ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
197 bsf STATUS,C ; - set carry bit
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
198 rtc_add_minutes_2:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
199 clrf WREG ; create a zero
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
200 addwfc rtc_latched_day,F ; add the carry bit
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
201 rcall rtc_check_day ; check & correct the resulting day with respect to #days in month
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
202 tstfsz WREG ; was the day beyond the last day of the month before correction?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
203 bra rtc_add_minutes_3 ; NO - done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
204 banksel isr_backup ; YES - select bank isr_backup again
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
205 incf rtc_latched_month,F ; - increment month
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
206 movlw .12 ; - limit for month
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
207 cpfsgt rtc_latched_month ; - resulting month > 12 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
208 bra rtc_add_minutes_3 ; NO - month is ok
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
209 subwf rtc_latched_month,F ; YES - subtract 12 from resulting month (actually sets back to January)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
210 incf rtc_latched_year,F ; - increment year
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
211 rtc_add_minutes_3
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
212 banksel common ; back to bank common
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
213 return ; done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
214
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
215 ;-----------------------------------------------------------------------------
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
216
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
217 END