annotate code_part1/OSTC_code_asm_part1/adc_rtc.asm @ 816:df8cd5ffd993

BUGFIX: Load first diluent if <> 1 correctly Auto-SP change work...
author heinrichsweikamp
date Sat, 16 May 2015 14:48:26 +0200
parents 2a0e5d884fc3
children 2750099bf5bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
815
2a0e5d884fc3 BUGFIX: Fix licence in German
heinrichsweikamp
parents: 807
diff changeset
1 ; OSTC Mk.2, 2N and 2C - diving computer code
807
c50296c3059e BUGFIX: Divetime had unwanted "." behind the minutes
heinrichsweikamp
parents: 729
diff changeset
2 ; Copyright (C) 2015 HeinrichsWeikamp GbR
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
3
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
4 ; This program is free software: you can redistribute it and/or modify
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
5 ; it under the terms of the GNU General Public License as published by
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
6 ; the Free Software Foundation, either version 3 of the License, or
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
7 ; (at your option) any later version.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
8
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
9 ; This program is distributed in the hope that it will be useful,
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
10 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
12 ; GNU General Public License for more details.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
13
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
14 ; You should have received a copy of the GNU General Public License
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
15 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
16
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
17
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
18 ; routines for AD converter, Realtime clock initialisation
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
19 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
20 ; written: 10/30/05
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
21 ; last updated: 05/15/08
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
22 ; known bugs:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
23 ; ToDo:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
24
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
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
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
31 bsf ADCON0,0 ; power on ADC
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
32 nop
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
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
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
35 get_battery_voltage2:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
36 btfsc ADCON0,1 ; Wait...
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
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
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
39
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
40 ; 3.3V/1024=3,2227mV Input/Bit=9,6680mV Battery/Bit.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
41 ; Example: 434*9,6680mV=4195,9mV Battery.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
42
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
43 movff ADRESH,xA+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
44 movff ADRESL,xA+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
45 movlw LOW d'966'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
46 movwf xB+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
47 movlw HIGH d'966'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
48 movwf xB+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
49 call mult16x16 ; AD_Result*966
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
50 movlw d'100'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
51 movwf xB+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
52 clrf xB+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
53 call div32x16 ;xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
54 movff xC+0,batt_voltage+0 ; store value
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
55 movff xC+1,batt_voltage+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
56 bcf ADCON0,0 ; power off ADC
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
57
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
58 ; Check if we should enter deep-sleep mode
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
59
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
60 movff batt_voltage+0,sub_b+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
61 movff batt_voltage+1,sub_b+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
62 movlw LOW d'2600' ; must be greater then 2600mV...
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
63 movwf sub_a+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
64 movlw HIGH d'2600'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
65 movwf sub_a+1
702
e6ff73e88e45 bugfix battery history
heinrichsweikamp
parents: 692
diff changeset
66 call subU16 ; sub_c = sub_a - sub_b
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
67 bcf enter_error_sleep ; Clear flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
68 btfsc neg_flag ; neg_flag=1 if eeprom40:41 < 2000
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
69 bra get_battery_voltage3 ; Battery in OK range
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
70
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
71 movlw d'2'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
72 movwf fatal_error_code ; Battery very low!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
73 bsf enter_error_sleep ; enter error routine
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
74
341
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 297
diff changeset
75 get_battery_voltage3:
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 297
diff changeset
76 SAFE_2BYTE_COPY amb_pressure, sub_b
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 297
diff changeset
77
398
ab962c4b19d6 Fixing issue 50, correct "Bar" to "bar" in texts and comments
heinrichsweikamp
parents: 341
diff changeset
78 movlw LOW d'15001' ; must be lower then 15001mbar
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
79 movwf sub_a+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
80 movlw HIGH d'15001'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
81 movwf sub_a+1
702
e6ff73e88e45 bugfix battery history
heinrichsweikamp
parents: 692
diff changeset
82 call subU16 ; sub_c = sub_a - sub_b
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
83 bcf enter_error_sleep ; Clear flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
84 btfss neg_flag ;
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
85 bra get_battery_voltage4 ; Pressure in OK range
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
86
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
87 movlw d'3'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
88 movwf fatal_error_code ; too deep
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
89 bsf enter_error_sleep ; enter error routine
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
90 ; Continue with rest of routine
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
91
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
92 get_battery_voltage4:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
93 ; check if the battery control memory needs to be initialised!
665
259e4c1bf3c2 grey-out TTS and ceiling after gas change (until new plan is ready)
heinrichsweikamp
parents: 622
diff changeset
94 bcf initialize_battery1 ; clear check-flag
703
39e02673db4c some cleanup
heinrichsweikamp
parents: 702
diff changeset
95 clrf EEADRH
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
96 read_int_eeprom d'40' ; get lowest battery voltage seen in mV
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
97 movff EEDATA,sub_b+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
98 read_int_eeprom d'41'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
99 movff EEDATA,sub_b+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
100
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
101 movlw LOW d'2000' ; must be greater then 2000mV...
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
102 movwf sub_a+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
103 movlw HIGH d'2000'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
104 movwf sub_a+1
729
71e88ee8bbf2 battery info updater
heinrichsweikamp
parents: 723
diff changeset
105 call subU16 ; sub_c = sub_a - sub_b
71e88ee8bbf2 battery info updater
heinrichsweikamp
parents: 723
diff changeset
106 btfss neg_flag ; neg_flag=1 if eeprom40:41 < 2000
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
107 bsf initialize_battery1 ; battery need to be initialised
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
108
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
109 movlw LOW d'4500' ; must be lower then 4500mV...
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
110 movwf sub_a+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
111 movlw HIGH d'4500'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
112 movwf sub_a+1
729
71e88ee8bbf2 battery info updater
heinrichsweikamp
parents: 723
diff changeset
113 call subU16 ; sub_c = sub_a - sub_b
71e88ee8bbf2 battery info updater
heinrichsweikamp
parents: 723
diff changeset
114 btfsc neg_flag ; neg_flag=1 if eeprom40:41 < 4500
665
259e4c1bf3c2 grey-out TTS and ceiling after gas change (until new plan is ready)
heinrichsweikamp
parents: 622
diff changeset
115 bsf initialize_battery1 ; battery need to be initialised
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
116
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
117 btfss initialize_battery1 ; battery need to be initialised?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
118 bra get_battery_no_init ; No, we have already valid values, just check for new extremas
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
119
702
e6ff73e88e45 bugfix battery history
heinrichsweikamp
parents: 692
diff changeset
120 get_battery_voltage_reset:
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
121 ; Init EEPROM for battery control
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
122 ; Reset lowest battery seen
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
123 movlw LOW d'4200' ; reset to 4.2V
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
124 movwf EEDATA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
125 write_int_eeprom d'40'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
126 movlw HIGH d'4200' ; reset to 4.2V
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
127 movwf EEDATA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
128 write_int_eeprom d'41'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
129 movff month,EEDATA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
130 write_int_eeprom d'42'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
131 movff day,EEDATA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
132 write_int_eeprom d'43'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
133 movff year,EEDATA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
134 write_int_eeprom d'44'
341
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 297
diff changeset
135 SAFE_2BYTE_COPY temperature,lo
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 297
diff changeset
136 movff lo,EEDATA
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
137 write_int_eeprom d'45'
341
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 297
diff changeset
138 movff hi,EEDATA
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
139 write_int_eeprom d'46'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
140 ; Reset charge statistics
53
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 21
diff changeset
141 clrf EEDATA
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 21
diff changeset
142 write_int_eeprom d'47' ; last complete charge
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 21
diff changeset
143 write_int_eeprom d'48' ; last complete charge
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 21
diff changeset
144 write_int_eeprom d'49' ; last complete charge
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 21
diff changeset
145 write_int_eeprom d'50' ; total cycles
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 21
diff changeset
146 write_int_eeprom d'51' ; total cycles
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 21
diff changeset
147 write_int_eeprom d'52' ; total complete cycles
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 21
diff changeset
148 write_int_eeprom d'53' ; total complete cycles
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
149 ; Reset temperature extremas
341
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 297
diff changeset
150 SAFE_2BYTE_COPY temperature,lo
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 297
diff changeset
151 movff lo,EEDATA ; Reset mimimum extrema
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
152 write_int_eeprom d'54'
341
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 297
diff changeset
153 movff hi,EEDATA
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
154 write_int_eeprom d'55'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
155 movff month,EEDATA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
156 write_int_eeprom d'56'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
157 movff day,EEDATA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
158 write_int_eeprom d'57'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
159 movff year,EEDATA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
160 write_int_eeprom d'58'
341
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 297
diff changeset
161 movff lo,EEDATA ; Reset maximum extrema
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
162 write_int_eeprom d'59'
341
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 297
diff changeset
163 movff hi,EEDATA
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
164 write_int_eeprom d'60'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
165 movff month,EEDATA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
166 write_int_eeprom d'61'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
167 movff day,EEDATA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
168 write_int_eeprom d'62'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
169 movff year,EEDATA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
170 write_int_eeprom d'63'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
171 get_battery_no_init:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
172 read_int_eeprom d'40' ; get lowest battery voltage seen in mV
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
173 movff EEDATA,sub_b+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
174 read_int_eeprom d'41'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
175 movff EEDATA,sub_b+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
176 movff batt_voltage+0,sub_a+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
177 movff batt_voltage+1,sub_a+1
702
e6ff73e88e45 bugfix battery history
heinrichsweikamp
parents: 692
diff changeset
178 call subU16 ; sub_c = sub_a - sub_b
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
179 btfss neg_flag ; new lowest battery voltage?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
180 return ; no, quit routine
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
181 ; Yes, store new value together with the date and temperature values
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
182 movff batt_voltage+0,EEDATA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
183 write_int_eeprom d'40'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
184 movff batt_voltage+1,EEDATA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
185 write_int_eeprom d'41'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
186 movff month,EEDATA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
187 write_int_eeprom d'42'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
188 movff day,EEDATA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
189 write_int_eeprom d'43'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
190 movff year,EEDATA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
191 write_int_eeprom d'44'
341
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 297
diff changeset
192 SAFE_2BYTE_COPY temperature,lo
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 297
diff changeset
193 movff lo,EEDATA
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
194 write_int_eeprom d'45'
341
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 297
diff changeset
195 movff hi,EEDATA
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
196 write_int_eeprom d'46'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
197 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
198
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
199 RTCinit: ; resets RTC
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
200 movlw 0x80
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
201 movwf TMR1H
537
3091628b2742 BUGFIX: Spurious logbook read issue
heinrichsweikamp
parents: 398
diff changeset
202 nop ; See errata DS80284E-page 2
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
203 clrf TMR1L
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
204 ; Reset RTC if any part of the time/date is out of range
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
205 movlw d'60' ; Limit
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
206 cpfslt secs ; Check part
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
207 bra RTCinit2 ; Reset time...
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
208 movlw d'60' ; Limit
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
209 cpfslt mins ; Check part
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
210 bra RTCinit2 ; Reset time...
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
211 movlw d'24' ; Limit
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
212 cpfslt hours ; Check part
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
213 bra RTCinit2 ; Reset time...
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
214 movlw d'32' ; Limit
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
215 cpfslt day ; Check part
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
216 bra RTCinit2 ; Reset time...
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
217 movlw d'12' ; Limit
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
218 cpfslt month ; Check part
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
219 bra RTCinit2 ; Reset time...
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
220 movlw d'100' ; Limit
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
221 cpfslt year ; Check part
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
222 bra RTCinit2 ; Reset time...
614
7a269c01192a Make sure day and month <> zero
heinrichsweikamp
parents: 605
diff changeset
223 ; Make sure day and month <> zero
7a269c01192a Make sure day and month <> zero
heinrichsweikamp
parents: 605
diff changeset
224 movlw .0
723
6fd9a9feca91 fix minor issue in rtc_init
heinrichsweikamp
parents: 720
diff changeset
225 cpfsgt day ; =0?
614
7a269c01192a Make sure day and month <> zero
heinrichsweikamp
parents: 605
diff changeset
226 incf day,F ; Yes, +1
723
6fd9a9feca91 fix minor issue in rtc_init
heinrichsweikamp
parents: 720
diff changeset
227 cpfsgt month ; =0?
614
7a269c01192a Make sure day and month <> zero
heinrichsweikamp
parents: 605
diff changeset
228 incf month,F ; Yes, +1
7a269c01192a Make sure day and month <> zero
heinrichsweikamp
parents: 605
diff changeset
229 bsf PIE1, TMR1IE ; Enable clock int
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
230 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
231
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
232 RTCinit2:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
233 movlw .00
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
234 movwf secs
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
235 movlw .00
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
236 movwf mins
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
237 movlw .12
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
238 movwf hours
720
4452837aff37 Vault date and time during update
heinrichsweikamp
parents: 703
diff changeset
239 movlw .1
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
240 movwf day
720
4452837aff37 Vault date and time during update
heinrichsweikamp
parents: 703
diff changeset
241 movlw .5
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
242 movwf month
692
82f71a73f450 indicate first gas in surfacemode
heinrichsweikamp
parents: 665
diff changeset
243 movlw .13
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
244 movwf year
614
7a269c01192a Make sure day and month <> zero
heinrichsweikamp
parents: 605
diff changeset
245 bsf PIE1, TMR1IE ; Enable clock int
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
246 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
247
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 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
249 bcf uart_reset_battery_stats ; Clear flag
703
39e02673db4c some cleanup
heinrichsweikamp
parents: 702
diff changeset
250 clrf EEADRH
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
251 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
252 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
253 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
254
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 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
256 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
257 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
258 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
259 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
260 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
261 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
262
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 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
264 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
265 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
266 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
267 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
268 ; 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
269 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
270 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
271 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
272 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
273
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
274 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
275 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
276 goto surfloop_loop ; return to surface loop