annotate src/rtc.asm @ 653:8bcd138ab744

add tools/o3pack.bat and the required tools/libs
author heinrichsweikamp
date Fri, 11 Aug 2023 15:53:49 +0200
parents 4050675965ea
children 75e90cd0c2c3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
3 ; File rtc.asm * combined next generation V3.09.4k
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"
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
13 #include "convert.inc"
0
heinrichsweikamp
parents:
diff changeset
14
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 ;=============================================================================
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
17 rtc1 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
18 ;=============================================================================
0
heinrichsweikamp
parents:
diff changeset
19
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
20
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
21 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
22 ; Initialize RTC to Firmware creation Date
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
23 ;
0
heinrichsweikamp
parents:
diff changeset
24 global rtc_init
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
25 rtc_init:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
26 banksel isr_backup ; select bank ISR data
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
27 movlw .0 ; reset time to 12:00:00
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
28 movwf rtc_latched_secs ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
29 movlw .0 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
30 movwf rtc_latched_mins ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
31 movlw .12 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
32 movwf rtc_latched_hour ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
33 movlw firmware_creation_day ; reset date to firmware creation date
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
34 movwf rtc_latched_day ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
35 movlw firmware_creation_month ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
36 movwf rtc_latched_month ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
37 movlw firmware_creation_year ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
38 movwf rtc_latched_year ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
39 ;bra rtc_set_rtc ; set the real time clock
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
40
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
41
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
42 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
43 ; Set new Time & Date
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
44 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
45 global rtc_set_rtc
0
heinrichsweikamp
parents:
diff changeset
46 rtc_set_rtc:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
47 banksel isr_backup ; select bank ISR data
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
48 movlw d'24' ; safeguard hour
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
49 cpfslt rtc_latched_hour ; hour < 24 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
50 clrf rtc_latched_hour ; NO - reset to 0
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
51 movlw d'60' ; safeguard minutes and seconds
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
52 cpfslt rtc_latched_mins ; minute < 60 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
53 clrf rtc_latched_mins ; NO - reset to 0
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
54 cpfslt rtc_latched_secs ; seconds < 60 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
55 clrf rtc_latched_secs ; NO - reset to 0
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
56 movlw d'100' ; safeguard year
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
57 cpfslt rtc_latched_year ; year < 100 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
58 clrf rtc_latched_year ; NO - reset to 0
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
59 movlw d'12' ; safeguard month
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
60 cpfslt rtc_latched_month ; month < 12 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
61 movwf rtc_latched_month ; NO - clip at 12
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
62
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
63 rcall rtc_check_day ; safeguard day
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
64 bsf block_rtc_access ; suspend the ISR from accessing the RTC
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
65
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
66 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
67
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
68 movlw 0x55 ; | unlock sequence for RTCWREN, EECON2 is located in the access RAM
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
69 movwf EECON2 ; |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
70 movlw 0xAA ; |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
71 movwf EECON2 ; |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
72 bsf RTCCFG,RTCWREN ; | RTC write unlock, must follow directly after above unlock sequence!
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
73 bsf RTCCFG,RTCPTR1 ; |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
74 bsf RTCCFG,RTCPTR0 ; |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
75 movff rtc_latched_year,WREG ; get year
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 year
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
78 movwf RTCVALH ; dummy write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
79 movff rtc_latched_day,WREG ; get day
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
80 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
81 movwf RTCVALL ; write day
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
82 movff rtc_latched_month,WREG ; get month
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
83 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
84 movwf RTCVALH ; write month
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
85 movff rtc_latched_hour,WREG ; get hour
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
86 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
87 movwf RTCVALL ; write hour
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
88 movlw d'0' ; set weekday to 0 (unused)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
89 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
90 movwf RTCVALH ; (dummy) write weekday
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
91 movff rtc_latched_secs,WREG ; get seconds
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
92 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
93 movwf RTCVALL ; write seconds
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
94 movff rtc_latched_mins,WREG ; get minutes
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
95 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
96 movwf RTCVALH ; write minutes
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
97
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
98 movlw 0x55 ; | probably not needed when clearing RTCWREN
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
99 movwf EECON2 ; |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
100 movlw 0xAA ; |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
101 movwf EECON2 ; |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
102 bcf RTCCFG,RTCWREN ; lock sequence for RTCWREN
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
103
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
104 banksel common ; back to bank common
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
105
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
106 ; 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
107 movff rtc_latched_year, rtc_year
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
108 movff rtc_latched_month,rtc_month
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
109 movff rtc_latched_day, rtc_day
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
110 movff rtc_latched_hour, rtc_hour
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
111 movff rtc_latched_mins, rtc_mins
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
112 movff rtc_latched_secs, rtc_secs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
113
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
114 bcf block_rtc_access ; allow the ISR to access the RTC again
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
115 return ; done
0
heinrichsweikamp
parents:
diff changeset
116
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
117
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
118 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
119 ; Helper Function - convert from decimal to BCD
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
120 ;
0
heinrichsweikamp
parents:
diff changeset
121 rtc_dec2bcd:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
122 banksel common ; switch to bank common
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
123 movwf lo ; input in decimal
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
124 setf hi ; 10s
0
heinrichsweikamp
parents:
diff changeset
125 rtc_dec2bcd2:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
126 incf hi,F ; count 10's
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
127 movlw d'10' ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
128 subwf lo,F ; ...
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
129 btfss STATUS,N ; result negative?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
130 bra rtc_dec2bcd2 ; NO - loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
131 movlw d'10' ; YES -
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
132 addwf lo,F ; - 1s
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
133 swapf hi,W ; - swap to bit 7-4 -> WREG
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
134 addwf lo,W ; - result in BCD
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
135 banksel 0xF16 ; - switch back to bank for I/O registers
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
136 return ; - done
0
heinrichsweikamp
parents:
diff changeset
137
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
138
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
139 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
140 ; Helper Function - check Validity of Day according to Month
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
141 ;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
142 ; wrap-around the month depending on the number of days per month
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
143 ;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
144 ; Attention: needs to be called in bank isr_backup!
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
145 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
146 rtc_check_day:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
147 movlw .28 ; the default February has 28 days
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
148 btfsc rtc_latched_year,0 ; is the year an even year?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
149 bra rtc_check_day_1 ; NO - keep the 28 days
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
150 btfss rtc_latched_year,1 ; YES - is it a multiple of 4 years?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
151 movlw .29 ; YES - leap year, February has 29 days
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
152 rtc_check_day_1:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
153 movwf backup_hi ; store highest day in February in backup_hi
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
154 decf rtc_latched_month,W ; compute month - 1 and...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
155 movwf backup_lo ; store result in backup_lo
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
156 movlw .31 ; default highest day is 31
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
157 dcfsnz backup_lo,F ; month = February?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
158 movf backup_hi,W ; YES - highest day is 28/29
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
159 dcfsnz backup_lo,F ; month = March?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
160 movlw .31 ; YES - highest day is 31
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
161 dcfsnz backup_lo,F ; month = April?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
162 movlw .30 ; YES - highest day is 30
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
163 dcfsnz backup_lo,F ; month = May?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
164 movlw .31 ; YES - highest day is 31
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
165 dcfsnz backup_lo,F ; month = June?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
166 movlw .30 ; YES - highest day is 30
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
167 dcfsnz backup_lo,F ; month = July?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
168 movlw .31 ; YES - highest day is 31
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
169 dcfsnz backup_lo,F ; month = August?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
170 movlw .31 ; YES - highest day = 31
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
171 dcfsnz backup_lo,F ; month = September?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
172 movlw .30 ; YES - highest day = 30
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
173 dcfsnz backup_lo,F ; month = October?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
174 movlw .31 ; YES - highest day = 31
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
175 dcfsnz backup_lo,F ; month = November?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
176 movlw .30 ; YES - highest day = 30
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
177 dcfsnz backup_lo,F ; month = December?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
178 movlw .31 ; YES - highest day = 31
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
179 cpfsgt rtc_latched_day ; current day > highest day?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
180 retlw .1 ; NO - done, signal day was ok
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
181 movlw .1 ; YES - wrap around to 1st day in month
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
182 movwf rtc_latched_day ; - ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
183 retlw .0 ; - done, signal a correction was made
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
184
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
185
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
186 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
187 rtc2 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
188 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
189
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
190 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
191 ; Add minutes in mpr:2 to the time/date in in rtc_latched and rounds up/down
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
192 ; to next full minute
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
193 ;
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
194 ; Attention:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
195 ; This code works for a maximum of 1439 minutes to add (23 hours, 59 minutes)!
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
196 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
197 global rtc_add_minutes
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
198 rtc_add_minutes:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
199 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
200 banksel isr_backup ; switch to bank isr_backup
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
201 bcf STATUS,C ; clear carry bit
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
202 movlw .30 ; rounding point for seconds
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
203 cpfslt rtc_latched_secs ; seconds < rounding point?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
204 bsf STATUS,C ; NO - set carry bit -> round up to next full minute
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
205 clrf rtc_latched_secs ; set the second to zero
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
206 movff lo,WREG ; get minutes to add
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
207 addwfc rtc_latched_mins,F ; add minutes to add
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
208 movlw .59 ; limit for minute
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
209 cpfsgt rtc_latched_mins ; resulting minute > 59 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
210 bra rtc_add_minutes_1 ; NO - minute is ok
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
211 movlw .60 ; YES - subtract 60 from resulting minute
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
212 subwf rtc_latched_mins,F ; - ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
213 bsf STATUS,C ; - set carry bit
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
214 rtc_add_minutes_1:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
215 movff hi,WREG ; get hours to add
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
216 addwfc rtc_latched_hour,F ; add hours to add plus carry bit
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
217 movlw .23 ; limit for hour
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
218 cpfsgt rtc_latched_hour ; resulting hour > 23 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
219 bra rtc_add_minutes_2 ; NO - hour is ok
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
220 movlw .24 ; YES - subtract 24 from resulting hour
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
221 subwf rtc_latched_hour ; - ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
222 bsf STATUS,C ; - set carry bit
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
223 rtc_add_minutes_2:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
224 clrf WREG ; create a zero
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
225 addwfc rtc_latched_day,F ; add the carry bit
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
226 call rtc_check_day ; check & correct the resulting day with respect to #days in month
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
227 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
228 bra rtc_add_minutes_3 ; NO - done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
229 banksel isr_backup ; YES - select bank isr_backup again
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
230 incf rtc_latched_month,F ; - increment month
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
231 movlw .12 ; - limit for month
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
232 cpfsgt rtc_latched_month ; - resulting month > 12 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
233 bra rtc_add_minutes_3 ; NO - month is ok
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
234 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
235 incf rtc_latched_year,F ; - increment year
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
236 rtc_add_minutes_3
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
237 banksel common ; back to bank common
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
238 return ; done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
239
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
240 ;-----------------------------------------------------------------------------
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
241
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
242 END