annotate code_part1/OSTC_code_asm_part1/isr.asm @ 217:ce6f16711567

BUGFIX gas switch + Make sure not to pass gas switch + Don't clobber ratio N2/He when canceling ascent passing gas switch. + Build-up GF_low history during the whole dive.
author JeanDo
date Thu, 24 Feb 2011 23:22:32 +0100
parents ed7826c740a0
children 9581e48a914f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
2 ; OSTC - diving computer code
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
3 ; Copyright (C) 2008 HeinrichsWeikamp GbR
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
4
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
5 ; This program is free software: you can redistribute it and/or modify
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
6 ; it under the terms of the GNU General Public License as published by
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
7 ; the Free Software Foundation, either version 3 of the License, or
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
8 ; (at your option) any later version.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
9
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
10 ; This program is distributed in the hope that it will be useful,
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
13 ; GNU General Public License for more details.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
14
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
15 ; You should have received a copy of the GNU General Public License
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
16 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
17
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
18
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/16/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 ; the timer1 module interrupts every 62.5ms (16x/second)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
26 ; temperature and pressure is averaged over 4 measurements
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
27 ; flag pressure_refresh is set every 500ms
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
28 ; and provides accurate pressure (+/-1mBar stable) and temperature (0.1C stable)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
29
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
30 uartint:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
31 btfsc simulatormode_active ; are we in simulatormode?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
32 bra simulator_int ; Yes, reading is depth in m!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
33
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
34 movff RCREG,uart1_temp
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
35 movlw d'96'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
36 subwf uart1_temp,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
37 dcfsnz uart1_temp,F ; "a"
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
38 bsf dump_external_eeprom ; set flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
39 dcfsnz uart1_temp,F ; "b"
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
40 bsf uart_settime ; set flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
41 dcfsnz uart1_temp,F ; "c"
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
42 bsf simulatormode_active ; set flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
43 dcfsnz uart1_temp,F ; "d"
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
44 bsf internal_eeprom_write ; set flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
45 dcfsnz uart1_temp,F ; "e"
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
46 bsf uart_send_hash ; set flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
47 dcfsnz uart1_temp,F ; "f"
49
cd5b650920f6 1.70...
heinrichsweikamp
parents: 43
diff changeset
48 nop ; no longer used command "f"
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
49 dcfsnz uart1_temp,F ; "g"
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
50 bsf uart_send_int_eeprom ; set flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
51 dcfsnz uart1_temp,F ; "h"
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
52 bsf uart_reset_decodata ; set flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
53 dcfsnz uart1_temp,F ; "i"
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
54 bsf internal_eeprom_write2 ; set flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
55 dcfsnz uart1_temp,F ; "j"
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
56 bsf uart_send_int_eeprom2 ; set flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
57 dcfsnz uart1_temp,F ; "k"
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
58 bsf uart_store_tissue_data ; set flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
59
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
60
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
61 uartint1:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
62 movf RCREG,w ; unload RCREG in stand-alone simulator mode
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
63 bcf PIR1,RCIF ; Clear flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
64 bcf RCSTA,CREN ; Clear receiver status
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
65 bsf RCSTA,CREN
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
66 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
67
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
68 simulator_int:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
69 btfsc standalone_simulator ; ignore in standalone simulator mode
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
70 bra uartint1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
71
21
73014f788032 1.60 stable rc1
heinrichsweikamp
parents: 13
diff changeset
72 bsf LED_blue
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
73 tstfsz RCREG ; =0x00?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
74 bra simulator_int1 ; No
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
75 incf RCREG,F ; Yes, so force RCREG=1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
76
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
77 simulator_int1:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
78 movf RCREG,w ; depth in m
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
79 mullw d'100' ; result will be mbar
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
80 movff PRODL,sim_pressure+0 ; stored for pressure overwrite
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
81 movff PRODH,sim_pressure+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
82 bra uartint1 ; exit uart int
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
83
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
84 schalter_links: ;
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
85 bcf INTCON,INT0IF ; Clear flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
86
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
87 btfsc T0CON,TMR0ON ; Timer0 running?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
88 bra timer0_restart ; Yes, restart
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
89
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
90 bsf switch_left ; Set flag, button press is OK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
91
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
92 bsf T0CON,TMR0ON ; Start Timer 0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
93 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
94
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
95
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
96 schalter_rechts: ;
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
97 bcf INTCON3,INT1IF ; Clear flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
98
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
99 btfsc T0CON,TMR0ON ; Timer0 running?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
100 bra timer0_restart ; Yes, restart
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
101
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
102 bsf switch_right ; Set flag, button press is OK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
103
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
104 bsf T0CON,TMR0ON ; Start Timer 0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
105 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
106
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
107 timer0_restart:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
108 bcf INTCON,TMR0IF ; Clear flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
109
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
110 clrf T0CON ; Timer0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
111 clrf TMR0H
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
112 clrf TMR0L
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
113 bsf T0CON,TMR0ON ; Start Timer 0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
114 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
115
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
116 timer0int:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
117 bcf INTCON,TMR0IF ; Clear flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
118 bcf T0CON,TMR0ON ; Stop Timer 0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
119 clrf TMR0H
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
120 clrf TMR0L
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
121 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
122
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
123
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
124 timer0int_left_reset:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
125 bcf INTCON2, INTEDG0 ; Interrupt on faling edge again
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
126 bcf switch_left_isr ; Clear flag, button press is done
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
127
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
128 movlw T0CON_debounce ; Timer0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
129 movwf T0CON
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
130
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
131 bsf T0CON,TMR0ON ; Start Timer 0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
132 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
133
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
134 timer0int_left:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
135 bsf INTCON2, INTEDG0 ; Interrupt on rising edge again
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
136 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
137
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
138 timer0int_right_reset:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
139 bcf INTCON2, INTEDG1 ; Interrupt on faling edge again
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
140 bcf switch_right_isr ; Clear flag, button press is done
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
141
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
142 movlw T0CON_debounce ; Timer0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
143 movwf T0CON
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
144
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
145 bsf T0CON,TMR0ON ; Start Timer 0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
146 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
147
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
148 timer0int_right:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
149 bsf INTCON2, INTEDG1 ; Interrupt on rising edge again
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
150 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
151
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
152 timer3int:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
153 bcf PIR2,TMR3IF ; Clear flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
154 bcf T3CON,TMR0ON ; Stop Timer 3
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
155 bcf T2CON,2 ; stop Timer 2
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
156 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
157
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
158 timer1int:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
159 bcf PIR1,TMR1IF ; Clear flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
160
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
161 timer1int_debug:
21
73014f788032 1.60 stable rc1
heinrichsweikamp
parents: 13
diff changeset
162 bcf LED_red ; LEDr off (For charge indicator)
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
163
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
164 movlw 0x08 ; Timer1 int after 62.5ms (=16/second)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
165 cpfslt TMR1H ; Did we miss a 1/16 second?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
166 incf timer1int_counter1,F ; Yes, add extra 1/16 second
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
167
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
168 movlw 0x08 ; Timer1 int after 62.5ms (=16/second)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
169 subwf TMR1H,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
170
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
171 incf timer1int_counter1,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
172 movlw d'15' ; One second 16
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
173 cpfsgt timer1int_counter1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
174 bra sensor_int_pre ; only pressure sensor
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
175 call RTCisr ; adjust time, then query pressure sensor
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
176
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
177 sensor_int_pre:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
178 btfss sleepmode ; In sleepmode?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
179 bra sensor_int ; No
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
180 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
181
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
182 sensor_int:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
183 btfsc no_sensor_int ; No sensor interrupt (because it's addressed during sleep)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
184 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
185
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
186 incf timer1int_counter2,F ; counts to eight for state maschine
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
187
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
188 movlw d'1'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
189 cpfseq timer1int_counter2 ; State 1?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
190 bra sensor_int1 ; No
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
191
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
192 bcf pressure_refresh ; clear flags
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
193 clrf isr3_temp+0 ; pressure average registers
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
194 clrf isr3_temp+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
195 clrf temperature_temp+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
196 clrf temperature_temp+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
197 sensor_int0:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
198 call get_temperature_value ; State 1: Get temperature
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
199 call get_pressure_start ; and start pressure integration.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
200 return ; Done.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
201 sensor_int1:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
202 movlw d'2'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
203 cpfseq timer1int_counter2 ; State 2?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
204 bra sensor_int2 ; No
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
205
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
206 sensor_int1_1:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
207 call get_pressure_value ; State2: Get pressure (51us)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
208 call get_temperature_start ; and start temperature integration (73,5us)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
209 call calculate_compensation ; calculate temperature compensated pressure (233us)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
210 movf amb_pressure+0,W
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
211 addwf isr3_temp+0 ; average pressure
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
212 movf amb_pressure+1,W
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
213 addwfc isr3_temp+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
214 movf temperature+0,W
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
215 addwf temperature_temp+0 ; average temperature
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
216 movf temperature+1,W
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
217 addwfc temperature_temp+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
218 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
219 sensor_int2:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
220 movlw d'3'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
221 cpfseq timer1int_counter2 ; State 3?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
222 bra sensor_int3 ; No
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
223 bra sensor_int0 ; Yes, but same as State 1!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
224 sensor_int3:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
225 movlw d'4'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
226 cpfseq timer1int_counter2 ; State 4?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
227 bra sensor_int4 ; No
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
228 bra sensor_int1_1 ; Yes, but same as State 2!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
229 sensor_int4:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
230 movlw d'5'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
231 cpfseq timer1int_counter2 ; State 5?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
232 bra sensor_int5 ; No
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
233 bra sensor_int0 ; Yes, but same as State 1!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
234 sensor_int5:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
235 movlw d'6'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
236 cpfseq timer1int_counter2 ; State 6?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
237 bra sensor_int6 ; No
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
238 bra sensor_int1_1 ; Yes, but same as State 2!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
239 sensor_int6:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
240 movlw d'7'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
241 cpfseq timer1int_counter2 ; State 7?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
242 bra sensor_int7 ; No
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
243 bra sensor_int0 ; Yes, but same as State 1!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
244 sensor_int7:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
245 rcall sensor_int1_1 ; Do State 2...
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
246 clrf timer1int_counter2 ; ..then reset State counter...
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
247 movlw d'2' ; and calculate average!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
248 movwf isr2_temp
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
249 sensor_int8:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
250 bcf STATUS,C
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
251 rrcf isr3_temp+1 ; isr3_temp / 2
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
252 rrcf isr3_temp+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
253 bcf STATUS,C
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
254 rrcf temperature_temp+1 ; temperature_temp /2
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
255 rrcf temperature_temp+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
256 decfsz isr2_temp,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
257 bra sensor_int8 ; once more
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
258
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
259 movff isr3_temp+1,amb_pressure+1 ; copy into actual register
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
260 movff isr3_temp+0,amb_pressure+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
261
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
262 movff temperature_temp+1,temperature+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
263 movff temperature_temp+0,temperature+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
264
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
265 bsf pressure_refresh ; Set flag! Temp and pressure were updated!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
266
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
267 btfss simulatormode_active ; are we in simulator mode?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
268 bra comp_air_pressure ; no
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
269
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
270 comp_air_pressure0:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
271 movlw LOW d'1000' ; yes, so simulate 1Bar surface pressure
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
272 movwf last_surfpressure+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
273 movlw HIGH d'1000'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
274 movwf last_surfpressure+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
275
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
276 comp_air_pressure:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
277 bcf neg_flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
278 movf last_surfpressure+0,W ; compensate airpressure
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
279 subwf amb_pressure+0,W
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
280 movwf rel_pressure+0 ; rel_pressure stores depth!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
281
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
282 movf last_surfpressure+1,W
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
283 subwfb amb_pressure+1,W
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
284 movwf rel_pressure+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
285 btfss STATUS,N ; result is below zero?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
286 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
287 clrf rel_pressure+0 ; Yes, do not display negative depths
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
288 clrf rel_pressure+1 ; e.g. when surface air pressure dropped during the dive
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
289 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
290
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
291 RTCisr:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
292 clrf timer1int_counter1 ; counts to 16 (one second / 62.5ms)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
293 bsf onesecupdate ; we have a new second!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
294
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
295 bcf STATUS,Z ; are we in dive mode?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
296 btfss divemode
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
297 bra RTCisr2 ; No, must be surface or sleepmode
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
298
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
299 incf samplesecs,F ; CF20 diving seconds done
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
300 decf samplesecs_value,W ; holds CF20 value (minus 1 into WREG)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
301 cpfsgt samplesecs
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
302 bra RTCisr1 ; no
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
303
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
304 clrf samplesecs ; clear counter...
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
305 bsf store_sample ; ...and set bit for profile storage
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
306 RTCisr1:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
307 ; Increase re-setable average depth divetime counter
111
ed7826c740a0 1.74beta rc1
heinrichsweikamp
parents: 49
diff changeset
308 incf average_divesecs+0,F ; increase stopwatch registers
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
309 btfsc STATUS,Z
111
ed7826c740a0 1.74beta rc1
heinrichsweikamp
parents: 49
diff changeset
310 incf average_divesecs+1,F ; increase stopwatch registers
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
311
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
312 btfss divemode2 ; displayed divetime is running?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
313 bra RTCisr2 ; No (e.g. too shallow)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
314
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
315 incf divesecs,F ; increase divetime registers
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
316 movlw d'59'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
317 cpfsgt divesecs
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
318 bra RTCisr1a
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
319 clrf divesecs
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
320 bsf realdive ; this bit is always set (again) if the dive is longer then one minute
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
321
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
322 incf divemins+0,F ; increase divemins
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
323 btfsc STATUS,Z
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
324 incf divemins+1,F ; and now do the realtime clock routine anyway
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
325
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
326 RTCisr1a:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
327 btfss FLAG_apnoe_mode ; Are we in Apnoe mode?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
328 bra RTCisr2 ; No, skip the following
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
329
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
330 incf apnoe_secs,F ; increase descent registers
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
331 movlw d'59'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
332 cpfsgt apnoe_secs
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
333 bra RTCisr2
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
334 clrf apnoe_secs
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
335
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
336 incf apnoe_mins,F ; increase descent mins
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
337 ; Now, do the RTC routine....
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
338 RTCisr2:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
339 incf secs,F ; adjusts seconds, minutes, hours, day, month and year. Checks for a leap year and works until 2099!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
340 movlw d'59'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
341 cpfsgt secs
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
342 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
343 clrf secs
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
344 bsf oneminupdate
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
345 incf mins,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
346 movlw d'59'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
347 cpfsgt mins
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
348 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
349 clrf mins
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
350 incf hours,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
351 movlw d'23'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
352 cpfsgt hours
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
353 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
354 clrf hours
13
3b30cd739782 1.53 beta rc2
heinrichsweikamp
parents: 0
diff changeset
355 incf day,F
43
65d5b0c8da41 New CF48, changed CF15
heinrichsweikamp
parents: 21
diff changeset
356 movff time_correction_value,secs ; Correct too slow clock
13
3b30cd739782 1.53 beta rc2
heinrichsweikamp
parents: 0
diff changeset
357
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
358 check_date:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
359 movff month,isr_divB ; new month?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
360 dcfsnz isr_divB,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
361 movlw .31
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
362 dcfsnz isr_divB,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
363 movlw .28
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
364 dcfsnz isr_divB,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
365 movlw .31
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
366 dcfsnz isr_divB,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
367 movlw .30
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
368 dcfsnz isr_divB,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
369 movlw .31
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
370 dcfsnz isr_divB,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
371 movlw .30
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
372 dcfsnz isr_divB,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
373 movlw .31
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
374 dcfsnz isr_divB,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
375 movlw .31
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
376 dcfsnz isr_divB,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
377 movlw .30
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
378 dcfsnz isr_divB,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
379 movlw .31
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
380 dcfsnz isr_divB,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
381 movlw .30
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
382 dcfsnz isr_divB,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
383 movlw .31
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
384 cpfsgt day,1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
385 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
386 movlw .1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
387 movwf day
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
388 incf month,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
389 movlw .12
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
390 cpfsgt month,1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
391 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
392 movlw .1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
393 movwf month
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
394 incf year,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
395 return