Mercurial > public > mk2
annotate code_part1/OSTC_code_asm_part1/adc_rtc.asm @ 318:50e5b54b3fbd
Renamed Escape TTS to Future TTS
author | heinrichsweikamp |
---|---|
date | Wed, 04 May 2011 12:56:37 +0200 |
parents | ceedf078b2d8 |
children | 2144f19fa1eb |
rev | line source |
---|---|
0 | 1 ; OSTC - diving computer code |
2 ; Copyright (C) 2008 HeinrichsWeikamp GbR | |
3 | |
4 ; This program is free software: you can redistribute it and/or modify | |
5 ; it under the terms of the GNU General Public License as published by | |
6 ; the Free Software Foundation, either version 3 of the License, or | |
7 ; (at your option) any later version. | |
8 | |
9 ; This program is distributed in the hope that it will be useful, | |
10 ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 ; GNU General Public License for more details. | |
13 | |
14 ; You should have received a copy of the GNU General Public License | |
15 ; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | |
17 | |
18 ; routines for AD converter, Realtime clock initialisation | |
19 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com | |
20 ; written: 10/30/05 | |
21 ; last updated: 05/15/08 | |
22 ; known bugs: | |
23 ; ToDo: | |
24 | |
25 get_battery_voltage: ; starts ADC and waits until fnished | |
81
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
26 ; In MPLAB Sim mode (hardware emulation), use a DMCI slider to |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
27 ; directly set a 16 bit value in the range 0..1023 |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
28 ; In normal mode, jut wait for the value to be ready: |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
29 |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
30 ifndef TESTING |
0 | 31 bsf ADCON0,0 ; power on ADC |
32 nop | |
33 bsf ADCON0,1 ; start ADC | |
81
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
34 |
0 | 35 get_battery_voltage2: |
36 btfsc ADCON0,1 ; Wait... | |
37 bra get_battery_voltage2 | |
81
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
38 endif |
0 | 39 |
40 ; 3.3V/1024=3,2227mV Input/Bit=9,6680mV Battery/Bit. | |
41 ; Example: 434*9,6680mV=4195,9mV Battery. | |
42 | |
43 movff ADRESH,xA+1 | |
44 movff ADRESL,xA+0 | |
45 movlw LOW d'966' | |
46 movwf xB+0 | |
47 movlw HIGH d'966' | |
48 movwf xB+1 | |
49 call mult16x16 ; AD_Result*966 | |
50 movlw d'100' | |
51 movwf xB+0 | |
52 clrf xB+1 | |
53 call div32x16 ;xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
54 movff xC+0,batt_voltage+0 ; store value | |
55 movff xC+1,batt_voltage+1 | |
56 bcf ADCON0,0 ; power off ADC | |
57 | |
58 ; Check if we should enter deep-sleep mode | |
59 | |
60 movff batt_voltage+0,sub_b+0 | |
61 movff batt_voltage+1,sub_b+1 | |
62 movlw LOW d'2600' ; must be greater then 2600mV... | |
63 movwf sub_a+0 | |
64 movlw HIGH d'2600' | |
65 movwf sub_a+1 | |
66 call sub16 ; sub_c = sub_a - sub_b | |
67 bcf enter_error_sleep ; Clear flag | |
68 btfsc neg_flag ; neg_flag=1 if eeprom40:41 < 2000 | |
69 bra get_battery_voltage3 ; Battery in OK range | |
70 | |
71 movlw d'2' | |
72 movwf fatal_error_code ; Battery very low! | |
73 bsf enter_error_sleep ; enter error routine | |
74 | |
75 get_battery_voltage3: | |
76 movff amb_pressure+0,sub_b+0 | |
77 movff amb_pressure+1,sub_b+1 | |
78 movlw LOW d'15001' ; must be lower then 15001mBar | |
79 movwf sub_a+0 | |
80 movlw HIGH d'15001' | |
81 movwf sub_a+1 | |
82 call sub16 ; sub_c = sub_a - sub_b | |
83 bcf enter_error_sleep ; Clear flag | |
84 btfss neg_flag ; | |
85 bra get_battery_voltage4 ; Pressure in OK range | |
86 | |
87 movlw d'3' | |
88 movwf fatal_error_code ; too deep | |
89 bsf enter_error_sleep ; enter error routine | |
90 ; Continue with rest of routine | |
91 | |
92 get_battery_voltage4: | |
93 ; check if the battery control memory needs to be initialised! | |
94 bcf initialize_battery1 ; clear check-flags | |
95 bcf initialize_battery2 | |
96 | |
97 read_int_eeprom d'40' ; get lowest battery voltage seen in mV | |
98 movff EEDATA,sub_b+0 | |
99 read_int_eeprom d'41' | |
100 movff EEDATA,sub_b+1 | |
101 | |
102 movlw LOW d'2000' ; must be greater then 2000mV... | |
103 movwf sub_a+0 | |
104 movlw HIGH d'2000' | |
105 movwf sub_a+1 | |
106 call sub16 ; sub_c = sub_a - sub_b | |
107 btfss neg_flag ; neg_flag=1 if eeprom40:41 < 2000 | |
108 bsf initialize_battery1 ; battery need to be initialised | |
109 | |
110 movlw LOW d'4500' ; must be lower then 4500mV... | |
111 movwf sub_a+0 | |
112 movlw HIGH d'4500' | |
113 movwf sub_a+1 | |
114 call sub16 ; sub_c = sub_a - sub_b | |
115 btfss neg_flag ; neg_flag=1 if eeprom40:41 < 4500 | |
116 bsf initialize_battery2 ; battery need to be initialised | |
117 | |
118 btfss initialize_battery1 ; battery need to be initialised? | |
119 bra get_battery_no_init ; No, we have already valid values, just check for new extremas | |
120 | |
121 btfss initialize_battery2 ; battery need to be initialised? | |
122 bra get_battery_no_init ; No, we have already valid values, just check for new extremas | |
297
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
123 |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
124 get_battery_voltage_reset: |
0 | 125 ; Init EEPROM for battery control |
126 ; Reset lowest battery seen | |
127 movlw LOW d'4200' ; reset to 4.2V | |
128 movwf EEDATA | |
129 write_int_eeprom d'40' | |
130 movlw HIGH d'4200' ; reset to 4.2V | |
131 movwf EEDATA | |
132 write_int_eeprom d'41' | |
133 movff month,EEDATA | |
134 write_int_eeprom d'42' | |
135 movff day,EEDATA | |
136 write_int_eeprom d'43' | |
137 movff year,EEDATA | |
138 write_int_eeprom d'44' | |
139 movff temperature+0,EEDATA | |
140 write_int_eeprom d'45' | |
141 movff temperature+1,EEDATA | |
142 write_int_eeprom d'46' | |
143 ; Reset charge statistics | |
53 | 144 clrf EEDATA |
145 write_int_eeprom d'47' ; last complete charge | |
146 write_int_eeprom d'48' ; last complete charge | |
147 write_int_eeprom d'49' ; last complete charge | |
148 write_int_eeprom d'50' ; total cycles | |
149 write_int_eeprom d'51' ; total cycles | |
150 write_int_eeprom d'52' ; total complete cycles | |
151 write_int_eeprom d'53' ; total complete cycles | |
0 | 152 ; Reset temperature extremas |
153 movff temperature+0,EEDATA ; Reset mimimum extrema | |
154 write_int_eeprom d'54' | |
155 movff temperature+1,EEDATA | |
156 write_int_eeprom d'55' | |
157 movff month,EEDATA | |
158 write_int_eeprom d'56' | |
159 movff day,EEDATA | |
160 write_int_eeprom d'57' | |
161 movff year,EEDATA | |
162 write_int_eeprom d'58' | |
163 movff temperature+0,EEDATA ; Reset maximum extrema | |
164 write_int_eeprom d'59' | |
165 movff temperature+1,EEDATA | |
166 write_int_eeprom d'60' | |
167 movff month,EEDATA | |
168 write_int_eeprom d'61' | |
169 movff day,EEDATA | |
170 write_int_eeprom d'62' | |
171 movff year,EEDATA | |
172 write_int_eeprom d'63' | |
173 | |
174 get_battery_no_init: | |
175 read_int_eeprom d'40' ; get lowest battery voltage seen in mV | |
176 movff EEDATA,sub_b+0 | |
177 read_int_eeprom d'41' | |
178 movff EEDATA,sub_b+1 | |
179 movff batt_voltage+0,sub_a+0 | |
180 movff batt_voltage+1,sub_a+1 | |
181 call sub16 ; sub_c = sub_a - sub_b | |
182 btfss neg_flag ; new lowest battery voltage? | |
183 return ; no, quit routine | |
184 ; Yes, store new value together with the date and temperature values | |
185 movff batt_voltage+0,EEDATA | |
186 write_int_eeprom d'40' | |
187 movff batt_voltage+1,EEDATA | |
188 write_int_eeprom d'41' | |
189 movff month,EEDATA | |
190 write_int_eeprom d'42' | |
191 movff day,EEDATA | |
192 write_int_eeprom d'43' | |
193 movff year,EEDATA | |
194 write_int_eeprom d'44' | |
195 movff temperature+0,EEDATA | |
196 write_int_eeprom d'45' | |
197 movff temperature+1,EEDATA | |
198 write_int_eeprom d'46' | |
199 return | |
200 | |
201 RTCinit: ; resets RTC | |
202 movlw 0x80 | |
203 movwf TMR1H | |
204 clrf TMR1L | |
205 | |
206 ; Reset RTC if any part of the time/date is out of range | |
207 movlw d'60' ; Limit | |
208 cpfslt secs ; Check part | |
209 bra RTCinit2 ; Reset time... | |
210 movlw d'60' ; Limit | |
211 cpfslt mins ; Check part | |
212 bra RTCinit2 ; Reset time... | |
213 movlw d'24' ; Limit | |
214 cpfslt hours ; Check part | |
215 bra RTCinit2 ; Reset time... | |
216 movlw d'32' ; Limit | |
217 cpfslt day ; Check part | |
218 bra RTCinit2 ; Reset time... | |
219 movlw d'12' ; Limit | |
220 cpfslt month ; Check part | |
221 bra RTCinit2 ; Reset time... | |
222 movlw d'100' ; Limit | |
223 cpfslt year ; Check part | |
224 bra RTCinit2 ; Reset time... | |
225 | |
226 bsf PIE1, TMR1IE | |
227 return | |
228 | |
229 RTCinit2: | |
230 movlw .00 | |
231 movwf secs | |
232 movlw .00 | |
233 movwf mins | |
234 movlw .12 | |
235 movwf hours | |
297
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
236 movlw .5 |
0 | 237 movwf day |
297
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
238 movlw .5 |
0 | 239 movwf month |
153 | 240 movlw .11 |
0 | 241 movwf year |
242 bsf PIE1, TMR1IE | |
297
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
243 return |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
244 |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
245 reset_battery_stats: |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
246 bcf uart_reset_battery_stats ; Clear flag |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
247 bcf PIE1,RCIE ; no interrupt for UART |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
248 call rs232_get_byte ; Get Byte |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
249 bcf PIR1,RCIF ; clear flag |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
250 |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
251 btfsc rs232_recieve_overflow ; Byte received? |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
252 bra reset_battery_stats_exit ; No, exit |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
253 movlw 'f' |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
254 cpfseq RCREG ; Really reset statistics? |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
255 bra reset_battery_stats_exit ; No, exit |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
256 call rs232_get_byte ; Get byte |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
257 bcf PIR1,RCIF ; clear flag |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
258 |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
259 btfsc rs232_recieve_overflow ; Byte received? |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
260 bra reset_battery_stats_exit ; No, exit |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
261 movlw 'f' |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
262 cpfseq RCREG ; Really reset statistics? |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
263 bra reset_battery_stats_exit ; No, exit |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
264 ; Yes, Reset now. |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
265 rcall get_battery_voltage_reset ; Reset Statistics |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
266 movlw 'f' |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
267 movwf TXREG |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
268 call rs232_wait_tx ; Wait for uart |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
269 |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
270 reset_battery_stats_exit: |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
271 bsf PIE1,RCIE ; re-enable interrupt for UART |
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
255
diff
changeset
|
272 goto surfloop_loop ; return to surface loop |