Mercurial > public > hwos_code
annotate src/adc_lightsensor.asm @ 489:22092d14fd8c
docu (battery info byte)
| author | heinrichsweikamp |
|---|---|
| date | Mon, 27 Mar 2017 16:06:09 +0200 |
| parents | 237afdfb4918 |
| children | b455b31ce022 |
| rev | line source |
|---|---|
| 0 | 1 ;============================================================================= |
| 2 ; | |
| 3 ; File adc.asm | |
| 4 ; | |
| 5 ; | |
| 6 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
| 7 ;============================================================================= | |
| 8 ; HISTORY | |
| 9 ; 2011-08-08 : [mH] moving from OSTC code | |
| 10 | |
| 275 | 11 #include "hwos.inc" |
| 0 | 12 #include "math.inc" |
| 13 #include "wait.inc" | |
| 14 #include "eeprom_rs232.inc" | |
| 113 | 15 #include "i2c.inc" |
| 0 | 16 |
| 17 sensors CODE | |
| 18 | |
| 19 wait_adc: | |
| 20 movwf ADCON0 | |
| 21 nop | |
| 22 bsf ADCON0,1 ; start ADC | |
| 23 wait_adc2: | |
| 24 btfsc ADCON0,1 ; Wait... | |
| 25 bra wait_adc2 | |
| 26 return | |
| 27 | |
| 28 global get_battery_voltage | |
| 29 get_battery_voltage: ; starts ADC and waits until fnished | |
| 448 | 30 btfss battery_gauge_available |
| 113 | 31 bra get_battery_voltage1 ; Normal ostc3 hardware |
| 32 | |
| 33 call lt2942_get_accumulated_charge | |
| 34 call lt2942_get_voltage | |
| 466 | 35 |
| 36 tstfsz batt_voltage+1 ; <256mV? | |
| 37 bra get_battery_voltage_noretry ; No | |
| 218 | 38 |
| 466 | 39 ; Retry |
| 40 call lt2942_get_accumulated_charge | |
| 41 call lt2942_get_voltage | |
| 42 | |
| 43 get_battery_voltage_noretry: | |
| 218 | 44 btfsc divemode |
| 45 return ; Not in divemode | |
| 46 | |
| 207 | 47 bcf cv_active |
| 48 bcf cc_active | |
| 120 | 49 bcf LEDr |
| 50 bcf TRISJ,2 ; Chrg-Out output | |
| 51 bsf CHRG_OUT | |
| 52 | |
| 53 btfss CHRG_IN | |
| 207 | 54 bra charge_cc_active |
| 120 | 55 |
| 56 bcf CHRG_OUT | |
| 57 bsf TRISJ,2 ; Chrg-Out high impedance | |
| 58 | |
| 59 WAITMS d'1' | |
| 60 | |
| 61 btfsc CHRG_IN | |
| 62 return | |
| 63 ;cv_active: | |
| 218 | 64 decfsz safety_stop_countdown,F |
| 65 return | |
| 266 | 66 movlw .15 |
| 67 cpfsgt batt_voltage+1 ; Batt Voltage >= 16*256mV (4,096V)? | |
| 260 | 68 bra charge_cc_active ; No |
| 207 | 69 bsf cc_active |
| 70 bsf cv_active | |
| 120 | 71 bsf LEDr ; Indicate charging |
| 72 call lt2942_charge_done ; Reset accumulating registers to 0xFFFF | |
| 73 WAITMS d'10' | |
| 74 bcf LEDr ; Indicate charging | |
| 218 | 75 bsf safety_stop_countdown,0 ; =1 |
| 120 | 76 return |
| 77 | |
| 207 | 78 charge_cc_active: |
| 79 bsf cc_active | |
| 120 | 80 bsf LEDr ; Indicate charging |
| 81 bcf CHRG_OUT | |
| 82 bsf TRISJ,2 ; Chrg-Out high impedance | |
| 260 | 83 movlw .10 |
| 218 | 84 movwf safety_stop_countdown |
| 113 | 85 return |
| 86 | |
| 87 get_battery_voltage1: | |
| 0 | 88 bsf adc_running ; =1: The ADC is in use |
| 89 movlw b'00100000' ; 2.048V Vref+ -> 1LSB = 500µV | |
| 90 movwf ADCON1 | |
| 91 movlw b'00011001' ; power on ADC, select AN6 | |
| 92 rcall wait_adc | |
| 93 | |
| 94 movff ADRESH,batt_voltage+1 ; store value | |
| 95 movff ADRESL,batt_voltage+0 ; store value | |
| 96 bcf ADCON0,0 ; power off ADC | |
| 97 | |
| 98 ; Multiply with 2,006 to be excact here... | |
| 99 ; bcf STATUS,C | |
| 100 ; rlcf xA+0,F | |
| 101 ; | |
| 102 ; rlcf xA+1,F ; x2 | |
| 103 | |
| 104 ; movff xA+0,batt_voltage+0 ; store value | |
| 105 ; movff xA+1,batt_voltage+1 | |
| 106 | |
| 107 movlw LOW lithium_36v_low | |
| 108 movwf sub_a+0 | |
| 109 movlw HIGH lithium_36v_low | |
| 110 movwf sub_a+1 | |
| 111 movff batt_voltage+0,sub_b+0 | |
| 112 movff batt_voltage+1,sub_b+1 | |
| 113 call subU16 ; sub_c = sub_a - sub_b | |
| 114 ; Battery is 3,6V (>lithium_36v_low?) | |
| 115 btfss neg_flag | |
| 116 bra get_battery_voltage4 ; No, use 1,5V | |
| 117 | |
| 118 bsf battery_is_36v ; Yes, set flag (Cleared in power-on reset only!) | |
| 119 | |
| 120 ; Check if the battery is near-dead already | |
| 121 movlw LOW lithium_36v_empty | |
| 122 movwf sub_a+0 | |
| 123 movlw HIGH lithium_36v_empty | |
| 124 movwf sub_a+1 | |
| 125 call subU16 ; sub_c = sub_a - sub_b | |
| 126 ; Battery is not dead yet (>lithium_36v_empty?) | |
| 127 btfsc neg_flag | |
| 128 bra get_battery_voltage2 ; Yes, battery is still ok | |
| 129 | |
| 130 ; Battery is probably dead very soon | |
| 131 ; Set ">=24Ah used" into battery gauge registers | |
| 132 movlw .128 | |
| 133 movff WREG,battery_gauge+5 | |
| 134 | |
| 135 get_battery_voltage2: | |
| 136 ; Use 3,6V battery gauging mode | |
| 137 movff battery_gauge+5,xC+3 | |
| 138 movff battery_gauge+4,xC+2 | |
| 139 movff battery_gauge+3,xC+1 | |
| 140 movff battery_gauge+2,xC+0 | |
| 141 ; battery_gauge:6 is nAs | |
| 142 ; devide through 65536 | |
| 448 | 143 ; devide through battery_capacity:2 |
| 144 ; Result is in percent | |
| 145 movff internal_battery_capacity+0,xB+0 | |
| 146 movff internal_battery_capacity+1,xB+1 | |
| 0 | 147 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
| 148 movff xC+0,lo | |
| 149 ; Limit to 100 | |
| 150 movlw .100 | |
| 151 cpfslt lo | |
| 152 movwf lo | |
| 153 ; lo will be between 0 (Full) and 100 (empty) | |
| 154 movf lo,W | |
| 155 sublw .100 | |
| 156 movwf lo | |
| 157 get_battery_voltage3: | |
| 158 movlw .100 | |
| 159 cpfslt lo | |
| 160 movwf lo | |
| 161 ; lo will be between 100 (Full) and 0 (empty) | |
|
37
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
162 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
163 ; use 3,6V battery sensing based on 50mA load |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
164 ; 75% |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
165 movff batt_voltage+0,sub_b+0 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
166 movff batt_voltage+1,sub_b+1 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
167 movlw LOW lithium_36v_75 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
168 movwf sub_a+0 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
169 movlw HIGH lithium_36v_75 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
170 movwf sub_a+1 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
171 call subU16 ; sub_c = sub_a - sub_b |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
172 btfsc neg_flag |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
173 bra get_battery_voltage3a |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
174 movlw .75 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
175 movwf lo |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
176 get_battery_voltage3a: |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
177 ; 50% |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
178 movlw LOW lithium_36v_50 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
179 movwf sub_a+0 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
180 movlw HIGH lithium_36v_50 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
181 movwf sub_a+1 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
182 call subU16 ; sub_c = sub_a - sub_b |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
183 btfsc neg_flag |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
184 bra get_battery_voltage3b |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
185 movlw .50 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
186 movwf lo |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
187 get_battery_voltage3b: |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
188 ; 25% |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
189 movlw LOW lithium_36v_25 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
190 movwf sub_a+0 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
191 movlw HIGH lithium_36v_25 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
192 movwf sub_a+1 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
193 call subU16 ; sub_c = sub_a - sub_b |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
194 btfsc neg_flag |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
195 bra get_battery_voltage3c |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
196 movlw .25 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
197 movwf lo |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
198 get_battery_voltage3c: |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
199 ; 10% |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
200 movlw LOW lithium_36v_10 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
201 movwf sub_a+0 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
202 movlw HIGH lithium_36v_10 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
203 movwf sub_a+1 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
204 call subU16 ; sub_c = sub_a - sub_b |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
205 btfsc neg_flag |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
206 bra get_battery_voltage3d |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
207 movlw .10 |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
208 movwf lo |
|
0e1723f2761e
use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
209 get_battery_voltage3d: |
|
44
18fe4e668baa
BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents:
37
diff
changeset
|
210 movlw .100 |
|
18fe4e668baa
BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents:
37
diff
changeset
|
211 cpfslt lo |
|
18fe4e668baa
BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents:
37
diff
changeset
|
212 movwf lo |
|
18fe4e668baa
BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents:
37
diff
changeset
|
213 ; lo will be between 100 (Full) and 0 (empty) |
| 0 | 214 movf batt_percent,W |
| 215 cpfsgt lo ; keep batt_percent on the lowest value found | |
| 216 movff lo,batt_percent ; store value | |
|
472
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
468
diff
changeset
|
217 btfsc battery_is_36v ; but always use computed value for 3,6V battery |
|
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
468
diff
changeset
|
218 movff lo,batt_percent ; store value |
| 0 | 219 bcf adc_running ; =1: The ADC is in use |
| 220 return | |
| 221 | |
| 222 get_battery_voltage4: | |
| 223 ; Use 1,5V battery voltage mode | |
| 224 ; Use approximation (batt_voltage:2-aa_15v_low)/4 = lo | |
| 225 movff batt_voltage+0,sub_a+0 | |
| 226 movff batt_voltage+1,sub_a+1 | |
| 227 movlw LOW aa_15v_low | |
| 228 movwf sub_b+0 | |
| 229 movlw HIGH aa_15v_low | |
| 230 movwf sub_b+1 | |
| 231 call subU16 ; sub_c = sub_a - sub_b | |
| 232 bcf STATUS,C | |
| 233 rrcf sub_c+1 | |
| 234 rrcf sub_c+0 ; /2 | |
| 235 bcf STATUS,C | |
| 236 rrcf sub_c+1 | |
| 237 rrcf sub_c+0 ; /4 | |
| 238 movff sub_c+0,lo | |
|
44
18fe4e668baa
BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents:
37
diff
changeset
|
239 bra get_battery_voltage3d ; Check limits and return |
| 0 | 240 |
| 241 global get_ambient_level | |
| 242 get_ambient_level: ; starts ADC and waits until finished | |
| 243 btfsc adc_running ; ADC in use? | |
| 244 return ; Yes, return | |
| 245 | |
| 236 | 246 btfsc ambient_sensor |
| 113 | 247 bra get_ambient_level1 ; Normal ostc3 hardware |
| 203 | 248 |
| 249 banksel isr_backup ; Back to Bank0 ISR data | |
| 250 movff opt_brightness,isr1_temp | |
| 251 incf isr1_temp,F ; adjust 0-2 to 1-3 | |
| 354 | 252 movlw ambient_light_max_high_cr; cR and 2 hardware brightest setting |
| 203 | 253 dcfsnz isr1_temp,F |
| 254 movlw ambient_light_max_eco ; brightest setting | |
| 255 dcfsnz isr1_temp,F | |
| 256 movlw ambient_light_max_medium; brightest setting | |
| 257 | |
| 258 movff WREG,ambient_light+0 ; Set to max. | |
| 259 movff ambient_light+0,max_CCPR1L ; Store value for dimming in TMR7 interrupt | |
| 260 return | |
| 113 | 261 |
| 262 get_ambient_level1: | |
| 0 | 263 movlw b'00000000' ; Vref+ = Vdd |
| 264 movwf ADCON1 | |
| 265 movlw b'00011101' ; power on ADC, select AN7 | |
| 266 rcall wait_adc | |
| 267 | |
| 268 movff ADRESH,ambient_light+1 | |
| 269 movff ADRESL,ambient_light+0 | |
| 270 bcf ADCON0,0 ; power off ADC | |
| 271 | |
| 272 ; ambient_light:2 is between 4096 (direct sunlight) and about 200 (darkness) | |
| 273 ; First: Devide through 16 | |
| 274 bcf STATUS,C | |
| 275 rrcf ambient_light+1 | |
| 276 rrcf ambient_light+0 | |
| 277 bcf STATUS,C | |
| 278 rrcf ambient_light+1 | |
| 279 rrcf ambient_light+0 | |
| 280 bcf STATUS,C | |
| 281 rrcf ambient_light+1 | |
| 282 rrcf ambient_light+0 | |
| 283 bcf STATUS,C | |
| 284 rrcf ambient_light+1 | |
| 285 rrcf ambient_light+0 | |
| 286 ; Result: ambient_light:2/16 | |
| 287 ; Now, make sure to have value between ambient_light_low and ambient_light_max | |
| 288 | |
| 289 movlw .254 | |
| 290 tstfsz ambient_light+1 ; >255? | |
| 291 movwf ambient_light+0 ; avoid ADC clipping | |
| 292 | |
| 293 incfsz ambient_light+0,W ; =255? | |
| 294 bra get_ambient_level2 ; No, continue | |
| 295 | |
| 296 movlw .254 | |
| 297 movwf ambient_light+0 ; avoid ADC clipping | |
| 298 | |
| 299 get_ambient_level2: | |
|
357
36bd27f42362
BUGFIX: Auto-Brightness clipped to lowest settings in bright sunlight on some devices
heinrichsweikamp
parents:
354
diff
changeset
|
300 ; movlw .10 |
|
36bd27f42362
BUGFIX: Auto-Brightness clipped to lowest settings in bright sunlight on some devices
heinrichsweikamp
parents:
354
diff
changeset
|
301 ; subwf ambient_light+0,F ; Subtract 10 (ADC Offset) |
|
36bd27f42362
BUGFIX: Auto-Brightness clipped to lowest settings in bright sunlight on some devices
heinrichsweikamp
parents:
354
diff
changeset
|
302 ; btfsc STATUS,N |
|
36bd27f42362
BUGFIX: Auto-Brightness clipped to lowest settings in bright sunlight on some devices
heinrichsweikamp
parents:
354
diff
changeset
|
303 ; movwf ambient_light+0 ; avoid clipping |
| 201 | 304 |
| 0 | 305 banksel isr_backup ; Back to Bank0 ISR data |
| 306 movff opt_brightness,isr1_temp | |
| 307 | |
| 308 btfsc RCSTA1,7 ; UART module on? | |
| 309 clrf isr1_temp ; Yes, set temporally to eco mode | |
| 310 | |
| 311 incf isr1_temp,F ; adjust 0-2 to 1-3 | |
| 312 | |
| 313 banksel common ; flag is in bank1 | |
| 354 | 314 movlw ambient_light_max_high_cr; cR and 2 hardware brightest setting |
| 448 | 315 btfss battery_gauge_available |
| 136 | 316 movlw ambient_light_max_high_15V; 1,5V battery brightest setting |
| 317 btfsc battery_is_36v ; 3,6V battery in use? | |
| 318 movlw ambient_light_max_high_36V ; 3,6V battery brightest setting | |
| 0 | 319 banksel isr_backup ; Back to Bank0 ISR data |
| 320 | |
| 321 dcfsnz isr1_temp,F | |
| 322 movlw ambient_light_max_eco ; brightest setting | |
| 323 dcfsnz isr1_temp,F | |
| 324 movlw ambient_light_max_medium; brightest setting | |
| 325 | |
| 326 banksel common ; ambient_light is in Bank1 | |
| 327 incf ambient_light+0,F ; +1 | |
| 328 cpfslt ambient_light+0 ; smaller then WREG? | |
| 329 movwf ambient_light+0 ; No, set to max. | |
| 330 | |
| 331 banksel isr_backup ; Back to Bank0 ISR data | |
| 332 movff opt_brightness,isr1_temp | |
| 333 incf isr1_temp,F ; adjust 0-2 to 1-3 | |
| 334 movlw ambient_light_min_high ; darkest setting | |
| 335 | |
| 336 dcfsnz isr1_temp,F | |
| 337 movlw ambient_light_min_eco ; darkest setting | |
| 338 dcfsnz isr1_temp,F | |
| 339 movlw ambient_light_min_medium; darkest setting | |
| 340 dcfsnz isr1_temp,F | |
| 341 movlw ambient_light_min_high ; darkest setting | |
| 342 | |
| 343 banksel common ; ambient_light is in Bank1 | |
| 344 cpfsgt ambient_light+0 ; bigger then WREG? | |
| 345 movwf ambient_light+0 ; No, set to min | |
| 346 | |
| 347 movff ambient_light+0,max_CCPR1L ; Store value for dimming in TMR7 interrupt | |
| 348 return | |
| 349 | |
| 113 | 350 global get_analog_inputs |
| 351 get_analog_inputs: ; starts ADC and waits until finished | |
| 0 | 352 bsf adc_running ; =1: The ADC is in use |
| 113 | 353 btfsc TFT_PWM |
| 354 bra get_analog_inputs ; Wait for PWM low | |
| 355 movlw b'00100000' ; 2.048V Vref+ -> 1LSB = 500µV | |
| 356 movwf ADCON1 | |
| 357 movlw b'00100001' ; power on ADC, select AN8 | |
| 358 rcall wait_adc | |
| 359 bcf STATUS,C | |
| 360 rrcf ADRESH,F ; /2 | |
|
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
361 rrcf ADRESL,W |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
362 ; add to o2_mv_sensor1:2 |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
363 addwf o2_mv_sensor1+0,F |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
364 movf ADRESH,W |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
365 addwfc o2_mv_sensor1+1,F |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
366 ; Devide by 2 |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
367 bcf STATUS,C |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
368 rrcf o2_mv_sensor1+1,F ; /2 |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
369 rrcf o2_mv_sensor1+0,F |
|
196
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
370 |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
371 movlw HIGH ignore_mv |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
372 cpfsgt o2_mv_sensor1+1 ; >ignore_mv? |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
373 bra get_analog_inputs2a ; No |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
374 ; Yes, ignore this reading |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
375 clrf o2_mv_sensor1+1 |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
376 clrf o2_mv_sensor1+0 |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
377 get_analog_inputs2a: |
| 354 | 378 ; Ignore 1,9mV noise for not-connected inputs |
|
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
158
diff
changeset
|
379 tstfsz o2_mv_sensor1+1 ; >25,5mV? |
|
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
158
diff
changeset
|
380 bra get_analog_inputs2 ; Yes, skip here |
|
270
bddb63835035
increase min input voltage from 1,2mV to 1,9mV (cR only)
heinrichsweikamp
parents:
266
diff
changeset
|
381 movlw .19 |
|
bddb63835035
increase min input voltage from 1,2mV to 1,9mV (cR only)
heinrichsweikamp
parents:
266
diff
changeset
|
382 cpfsgt o2_mv_sensor1+0 ; >1,9mV? |
|
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
158
diff
changeset
|
383 clrf o2_mv_sensor1+0 ; no, clear result |
|
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
158
diff
changeset
|
384 get_analog_inputs2: |
| 113 | 385 movlw b'00100101' ; power on ADC, select AN9 |
| 0 | 386 rcall wait_adc |
| 113 | 387 bcf STATUS,C |
| 388 rrcf ADRESH,F ; /2 | |
|
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
389 rrcf ADRESL,W |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
390 ; add to o2_mv_sensor2:2 |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
391 addwf o2_mv_sensor2+0,F |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
392 movf ADRESH,W |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
393 addwfc o2_mv_sensor2+1,F |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
394 ; Devide by 2 |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
395 bcf STATUS,C |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
396 rrcf o2_mv_sensor2+1,F ; /2 |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
397 rrcf o2_mv_sensor2+0,F |
|
196
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
398 |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
399 movlw HIGH ignore_mv |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
400 cpfsgt o2_mv_sensor2+1 ; >ignore_mv? |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
401 bra get_analog_inputs3a ; No |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
402 ; Yes, ignore this reading |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
403 clrf o2_mv_sensor2+1 |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
404 clrf o2_mv_sensor2+0 |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
405 get_analog_inputs3a: |
| 354 | 406 ; Ignore 1,9mV noise for not-connected inputs |
|
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
158
diff
changeset
|
407 tstfsz o2_mv_sensor2+1 ; >25,5mV? |
|
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
158
diff
changeset
|
408 bra get_analog_inputs3 ; Yes, skip here |
|
270
bddb63835035
increase min input voltage from 1,2mV to 1,9mV (cR only)
heinrichsweikamp
parents:
266
diff
changeset
|
409 movlw .19 |
|
bddb63835035
increase min input voltage from 1,2mV to 1,9mV (cR only)
heinrichsweikamp
parents:
266
diff
changeset
|
410 cpfsgt o2_mv_sensor2+0 ; >1,9mV? |
|
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
158
diff
changeset
|
411 clrf o2_mv_sensor2+0 ; no, clear result |
|
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
158
diff
changeset
|
412 get_analog_inputs3: |
| 113 | 413 movlw b'00101001' ; power on ADC, select AN10 |
| 414 rcall wait_adc | |
| 415 bcf STATUS,C | |
| 416 rrcf ADRESH,F ; /2 | |
|
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
417 rrcf ADRESL,W |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
418 ; add to o2_mv_sensor3:2 |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
419 addwf o2_mv_sensor3+0,F |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
420 movf ADRESH,W |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
421 addwfc o2_mv_sensor3+1,F |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
422 ; Devide by 2 |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
423 bcf STATUS,C |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
424 rrcf o2_mv_sensor3+1,F ; /2 |
|
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
425 rrcf o2_mv_sensor3+0,F |
|
196
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
426 |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
427 movlw HIGH ignore_mv |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
428 cpfsgt o2_mv_sensor3+1 ; >ignore_mv? |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
429 bra get_analog_inputs4a ; No |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
430 ; Yes, ignore this reading |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
431 clrf o2_mv_sensor3+1 |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
432 clrf o2_mv_sensor3+0 |
|
a0e0ddfc1b49
suppress ghost readings for long, open cables
heinrichsweikamp
parents:
189
diff
changeset
|
433 get_analog_inputs4a: |
| 354 | 434 ; Ignore 1,9mV noise for not-connected inputs |
|
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
158
diff
changeset
|
435 tstfsz o2_mv_sensor3+1 ; >25,5mV? |
|
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
158
diff
changeset
|
436 bra get_analog_inputs4 ; Yes, skip here |
|
270
bddb63835035
increase min input voltage from 1,2mV to 1,9mV (cR only)
heinrichsweikamp
parents:
266
diff
changeset
|
437 movlw .19 |
|
bddb63835035
increase min input voltage from 1,2mV to 1,9mV (cR only)
heinrichsweikamp
parents:
266
diff
changeset
|
438 cpfsgt o2_mv_sensor3+0 ; >1,9mV? |
|
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
158
diff
changeset
|
439 clrf o2_mv_sensor3+0 ; no, clear result |
|
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
158
diff
changeset
|
440 get_analog_inputs4: |
| 0 | 441 bcf ADCON0,0 ; power off ADC |
| 442 bcf adc_running ; =1: The ADC is in use | |
| 443 return | |
| 444 | |
| 113 | 445 global piezo_config ; Sets up piezo sensitivity of heinrichs weikamp Piezo buttons (~30ms) |
| 117 | 446 piezo_config: ; Settings between 20 and 200 |
|
416
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
357
diff
changeset
|
447 clrf TMR5H |
|
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
357
diff
changeset
|
448 clrf TMR5L ; ~2sec |
|
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
357
diff
changeset
|
449 bcf PIR5,TMR5IF ; Clear flag |
|
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
357
diff
changeset
|
450 bcf switch_right |
|
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
357
diff
changeset
|
451 bcf switch_left |
|
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
357
diff
changeset
|
452 piezo_config0: |
|
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
357
diff
changeset
|
453 btfsc switch_right |
|
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
357
diff
changeset
|
454 bra piezo_config |
|
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
357
diff
changeset
|
455 btfsc switch_left |
|
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
357
diff
changeset
|
456 bra piezo_config ; Restart on button press |
|
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
357
diff
changeset
|
457 |
|
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
357
diff
changeset
|
458 btfss PIR5,TMR5IF |
|
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
357
diff
changeset
|
459 bra piezo_config0 ; Wait loop |
| 468 | 460 |
| 461 bcf INTCON,GIE | |
|
220
effd7259f5a5
make button sensitivity configurable (cR hardware)
heinrichsweikamp
parents:
218
diff
changeset
|
462 movff opt_cR_button_right,WREG; right button |
|
343
34e2f5bdc5a2
BUGFIX: Rotate button sensitivity with screen (OSTC 2 and cR)
heinrichsweikamp
parents:
275
diff
changeset
|
463 btfsc flip_screen ; 180° rotation ? |
|
34e2f5bdc5a2
BUGFIX: Rotate button sensitivity with screen (OSTC 2 and cR)
heinrichsweikamp
parents:
275
diff
changeset
|
464 movff opt_cR_button_left,WREG ; Yes, left button |
| 117 | 465 rcall piezo_config_tx |
|
343
34e2f5bdc5a2
BUGFIX: Rotate button sensitivity with screen (OSTC 2 and cR)
heinrichsweikamp
parents:
275
diff
changeset
|
466 |
|
220
effd7259f5a5
make button sensitivity configurable (cR hardware)
heinrichsweikamp
parents:
218
diff
changeset
|
467 movff opt_cR_button_left,WREG ; left button |
|
343
34e2f5bdc5a2
BUGFIX: Rotate button sensitivity with screen (OSTC 2 and cR)
heinrichsweikamp
parents:
275
diff
changeset
|
468 btfsc flip_screen ; 180° rotation ? |
|
34e2f5bdc5a2
BUGFIX: Rotate button sensitivity with screen (OSTC 2 and cR)
heinrichsweikamp
parents:
275
diff
changeset
|
469 movff opt_cR_button_right,WREG; Yes, right button |
| 204 | 470 rcall piezo_config_tx |
|
343
34e2f5bdc5a2
BUGFIX: Rotate button sensitivity with screen (OSTC 2 and cR)
heinrichsweikamp
parents:
275
diff
changeset
|
471 |
| 468 | 472 movlw .20 ; reserved |
| 204 | 473 rcall piezo_config_tx |
| 468 | 474 movlw .20 ; reserved |
| 204 | 475 rcall piezo_config_tx |
| 468 | 476 bsf INTCON,GIE |
| 204 | 477 return |
| 478 | |
| 117 | 479 piezo_config_tx: ; Send one byte |
| 113 | 480 movwf uart1_temp ; Store byte |
| 481 movlw .8 | |
| 482 movwf uart2_temp ; Bit counter | |
| 483 bcf TX3_PIEZO_CFG ; Startbit | |
| 484 rcall piezo_config_wait_bit | |
| 485 piezo_config_tx_loop: | |
| 486 btfss uart1_temp,0 ; LSB first | |
| 487 bcf TX3_PIEZO_CFG | |
| 488 btfsc uart1_temp,0 ; LSB first | |
| 489 bsf TX3_PIEZO_CFG | |
| 490 rcall piezo_config_wait_bit | |
| 491 rrncf uart1_temp,F | |
| 492 decfsz uart2_temp,F | |
| 493 bra piezo_config_tx_loop | |
| 494 bsf TX3_PIEZO_CFG ; Stopbit | |
| 495 rcall piezo_config_wait_bit | |
| 496 return | |
| 497 | |
| 498 piezo_config_wait_bit: | |
| 499 setf TMR5H | |
| 500 movlw .255-.26 ;26 x 31,5µs = 819us | |
| 501 movwf TMR5L | |
| 502 bcf PIR5,TMR5IF ; Clear flag | |
| 503 piezo_config_wait_bit3: | |
| 504 btfss PIR5,TMR5IF | |
| 505 bra piezo_config_wait_bit3 ; Wait loop | |
| 506 return | |
| 507 | |
| 448 | 508 global reset_battery_pointer, reset_battery_internal_only |
| 0 | 509 reset_battery_pointer: ; Resets battery pointer 0x07-0x0C and battery_gauge:5 |
| 113 | 510 extern lt2942_charge_done |
| 448 | 511 btfsc battery_gauge_available ; Something to reset? |
| 260 | 512 call lt2942_charge_done ; Yes, reset accumulating registers to 0xFFFF |
| 448 | 513 reset_battery_internal_only: |
| 113 | 514 clrf EEADRH |
| 448 | 515 clrf EEDATA ; Delete to zero |
| 516 write_int_eeprom 0x07 | |
| 517 write_int_eeprom 0x08 | |
| 518 write_int_eeprom 0x09 | |
| 519 write_int_eeprom 0x0A | |
| 520 write_int_eeprom 0x0B | |
| 521 write_int_eeprom 0x0C | |
| 0 | 522 banksel battery_gauge+0 |
| 523 clrf battery_gauge+0 | |
| 524 clrf battery_gauge+1 | |
| 525 clrf battery_gauge+2 | |
| 526 clrf battery_gauge+3 | |
| 527 clrf battery_gauge+4 | |
| 528 clrf battery_gauge+5 | |
| 529 banksel common | |
| 530 movlw .100 | |
| 531 movwf batt_percent | |
| 532 return | |
| 533 | |
| 448 | 534 global get_analog_switches |
| 535 get_analog_switches: ; starts ADC and waits until finished | |
| 536 btfsc analog_switches | |
| 537 bra get_analog_switches2 | |
| 538 ; no analog switches | |
| 539 bcf analog_sw2_pressed | |
| 540 bcf analog_sw1_pressed | |
| 541 return ; Done. | |
| 542 get_analog_switches2: | |
| 543 btfsc adc_running ; ADC in use? | |
| 544 return ; Yes, return | |
| 545 | |
| 546 movlw b'00001001' ; left justified | |
| 547 movwf ADCON2 | |
|
472
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
468
diff
changeset
|
548 ; movlw b'00000000' ; Vref+ = Vdd |
|
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
468
diff
changeset
|
549 clrf ADCON1 |
| 448 | 550 movlw b'00100101' ; power on ADC, select AN9 |
| 551 rcall wait_adc | |
| 474 | 552 banksel analog_counter |
| 553 movff ADRESH,WREG | |
| 554 addwf analog_sw2_raw+0 | |
| 555 movlw .0 | |
| 556 addwfc analog_sw2_raw+1 | |
| 557 decfsz analog_counter,F ; continue averaging? | |
| 558 bra get_analog_switches2a ; Yes | |
| 559 ; Done. Compute average | |
| 560 bcf STATUS,C | |
| 561 rrcf analog_sw2_raw+1 | |
| 562 rrcf analog_sw2_raw+0 ; /2 | |
| 563 bcf STATUS,C | |
| 564 rrcf analog_sw2_raw+1 | |
| 565 rrcf analog_sw2_raw+0 ; /4 | |
| 566 bcf STATUS,C | |
| 567 rrcf analog_sw2_raw+1 | |
| 568 rrcf analog_sw2_raw+0 ; /8 | |
| 569 bcf STATUS,C | |
| 570 rrcf analog_sw2_raw+1 | |
| 571 rrcf analog_sw2_raw+0 ; /16 | |
| 572 movff analog_sw2_raw+0, analog_sw2 | |
| 573 clrf analog_sw2_raw+1 | |
| 574 clrf analog_sw2_raw+0 ; Reset average registers | |
| 575 ; movlw .16 | |
| 576 ; movwf analog_counter ; only once... | |
| 577 get_analog_switches2a: | |
| 578 banksel common | |
| 448 | 579 bcf analog_sw2_pressed |
|
472
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
468
diff
changeset
|
580 movff opt_cR_button_left,WREG ;20-100 |
|
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
468
diff
changeset
|
581 bcf STATUS,C |
|
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
468
diff
changeset
|
582 rrcf WREG ;/2 -> 10-50 |
|
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
468
diff
changeset
|
583 bcf STATUS,C |
|
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
468
diff
changeset
|
584 rrcf WREG ;/2 -> 5-25 |
| 474 | 585 decf WREG,W ;-1 |
| 586 decf WREG,W ;-1 | |
| 587 decf WREG,W ;-1 -> 2-22 | |
| 588 banksel analog_sw2 | |
| 475 | 589 btfss button_polarity,1;(1= normal, 0=inverted) |
| 590 bra sw2_inverted | |
| 474 | 591 addwf analog_sw2,W ; average (~128) |
| 448 | 592 cpfsgt ADRESH |
| 593 bra get_analog_sw1 | |
| 475 | 594 banksel common |
| 595 bsf analog_sw2_pressed ; Left button normal | |
| 596 bra get_analog_sw1 | |
| 597 sw2_inverted: | |
| 598 subwf analog_sw2,W ; average (~128) | |
| 599 cpfslt ADRESH | |
| 600 bra get_analog_sw1 | |
| 601 banksel common | |
| 602 bsf analog_sw2_pressed ; Left button inverted | |
| 448 | 603 get_analog_sw1: |
| 475 | 604 banksel common |
| 448 | 605 movlw b'00101001' ; power on ADC, select AN10 |
| 606 rcall wait_adc | |
| 474 | 607 banksel analog_counter |
| 608 movff ADRESH,WREG | |
| 609 addwf analog_sw1_raw+0 | |
| 610 movlw .0 | |
| 611 addwfc analog_sw1_raw+1 | |
| 612 tstfsz analog_counter ; continue averaging? | |
| 613 bra get_analog_switches1a ; Yes | |
| 614 ; Done. Compute average | |
| 615 bcf STATUS,C | |
| 616 rrcf analog_sw1_raw+1 | |
| 617 rrcf analog_sw1_raw+0 ; /2 | |
| 618 bcf STATUS,C | |
| 619 rrcf analog_sw1_raw+1 | |
| 620 rrcf analog_sw1_raw+0 ; /4 | |
| 621 bcf STATUS,C | |
| 622 rrcf analog_sw1_raw+1 | |
| 623 rrcf analog_sw1_raw+0 ; /8 | |
| 624 bcf STATUS,C | |
| 625 rrcf analog_sw1_raw+1 | |
| 626 rrcf analog_sw1_raw+0 ; /16 | |
| 627 movff analog_sw1_raw+0, analog_sw1 | |
| 628 clrf analog_sw1_raw+1 | |
| 629 clrf analog_sw1_raw+0 ; Reset average registers | |
| 630 movlw .16 | |
| 631 movwf analog_counter ; only once... | |
| 632 get_analog_switches1a: | |
| 633 banksel common | |
| 448 | 634 bcf analog_sw1_pressed |
| 474 | 635 movff opt_cR_button_right,WREG ;20-100 |
|
472
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
468
diff
changeset
|
636 bcf STATUS,C |
|
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
468
diff
changeset
|
637 rrcf WREG ;/2 -> 10-50 |
|
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
468
diff
changeset
|
638 bcf STATUS,C |
|
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
468
diff
changeset
|
639 rrcf WREG ;/2 -> 5-25 |
| 474 | 640 decf WREG,W ;-1 |
| 641 decf WREG,W ;-1 | |
| 642 decf WREG,W ;-1 -> 2-22 | |
| 643 banksel analog_sw1 | |
| 475 | 644 btfss button_polarity,0;(1= normal, 0=inverted) |
| 645 bra sw1_inverted | |
| 474 | 646 addwf analog_sw1,W ; average (~128) |
| 448 | 647 cpfsgt ADRESH |
| 648 bra get_analog_sw_done | |
| 475 | 649 banksel common |
| 650 bsf analog_sw1_pressed ; right button normal | |
| 651 bra get_analog_sw_done | |
| 652 sw1_inverted: | |
| 653 subwf analog_sw1,W ; average (~128) | |
| 654 cpfslt ADRESH | |
| 655 bra get_analog_sw_done | |
| 656 banksel common | |
| 657 bsf analog_sw1_pressed ; right button inverted | |
| 448 | 658 get_analog_sw_done: |
| 475 | 659 banksel common |
| 448 | 660 movlw b'10001101' ; Restore to right justified |
| 661 movwf ADCON2 | |
| 451 | 662 btfsc analog_sw1_pressed |
| 663 return | |
| 664 btfsc analog_sw2_pressed | |
| 665 return | |
| 666 setf TMR1H ; No button pressed, enhance timer1 to overflow quickly | |
| 448 | 667 return |
| 668 | |
| 0 | 669 END |
