annotate src/rtc.asm @ 623:c40025d8e750

3.03 beta released
author heinrichsweikamp
date Mon, 03 Jun 2019 14:01:48 +0200
parents d866684249bd
children 185ba2f91f59
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
3 ; File rtc.asm combined next generation V3.02.1
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
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
19 global rtc_set_rtc
0
heinrichsweikamp
parents:
diff changeset
20 rtc_init:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
21 banksel isr_backup ; select bank ISR data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
22 movlw .0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
23 movwf rtc_latched_secs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
24 movlw .0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
25 movwf rtc_latched_mins
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 598
diff changeset
26 movlw .12
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
27 movwf rtc_latched_hour
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
28 movlw firmware_creation_day
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
29 movwf rtc_latched_day
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
30 movlw firmware_creation_month
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
31 movwf rtc_latched_month
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
32 movlw firmware_creation_year
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
33 movwf rtc_latched_year
0
heinrichsweikamp
parents:
diff changeset
34 rtc_set_rtc:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
35 banksel isr_backup
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
36 movlw d'24' ; safeguard hour
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
37 cpfslt rtc_latched_hour
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
38 clrf rtc_latched_hour
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
39 movlw d'60' ; safeguard minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
40 cpfslt rtc_latched_mins
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
41 clrf rtc_latched_mins
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
42 movlw d'60' ; safeguard seconds
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
43 cpfslt rtc_latched_secs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
44 clrf rtc_latched_secs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
45 movlw d'99' ; safeguard year
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
46 cpfslt rtc_latched_year
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
47 movwf rtc_latched_year
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
48 movlw d'12' ; safeguard month
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
49 cpfslt rtc_latched_month
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
50 movwf rtc_latched_month
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
51
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
52 banksel common ; select bank common
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
53 rcall rtc_check_day ; safeguard day
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
54 bsf block_rtc_access ; suspend the ISR from accessing the RTC
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
55
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
56
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
57 banksel 0xF16 ; addresses F16h through F5Fh are also used by SFRs, but are not part of the access RAM
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
58
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
59 movlw 0x55 ; | unlock sequence for RTCWREN, EECON2 is located in the access RAM
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
60 movwf EECON2 ; |
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
61 movlw 0xAA ; |
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
62 movwf EECON2 ; |
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
63 bsf RTCCFG,RTCWREN ; RTC write unlock, must follow directly after above unlock sequence!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
64 bsf RTCCFG,RTCPTR1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
65 bsf RTCCFG,RTCPTR0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
66 movff rtc_latched_year,WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
67 rcall rtc_dec2bcd ; IN: WREG in decimal, OUT: WREG in BCD, also sets to bank16h!
0
heinrichsweikamp
parents:
diff changeset
68 movwf RTCVALL ; year
heinrichsweikamp
parents:
diff changeset
69 movwf RTCVALH ; dummy write
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
70 movff rtc_latched_day,WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
71 rcall rtc_dec2bcd ; IN: WREG in decimal, OUT: WREG in BCD, also sets to bank16h!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
72 movwf RTCVALL ; day
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
73 movff rtc_latched_month,WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
74 rcall rtc_dec2bcd ; IN: WREG in decimal, OUT: WREG in BCD, also sets to bank16h!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
75 movwf RTCVALH ; month
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
76 movff rtc_latched_hour,WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
77 rcall rtc_dec2bcd ; IN: WREG in decimal, OUT: WREG in BCD, also sets to bank16h!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
78 movwf RTCVALL ; hour
0
heinrichsweikamp
parents:
diff changeset
79 movlw d'0'
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
80 rcall rtc_dec2bcd ; IN: WREG in decimal, OUT: WREG in BCD, also sets to bank16h!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
81 movwf RTCVALH ; weekday
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
82 movff rtc_latched_secs,WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
83 rcall rtc_dec2bcd ; IN: WREG in decimal, OUT: WREG in BCD, also sets to bank16h!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
84 movwf RTCVALL ; seconds
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
85 movff rtc_latched_mins,WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
86 rcall rtc_dec2bcd ; IN: WREG in decimal, OUT: WREG in BCD, also sets to bank16h!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
87 movwf RTCVALH ; minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
88
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
89 movlw 0x55 ; | probably not needed when clearing RTCWREN
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
90 movwf EECON2 ; |
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
91 movlw 0xAA ; |
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
92 movwf EECON2 ; |
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
93 bcf RTCCFG,RTCWREN ; lock sequence for RTCWREN
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
94
0
heinrichsweikamp
parents:
diff changeset
95 banksel common
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
96
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
97 ; 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
98 movff rtc_latched_year, rtc_year
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
99 movff rtc_latched_month,rtc_month
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
100 movff rtc_latched_day, rtc_day
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
101 movff rtc_latched_hour, rtc_hour
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
102 movff rtc_latched_mins, rtc_mins
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
103 movff rtc_latched_secs, rtc_secs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
104
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
105 bcf block_rtc_access ; allow the ISR to access the RTC again
0
heinrichsweikamp
parents:
diff changeset
106 return
heinrichsweikamp
parents:
diff changeset
107
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
108
0
heinrichsweikamp
parents:
diff changeset
109 rtc_dec2bcd:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
110 banksel common ; switch to bank common
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
111 movwf lo ; input in decimal
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
112 setf hi ; 10s
0
heinrichsweikamp
parents:
diff changeset
113 rtc_dec2bcd2:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
114 incf hi,F ; count 10's
0
heinrichsweikamp
parents:
diff changeset
115 movlw d'10'
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
116 subwf lo,F
0
heinrichsweikamp
parents:
diff changeset
117 btfss STATUS,N
heinrichsweikamp
parents:
diff changeset
118 bra rtc_dec2bcd2
heinrichsweikamp
parents:
diff changeset
119 movlw d'10'
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
120 addwf lo,F ; 1s
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
121 swapf hi,W ; swap to bit 7-4 -> WREG
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
122 addwf lo,W ; result in BCD
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
123 banksel 0xF16 ; switch back to bank for I/O registers
0
heinrichsweikamp
parents:
diff changeset
124 return
heinrichsweikamp
parents:
diff changeset
125
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
126 rtc_check_day:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
127 movlw .28 ; the default February has 28 days
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
128 movff rtc_latched_year,lo ; bank-safe get of the current year
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
129 btfsc lo,0 ; is the current year an even year?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
130 bra rtc_check_day_1 ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
131 btfss lo,1 ; YES - is it a multiple of 4 years?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
132 movlw .29 ; YES - leap year, February has 29 days
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
133 rtc_check_day_1: ; NO - keep the 28 days
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
134 movwf hi ; store highest day in February in hi
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
135 movff rtc_latched_month,lo; bank-safe get of the current month
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
136 dcfsnz lo,F ; current month = January?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
137 movlw .31 ; YES - highest day is 31
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
138 dcfsnz lo,F ; current month = February?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
139 movf hi,W ; YES - highest day is 28/29
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
140 dcfsnz lo,F ; current month = March?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
141 movlw .31 ; YES - highest day is 31
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
142 dcfsnz lo,F ; current month = April?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
143 movlw .30 ; YES - highest day is 30
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
144 dcfsnz lo,F ; current month = May?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
145 movlw .31 ; YES - highest day is 31
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
146 dcfsnz lo,F ; current month = June?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
147 movlw .30 ; YES - highest day is 30
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
148 dcfsnz lo,F ; current month = July?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
149 movlw .31 ; YES - highest day is 31
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
150 dcfsnz lo,F ; current month = August?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
151 movlw .31 ; YES - highest day = 31
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
152 dcfsnz lo,F ; current month = September?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
153 movlw .30 ; YES - highest day = 30
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
154 dcfsnz lo,F ; current month = October?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
155 movlw .31 ; YES - highest day = 31
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
156 dcfsnz lo,F ; current month = November?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
157 movlw .30 ; YES - highest day = 30
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
158 dcfsnz lo,F ; current month = December?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
159 movlw .31 ; YES - highest day = 31
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
160 movff rtc_latched_day,hi ; bank-safe get of the current day
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
161 cpfsgt hi ; current day > highest day?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
162 return ; NO - day is ok
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
163 movlw .1 ; YES - wrap around to 1st day in month
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
164 movff WREG,rtc_latched_day; - bank-safe write-back of corrected day
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
165 return ; - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
166
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 608
diff changeset
167 END