annotate src/adc_lightsensor.asm @ 501:69a98f3f3b84

minor
author heinrichsweikamp
date Mon, 22 May 2017 23:03:21 +0200
parents 237afdfb4918
children b455b31ce022
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
heinrichsweikamp
parents:
diff changeset
3 ; File adc.asm
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ;
heinrichsweikamp
parents:
diff changeset
6 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
7 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
8 ; HISTORY
heinrichsweikamp
parents:
diff changeset
9 ; 2011-08-08 : [mH] moving from OSTC code
heinrichsweikamp
parents:
diff changeset
10
275
653a3ab08062 rename into hwOS
heinrichsweikamp
parents: 270
diff changeset
11 #include "hwos.inc"
0
heinrichsweikamp
parents:
diff changeset
12 #include "math.inc"
heinrichsweikamp
parents:
diff changeset
13 #include "wait.inc"
heinrichsweikamp
parents:
diff changeset
14 #include "eeprom_rs232.inc"
113
heinrichsweikamp
parents: 44
diff changeset
15 #include "i2c.inc"
0
heinrichsweikamp
parents:
diff changeset
16
heinrichsweikamp
parents:
diff changeset
17 sensors CODE
heinrichsweikamp
parents:
diff changeset
18
heinrichsweikamp
parents:
diff changeset
19 wait_adc:
heinrichsweikamp
parents:
diff changeset
20 movwf ADCON0
heinrichsweikamp
parents:
diff changeset
21 nop
heinrichsweikamp
parents:
diff changeset
22 bsf ADCON0,1 ; start ADC
heinrichsweikamp
parents:
diff changeset
23 wait_adc2:
heinrichsweikamp
parents:
diff changeset
24 btfsc ADCON0,1 ; Wait...
heinrichsweikamp
parents:
diff changeset
25 bra wait_adc2
heinrichsweikamp
parents:
diff changeset
26 return
heinrichsweikamp
parents:
diff changeset
27
heinrichsweikamp
parents:
diff changeset
28 global get_battery_voltage
heinrichsweikamp
parents:
diff changeset
29 get_battery_voltage: ; starts ADC and waits until fnished
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
30 btfss battery_gauge_available
113
heinrichsweikamp
parents: 44
diff changeset
31 bra get_battery_voltage1 ; Normal ostc3 hardware
heinrichsweikamp
parents: 44
diff changeset
32
heinrichsweikamp
parents: 44
diff changeset
33 call lt2942_get_accumulated_charge
heinrichsweikamp
parents: 44
diff changeset
34 call lt2942_get_voltage
466
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 465
diff changeset
35
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 465
diff changeset
36 tstfsz batt_voltage+1 ; <256mV?
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 465
diff changeset
37 bra get_battery_voltage_noretry ; No
218
8fbd8c5ac51f 1.71beta start
heinrichsweikamp
parents: 207
diff changeset
38
466
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 465
diff changeset
39 ; Retry
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 465
diff changeset
40 call lt2942_get_accumulated_charge
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 465
diff changeset
41 call lt2942_get_voltage
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 465
diff changeset
42
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 465
diff changeset
43 get_battery_voltage_noretry:
218
8fbd8c5ac51f 1.71beta start
heinrichsweikamp
parents: 207
diff changeset
44 btfsc divemode
8fbd8c5ac51f 1.71beta start
heinrichsweikamp
parents: 207
diff changeset
45 return ; Not in divemode
8fbd8c5ac51f 1.71beta start
heinrichsweikamp
parents: 207
diff changeset
46
207
f5d909e03f52 charge indicator on surface screen
heinrichsweikamp
parents: 204
diff changeset
47 bcf cv_active
f5d909e03f52 charge indicator on surface screen
heinrichsweikamp
parents: 204
diff changeset
48 bcf cc_active
120
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
49 bcf LEDr
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
50 bcf TRISJ,2 ; Chrg-Out output
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
51 bsf CHRG_OUT
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
52
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
53 btfss CHRG_IN
207
f5d909e03f52 charge indicator on surface screen
heinrichsweikamp
parents: 204
diff changeset
54 bra charge_cc_active
120
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
55
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
56 bcf CHRG_OUT
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
57 bsf TRISJ,2 ; Chrg-Out high impedance
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
58
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
59 WAITMS d'1'
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
60
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
61 btfsc CHRG_IN
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
62 return
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
63 ;cv_active:
218
8fbd8c5ac51f 1.71beta start
heinrichsweikamp
parents: 207
diff changeset
64 decfsz safety_stop_countdown,F
8fbd8c5ac51f 1.71beta start
heinrichsweikamp
parents: 207
diff changeset
65 return
266
6a1ac89e2098 Charge done indicator (cR and 2 Hardware)
heinrichsweikamp
parents: 260
diff changeset
66 movlw .15
6a1ac89e2098 Charge done indicator (cR and 2 Hardware)
heinrichsweikamp
parents: 260
diff changeset
67 cpfsgt batt_voltage+1 ; Batt Voltage >= 16*256mV (4,096V)?
260
e1cd6848863d increase immunity against false Qi data
heinrichsweikamp
parents: 236
diff changeset
68 bra charge_cc_active ; No
207
f5d909e03f52 charge indicator on surface screen
heinrichsweikamp
parents: 204
diff changeset
69 bsf cc_active
f5d909e03f52 charge indicator on surface screen
heinrichsweikamp
parents: 204
diff changeset
70 bsf cv_active
120
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
71 bsf LEDr ; Indicate charging
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
72 call lt2942_charge_done ; Reset accumulating registers to 0xFFFF
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
73 WAITMS d'10'
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
74 bcf LEDr ; Indicate charging
218
8fbd8c5ac51f 1.71beta start
heinrichsweikamp
parents: 207
diff changeset
75 bsf safety_stop_countdown,0 ; =1
120
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
76 return
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
77
207
f5d909e03f52 charge indicator on surface screen
heinrichsweikamp
parents: 204
diff changeset
78 charge_cc_active:
f5d909e03f52 charge indicator on surface screen
heinrichsweikamp
parents: 204
diff changeset
79 bsf cc_active
120
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
80 bsf LEDr ; Indicate charging
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
81 bcf CHRG_OUT
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
82 bsf TRISJ,2 ; Chrg-Out high impedance
260
e1cd6848863d increase immunity against false Qi data
heinrichsweikamp
parents: 236
diff changeset
83 movlw .10
218
8fbd8c5ac51f 1.71beta start
heinrichsweikamp
parents: 207
diff changeset
84 movwf safety_stop_countdown
113
heinrichsweikamp
parents: 44
diff changeset
85 return
heinrichsweikamp
parents: 44
diff changeset
86
heinrichsweikamp
parents: 44
diff changeset
87 get_battery_voltage1:
0
heinrichsweikamp
parents:
diff changeset
88 bsf adc_running ; =1: The ADC is in use
heinrichsweikamp
parents:
diff changeset
89 movlw b'00100000' ; 2.048V Vref+ -> 1LSB = 500µV
heinrichsweikamp
parents:
diff changeset
90 movwf ADCON1
heinrichsweikamp
parents:
diff changeset
91 movlw b'00011001' ; power on ADC, select AN6
heinrichsweikamp
parents:
diff changeset
92 rcall wait_adc
heinrichsweikamp
parents:
diff changeset
93
heinrichsweikamp
parents:
diff changeset
94 movff ADRESH,batt_voltage+1 ; store value
heinrichsweikamp
parents:
diff changeset
95 movff ADRESL,batt_voltage+0 ; store value
heinrichsweikamp
parents:
diff changeset
96 bcf ADCON0,0 ; power off ADC
heinrichsweikamp
parents:
diff changeset
97
heinrichsweikamp
parents:
diff changeset
98 ; Multiply with 2,006 to be excact here...
heinrichsweikamp
parents:
diff changeset
99 ; bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
100 ; rlcf xA+0,F
heinrichsweikamp
parents:
diff changeset
101 ;
heinrichsweikamp
parents:
diff changeset
102 ; rlcf xA+1,F ; x2
heinrichsweikamp
parents:
diff changeset
103
heinrichsweikamp
parents:
diff changeset
104 ; movff xA+0,batt_voltage+0 ; store value
heinrichsweikamp
parents:
diff changeset
105 ; movff xA+1,batt_voltage+1
heinrichsweikamp
parents:
diff changeset
106
heinrichsweikamp
parents:
diff changeset
107 movlw LOW lithium_36v_low
heinrichsweikamp
parents:
diff changeset
108 movwf sub_a+0
heinrichsweikamp
parents:
diff changeset
109 movlw HIGH lithium_36v_low
heinrichsweikamp
parents:
diff changeset
110 movwf sub_a+1
heinrichsweikamp
parents:
diff changeset
111 movff batt_voltage+0,sub_b+0
heinrichsweikamp
parents:
diff changeset
112 movff batt_voltage+1,sub_b+1
heinrichsweikamp
parents:
diff changeset
113 call subU16 ; sub_c = sub_a - sub_b
heinrichsweikamp
parents:
diff changeset
114 ; Battery is 3,6V (>lithium_36v_low?)
heinrichsweikamp
parents:
diff changeset
115 btfss neg_flag
heinrichsweikamp
parents:
diff changeset
116 bra get_battery_voltage4 ; No, use 1,5V
heinrichsweikamp
parents:
diff changeset
117
heinrichsweikamp
parents:
diff changeset
118 bsf battery_is_36v ; Yes, set flag (Cleared in power-on reset only!)
heinrichsweikamp
parents:
diff changeset
119
heinrichsweikamp
parents:
diff changeset
120 ; Check if the battery is near-dead already
heinrichsweikamp
parents:
diff changeset
121 movlw LOW lithium_36v_empty
heinrichsweikamp
parents:
diff changeset
122 movwf sub_a+0
heinrichsweikamp
parents:
diff changeset
123 movlw HIGH lithium_36v_empty
heinrichsweikamp
parents:
diff changeset
124 movwf sub_a+1
heinrichsweikamp
parents:
diff changeset
125 call subU16 ; sub_c = sub_a - sub_b
heinrichsweikamp
parents:
diff changeset
126 ; Battery is not dead yet (>lithium_36v_empty?)
heinrichsweikamp
parents:
diff changeset
127 btfsc neg_flag
heinrichsweikamp
parents:
diff changeset
128 bra get_battery_voltage2 ; Yes, battery is still ok
heinrichsweikamp
parents:
diff changeset
129
heinrichsweikamp
parents:
diff changeset
130 ; Battery is probably dead very soon
heinrichsweikamp
parents:
diff changeset
131 ; Set ">=24Ah used" into battery gauge registers
heinrichsweikamp
parents:
diff changeset
132 movlw .128
heinrichsweikamp
parents:
diff changeset
133 movff WREG,battery_gauge+5
heinrichsweikamp
parents:
diff changeset
134
heinrichsweikamp
parents:
diff changeset
135 get_battery_voltage2:
heinrichsweikamp
parents:
diff changeset
136 ; Use 3,6V battery gauging mode
heinrichsweikamp
parents:
diff changeset
137 movff battery_gauge+5,xC+3
heinrichsweikamp
parents:
diff changeset
138 movff battery_gauge+4,xC+2
heinrichsweikamp
parents:
diff changeset
139 movff battery_gauge+3,xC+1
heinrichsweikamp
parents:
diff changeset
140 movff battery_gauge+2,xC+0
heinrichsweikamp
parents:
diff changeset
141 ; battery_gauge:6 is nAs
heinrichsweikamp
parents:
diff changeset
142 ; devide through 65536
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
143 ; devide through battery_capacity:2
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
144 ; Result is in percent
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
145 movff internal_battery_capacity+0,xB+0
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
146 movff internal_battery_capacity+1,xB+1
0
heinrichsweikamp
parents:
diff changeset
147 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
148 movff xC+0,lo
heinrichsweikamp
parents:
diff changeset
149 ; Limit to 100
heinrichsweikamp
parents:
diff changeset
150 movlw .100
heinrichsweikamp
parents:
diff changeset
151 cpfslt lo
heinrichsweikamp
parents:
diff changeset
152 movwf lo
heinrichsweikamp
parents:
diff changeset
153 ; lo will be between 0 (Full) and 100 (empty)
heinrichsweikamp
parents:
diff changeset
154 movf lo,W
heinrichsweikamp
parents:
diff changeset
155 sublw .100
heinrichsweikamp
parents:
diff changeset
156 movwf lo
heinrichsweikamp
parents:
diff changeset
157 get_battery_voltage3:
heinrichsweikamp
parents:
diff changeset
158 movlw .100
heinrichsweikamp
parents:
diff changeset
159 cpfslt lo
heinrichsweikamp
parents:
diff changeset
160 movwf lo
heinrichsweikamp
parents:
diff changeset
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
heinrichsweikamp
parents:
diff changeset
214 movf batt_percent,W
heinrichsweikamp
parents:
diff changeset
215 cpfsgt lo ; keep batt_percent on the lowest value found
heinrichsweikamp
parents:
diff changeset
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
heinrichsweikamp
parents:
diff changeset
219 bcf adc_running ; =1: The ADC is in use
heinrichsweikamp
parents:
diff changeset
220 return
heinrichsweikamp
parents:
diff changeset
221
heinrichsweikamp
parents:
diff changeset
222 get_battery_voltage4:
heinrichsweikamp
parents:
diff changeset
223 ; Use 1,5V battery voltage mode
heinrichsweikamp
parents:
diff changeset
224 ; Use approximation (batt_voltage:2-aa_15v_low)/4 = lo
heinrichsweikamp
parents:
diff changeset
225 movff batt_voltage+0,sub_a+0
heinrichsweikamp
parents:
diff changeset
226 movff batt_voltage+1,sub_a+1
heinrichsweikamp
parents:
diff changeset
227 movlw LOW aa_15v_low
heinrichsweikamp
parents:
diff changeset
228 movwf sub_b+0
heinrichsweikamp
parents:
diff changeset
229 movlw HIGH aa_15v_low
heinrichsweikamp
parents:
diff changeset
230 movwf sub_b+1
heinrichsweikamp
parents:
diff changeset
231 call subU16 ; sub_c = sub_a - sub_b
heinrichsweikamp
parents:
diff changeset
232 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
233 rrcf sub_c+1
heinrichsweikamp
parents:
diff changeset
234 rrcf sub_c+0 ; /2
heinrichsweikamp
parents:
diff changeset
235 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
236 rrcf sub_c+1
heinrichsweikamp
parents:
diff changeset
237 rrcf sub_c+0 ; /4
heinrichsweikamp
parents:
diff changeset
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
heinrichsweikamp
parents:
diff changeset
240
heinrichsweikamp
parents:
diff changeset
241 global get_ambient_level
heinrichsweikamp
parents:
diff changeset
242 get_ambient_level: ; starts ADC and waits until finished
heinrichsweikamp
parents:
diff changeset
243 btfsc adc_running ; ADC in use?
heinrichsweikamp
parents:
diff changeset
244 return ; Yes, return
heinrichsweikamp
parents:
diff changeset
245
236
e2ea74646127 configure hardware_flag byte
heinrichsweikamp
parents: 235
diff changeset
246 btfsc ambient_sensor
113
heinrichsweikamp
parents: 44
diff changeset
247 bra get_ambient_level1 ; Normal ostc3 hardware
203
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
248
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
249 banksel isr_backup ; Back to Bank0 ISR data
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
250 movff opt_brightness,isr1_temp
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
251 incf isr1_temp,F ; adjust 0-2 to 1-3
354
043890f06bce some cleanups
heinrichsweikamp
parents: 343
diff changeset
252 movlw ambient_light_max_high_cr; cR and 2 hardware brightest setting
203
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
253 dcfsnz isr1_temp,F
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
254 movlw ambient_light_max_eco ; brightest setting
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
255 dcfsnz isr1_temp,F
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
256 movlw ambient_light_max_medium; brightest setting
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
257
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
258 movff WREG,ambient_light+0 ; Set to max.
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
259 movff ambient_light+0,max_CCPR1L ; Store value for dimming in TMR7 interrupt
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
260 return
113
heinrichsweikamp
parents: 44
diff changeset
261
heinrichsweikamp
parents: 44
diff changeset
262 get_ambient_level1:
0
heinrichsweikamp
parents:
diff changeset
263 movlw b'00000000' ; Vref+ = Vdd
heinrichsweikamp
parents:
diff changeset
264 movwf ADCON1
heinrichsweikamp
parents:
diff changeset
265 movlw b'00011101' ; power on ADC, select AN7
heinrichsweikamp
parents:
diff changeset
266 rcall wait_adc
heinrichsweikamp
parents:
diff changeset
267
heinrichsweikamp
parents:
diff changeset
268 movff ADRESH,ambient_light+1
heinrichsweikamp
parents:
diff changeset
269 movff ADRESL,ambient_light+0
heinrichsweikamp
parents:
diff changeset
270 bcf ADCON0,0 ; power off ADC
heinrichsweikamp
parents:
diff changeset
271
heinrichsweikamp
parents:
diff changeset
272 ; ambient_light:2 is between 4096 (direct sunlight) and about 200 (darkness)
heinrichsweikamp
parents:
diff changeset
273 ; First: Devide through 16
heinrichsweikamp
parents:
diff changeset
274 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
275 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
276 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
277 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
278 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
279 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
280 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
281 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
282 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
283 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
284 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
285 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
286 ; Result: ambient_light:2/16
heinrichsweikamp
parents:
diff changeset
287 ; Now, make sure to have value between ambient_light_low and ambient_light_max
heinrichsweikamp
parents:
diff changeset
288
heinrichsweikamp
parents:
diff changeset
289 movlw .254
heinrichsweikamp
parents:
diff changeset
290 tstfsz ambient_light+1 ; >255?
heinrichsweikamp
parents:
diff changeset
291 movwf ambient_light+0 ; avoid ADC clipping
heinrichsweikamp
parents:
diff changeset
292
heinrichsweikamp
parents:
diff changeset
293 incfsz ambient_light+0,W ; =255?
heinrichsweikamp
parents:
diff changeset
294 bra get_ambient_level2 ; No, continue
heinrichsweikamp
parents:
diff changeset
295
heinrichsweikamp
parents:
diff changeset
296 movlw .254
heinrichsweikamp
parents:
diff changeset
297 movwf ambient_light+0 ; avoid ADC clipping
heinrichsweikamp
parents:
diff changeset
298
heinrichsweikamp
parents:
diff changeset
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
82faedf8fd58 lower minimum backlight in eco mode
heinrichsweikamp
parents: 200
diff changeset
304
0
heinrichsweikamp
parents:
diff changeset
305 banksel isr_backup ; Back to Bank0 ISR data
heinrichsweikamp
parents:
diff changeset
306 movff opt_brightness,isr1_temp
heinrichsweikamp
parents:
diff changeset
307
heinrichsweikamp
parents:
diff changeset
308 btfsc RCSTA1,7 ; UART module on?
heinrichsweikamp
parents:
diff changeset
309 clrf isr1_temp ; Yes, set temporally to eco mode
heinrichsweikamp
parents:
diff changeset
310
heinrichsweikamp
parents:
diff changeset
311 incf isr1_temp,F ; adjust 0-2 to 1-3
heinrichsweikamp
parents:
diff changeset
312
heinrichsweikamp
parents:
diff changeset
313 banksel common ; flag is in bank1
354
043890f06bce some cleanups
heinrichsweikamp
parents: 343
diff changeset
314 movlw ambient_light_max_high_cr; cR and 2 hardware brightest setting
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
315 btfss battery_gauge_available
136
9a637c9bb19a rename Deco Planner to Simulator
heinrichsweikamp
parents: 120
diff changeset
316 movlw ambient_light_max_high_15V; 1,5V battery brightest setting
9a637c9bb19a rename Deco Planner to Simulator
heinrichsweikamp
parents: 120
diff changeset
317 btfsc battery_is_36v ; 3,6V battery in use?
9a637c9bb19a rename Deco Planner to Simulator
heinrichsweikamp
parents: 120
diff changeset
318 movlw ambient_light_max_high_36V ; 3,6V battery brightest setting
0
heinrichsweikamp
parents:
diff changeset
319 banksel isr_backup ; Back to Bank0 ISR data
heinrichsweikamp
parents:
diff changeset
320
heinrichsweikamp
parents:
diff changeset
321 dcfsnz isr1_temp,F
heinrichsweikamp
parents:
diff changeset
322 movlw ambient_light_max_eco ; brightest setting
heinrichsweikamp
parents:
diff changeset
323 dcfsnz isr1_temp,F
heinrichsweikamp
parents:
diff changeset
324 movlw ambient_light_max_medium; brightest setting
heinrichsweikamp
parents:
diff changeset
325
heinrichsweikamp
parents:
diff changeset
326 banksel common ; ambient_light is in Bank1
heinrichsweikamp
parents:
diff changeset
327 incf ambient_light+0,F ; +1
heinrichsweikamp
parents:
diff changeset
328 cpfslt ambient_light+0 ; smaller then WREG?
heinrichsweikamp
parents:
diff changeset
329 movwf ambient_light+0 ; No, set to max.
heinrichsweikamp
parents:
diff changeset
330
heinrichsweikamp
parents:
diff changeset
331 banksel isr_backup ; Back to Bank0 ISR data
heinrichsweikamp
parents:
diff changeset
332 movff opt_brightness,isr1_temp
heinrichsweikamp
parents:
diff changeset
333 incf isr1_temp,F ; adjust 0-2 to 1-3
heinrichsweikamp
parents:
diff changeset
334 movlw ambient_light_min_high ; darkest setting
heinrichsweikamp
parents:
diff changeset
335
heinrichsweikamp
parents:
diff changeset
336 dcfsnz isr1_temp,F
heinrichsweikamp
parents:
diff changeset
337 movlw ambient_light_min_eco ; darkest setting
heinrichsweikamp
parents:
diff changeset
338 dcfsnz isr1_temp,F
heinrichsweikamp
parents:
diff changeset
339 movlw ambient_light_min_medium; darkest setting
heinrichsweikamp
parents:
diff changeset
340 dcfsnz isr1_temp,F
heinrichsweikamp
parents:
diff changeset
341 movlw ambient_light_min_high ; darkest setting
heinrichsweikamp
parents:
diff changeset
342
heinrichsweikamp
parents:
diff changeset
343 banksel common ; ambient_light is in Bank1
heinrichsweikamp
parents:
diff changeset
344 cpfsgt ambient_light+0 ; bigger then WREG?
heinrichsweikamp
parents:
diff changeset
345 movwf ambient_light+0 ; No, set to min
heinrichsweikamp
parents:
diff changeset
346
heinrichsweikamp
parents:
diff changeset
347 movff ambient_light+0,max_CCPR1L ; Store value for dimming in TMR7 interrupt
heinrichsweikamp
parents:
diff changeset
348 return
heinrichsweikamp
parents:
diff changeset
349
113
heinrichsweikamp
parents: 44
diff changeset
350 global get_analog_inputs
heinrichsweikamp
parents: 44
diff changeset
351 get_analog_inputs: ; starts ADC and waits until finished
0
heinrichsweikamp
parents:
diff changeset
352 bsf adc_running ; =1: The ADC is in use
113
heinrichsweikamp
parents: 44
diff changeset
353 btfsc TFT_PWM
heinrichsweikamp
parents: 44
diff changeset
354 bra get_analog_inputs ; Wait for PWM low
heinrichsweikamp
parents: 44
diff changeset
355 movlw b'00100000' ; 2.048V Vref+ -> 1LSB = 500µV
heinrichsweikamp
parents: 44
diff changeset
356 movwf ADCON1
heinrichsweikamp
parents: 44
diff changeset
357 movlw b'00100001' ; power on ADC, select AN8
heinrichsweikamp
parents: 44
diff changeset
358 rcall wait_adc
heinrichsweikamp
parents: 44
diff changeset
359 bcf STATUS,C
heinrichsweikamp
parents: 44
diff changeset
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
043890f06bce some cleanups
heinrichsweikamp
parents: 343
diff changeset
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
heinrichsweikamp
parents: 44
diff changeset
385 movlw b'00100101' ; power on ADC, select AN9
0
heinrichsweikamp
parents:
diff changeset
386 rcall wait_adc
113
heinrichsweikamp
parents: 44
diff changeset
387 bcf STATUS,C
heinrichsweikamp
parents: 44
diff changeset
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
043890f06bce some cleanups
heinrichsweikamp
parents: 343
diff changeset
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
heinrichsweikamp
parents: 44
diff changeset
413 movlw b'00101001' ; power on ADC, select AN10
heinrichsweikamp
parents: 44
diff changeset
414 rcall wait_adc
heinrichsweikamp
parents: 44
diff changeset
415 bcf STATUS,C
heinrichsweikamp
parents: 44
diff changeset
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
043890f06bce some cleanups
heinrichsweikamp
parents: 343
diff changeset
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
heinrichsweikamp
parents:
diff changeset
441 bcf ADCON0,0 ; power off ADC
heinrichsweikamp
parents:
diff changeset
442 bcf adc_running ; =1: The ADC is in use
heinrichsweikamp
parents:
diff changeset
443 return
heinrichsweikamp
parents:
diff changeset
444
113
heinrichsweikamp
parents: 44
diff changeset
445 global piezo_config ; Sets up piezo sensitivity of heinrichs weikamp Piezo buttons (~30ms)
117
heinrichsweikamp
parents: 113
diff changeset
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
heinrichsweikamp
parents: 466
diff changeset
460
heinrichsweikamp
parents: 466
diff changeset
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
heinrichsweikamp
parents: 113
diff changeset
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
heinrichsweikamp
parents: 203
diff changeset
470 rcall piezo_config_tx
343
34e2f5bdc5a2 BUGFIX: Rotate button sensitivity with screen (OSTC 2 and cR)
heinrichsweikamp
parents: 275
diff changeset
471
468
heinrichsweikamp
parents: 466
diff changeset
472 movlw .20 ; reserved
204
heinrichsweikamp
parents: 203
diff changeset
473 rcall piezo_config_tx
468
heinrichsweikamp
parents: 466
diff changeset
474 movlw .20 ; reserved
204
heinrichsweikamp
parents: 203
diff changeset
475 rcall piezo_config_tx
468
heinrichsweikamp
parents: 466
diff changeset
476 bsf INTCON,GIE
204
heinrichsweikamp
parents: 203
diff changeset
477 return
heinrichsweikamp
parents: 203
diff changeset
478
117
heinrichsweikamp
parents: 113
diff changeset
479 piezo_config_tx: ; Send one byte
113
heinrichsweikamp
parents: 44
diff changeset
480 movwf uart1_temp ; Store byte
heinrichsweikamp
parents: 44
diff changeset
481 movlw .8
heinrichsweikamp
parents: 44
diff changeset
482 movwf uart2_temp ; Bit counter
heinrichsweikamp
parents: 44
diff changeset
483 bcf TX3_PIEZO_CFG ; Startbit
heinrichsweikamp
parents: 44
diff changeset
484 rcall piezo_config_wait_bit
heinrichsweikamp
parents: 44
diff changeset
485 piezo_config_tx_loop:
heinrichsweikamp
parents: 44
diff changeset
486 btfss uart1_temp,0 ; LSB first
heinrichsweikamp
parents: 44
diff changeset
487 bcf TX3_PIEZO_CFG
heinrichsweikamp
parents: 44
diff changeset
488 btfsc uart1_temp,0 ; LSB first
heinrichsweikamp
parents: 44
diff changeset
489 bsf TX3_PIEZO_CFG
heinrichsweikamp
parents: 44
diff changeset
490 rcall piezo_config_wait_bit
heinrichsweikamp
parents: 44
diff changeset
491 rrncf uart1_temp,F
heinrichsweikamp
parents: 44
diff changeset
492 decfsz uart2_temp,F
heinrichsweikamp
parents: 44
diff changeset
493 bra piezo_config_tx_loop
heinrichsweikamp
parents: 44
diff changeset
494 bsf TX3_PIEZO_CFG ; Stopbit
heinrichsweikamp
parents: 44
diff changeset
495 rcall piezo_config_wait_bit
heinrichsweikamp
parents: 44
diff changeset
496 return
heinrichsweikamp
parents: 44
diff changeset
497
heinrichsweikamp
parents: 44
diff changeset
498 piezo_config_wait_bit:
heinrichsweikamp
parents: 44
diff changeset
499 setf TMR5H
heinrichsweikamp
parents: 44
diff changeset
500 movlw .255-.26 ;26 x 31,5µs = 819us
heinrichsweikamp
parents: 44
diff changeset
501 movwf TMR5L
heinrichsweikamp
parents: 44
diff changeset
502 bcf PIR5,TMR5IF ; Clear flag
heinrichsweikamp
parents: 44
diff changeset
503 piezo_config_wait_bit3:
heinrichsweikamp
parents: 44
diff changeset
504 btfss PIR5,TMR5IF
heinrichsweikamp
parents: 44
diff changeset
505 bra piezo_config_wait_bit3 ; Wait loop
heinrichsweikamp
parents: 44
diff changeset
506 return
heinrichsweikamp
parents: 44
diff changeset
507
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
508 global reset_battery_pointer, reset_battery_internal_only
0
heinrichsweikamp
parents:
diff changeset
509 reset_battery_pointer: ; Resets battery pointer 0x07-0x0C and battery_gauge:5
113
heinrichsweikamp
parents: 44
diff changeset
510 extern lt2942_charge_done
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
511 btfsc battery_gauge_available ; Something to reset?
260
e1cd6848863d increase immunity against false Qi data
heinrichsweikamp
parents: 236
diff changeset
512 call lt2942_charge_done ; Yes, reset accumulating registers to 0xFFFF
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
513 reset_battery_internal_only:
113
heinrichsweikamp
parents: 44
diff changeset
514 clrf EEADRH
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
515 clrf EEDATA ; Delete to zero
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
516 write_int_eeprom 0x07
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
517 write_int_eeprom 0x08
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
518 write_int_eeprom 0x09
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
519 write_int_eeprom 0x0A
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
520 write_int_eeprom 0x0B
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
521 write_int_eeprom 0x0C
0
heinrichsweikamp
parents:
diff changeset
522 banksel battery_gauge+0
heinrichsweikamp
parents:
diff changeset
523 clrf battery_gauge+0
heinrichsweikamp
parents:
diff changeset
524 clrf battery_gauge+1
heinrichsweikamp
parents:
diff changeset
525 clrf battery_gauge+2
heinrichsweikamp
parents:
diff changeset
526 clrf battery_gauge+3
heinrichsweikamp
parents:
diff changeset
527 clrf battery_gauge+4
heinrichsweikamp
parents:
diff changeset
528 clrf battery_gauge+5
heinrichsweikamp
parents:
diff changeset
529 banksel common
heinrichsweikamp
parents:
diff changeset
530 movlw .100
heinrichsweikamp
parents:
diff changeset
531 movwf batt_percent
heinrichsweikamp
parents:
diff changeset
532 return
heinrichsweikamp
parents:
diff changeset
533
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
534 global get_analog_switches
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
535 get_analog_switches: ; starts ADC and waits until finished
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
536 btfsc analog_switches
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
537 bra get_analog_switches2
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
538 ; no analog switches
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
539 bcf analog_sw2_pressed
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
540 bcf analog_sw1_pressed
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
541 return ; Done.
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
542 get_analog_switches2:
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
543 btfsc adc_running ; ADC in use?
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
544 return ; Yes, return
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
545
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
546 movlw b'00001001' ; left justified
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
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
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
550 movlw b'00100101' ; power on ADC, select AN9
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
551 rcall wait_adc
474
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
552 banksel analog_counter
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
553 movff ADRESH,WREG
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
554 addwf analog_sw2_raw+0
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
555 movlw .0
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
556 addwfc analog_sw2_raw+1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
557 decfsz analog_counter,F ; continue averaging?
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
558 bra get_analog_switches2a ; Yes
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
559 ; Done. Compute average
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
560 bcf STATUS,C
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
561 rrcf analog_sw2_raw+1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
562 rrcf analog_sw2_raw+0 ; /2
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
563 bcf STATUS,C
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
564 rrcf analog_sw2_raw+1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
565 rrcf analog_sw2_raw+0 ; /4
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
566 bcf STATUS,C
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
567 rrcf analog_sw2_raw+1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
568 rrcf analog_sw2_raw+0 ; /8
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
569 bcf STATUS,C
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
570 rrcf analog_sw2_raw+1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
571 rrcf analog_sw2_raw+0 ; /16
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
572 movff analog_sw2_raw+0, analog_sw2
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
573 clrf analog_sw2_raw+1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
574 clrf analog_sw2_raw+0 ; Reset average registers
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
575 ; movlw .16
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
576 ; movwf analog_counter ; only once...
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
577 get_analog_switches2a:
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
578 banksel common
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
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
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
585 decf WREG,W ;-1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
586 decf WREG,W ;-1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
587 decf WREG,W ;-1 -> 2-22
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
588 banksel analog_sw2
475
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
589 btfss button_polarity,1;(1= normal, 0=inverted)
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
590 bra sw2_inverted
474
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
591 addwf analog_sw2,W ; average (~128)
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
592 cpfsgt ADRESH
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
593 bra get_analog_sw1
475
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
594 banksel common
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
595 bsf analog_sw2_pressed ; Left button normal
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
596 bra get_analog_sw1
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
597 sw2_inverted:
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
598 subwf analog_sw2,W ; average (~128)
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
599 cpfslt ADRESH
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
600 bra get_analog_sw1
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
601 banksel common
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
602 bsf analog_sw2_pressed ; Left button inverted
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
603 get_analog_sw1:
475
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
604 banksel common
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
605 movlw b'00101001' ; power on ADC, select AN10
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
606 rcall wait_adc
474
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
607 banksel analog_counter
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
608 movff ADRESH,WREG
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
609 addwf analog_sw1_raw+0
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
610 movlw .0
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
611 addwfc analog_sw1_raw+1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
612 tstfsz analog_counter ; continue averaging?
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
613 bra get_analog_switches1a ; Yes
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
614 ; Done. Compute average
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
615 bcf STATUS,C
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
616 rrcf analog_sw1_raw+1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
617 rrcf analog_sw1_raw+0 ; /2
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
618 bcf STATUS,C
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
619 rrcf analog_sw1_raw+1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
620 rrcf analog_sw1_raw+0 ; /4
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
621 bcf STATUS,C
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
622 rrcf analog_sw1_raw+1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
623 rrcf analog_sw1_raw+0 ; /8
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
624 bcf STATUS,C
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
625 rrcf analog_sw1_raw+1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
626 rrcf analog_sw1_raw+0 ; /16
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
627 movff analog_sw1_raw+0, analog_sw1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
628 clrf analog_sw1_raw+1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
629 clrf analog_sw1_raw+0 ; Reset average registers
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
630 movlw .16
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
631 movwf analog_counter ; only once...
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
632 get_analog_switches1a:
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
633 banksel common
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
634 bcf analog_sw1_pressed
474
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
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
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
640 decf WREG,W ;-1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
641 decf WREG,W ;-1
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
642 decf WREG,W ;-1 -> 2-22
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
643 banksel analog_sw1
475
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
644 btfss button_polarity,0;(1= normal, 0=inverted)
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
645 bra sw1_inverted
474
2880aa1264f5 Fix new battery menu on Power-on reset
heinrichsweikamp
parents: 472
diff changeset
646 addwf analog_sw1,W ; average (~128)
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
647 cpfsgt ADRESH
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
648 bra get_analog_sw_done
475
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
649 banksel common
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
650 bsf analog_sw1_pressed ; right button normal
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
651 bra get_analog_sw_done
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
652 sw1_inverted:
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
653 subwf analog_sw1,W ; average (~128)
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
654 cpfslt ADRESH
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
655 bra get_analog_sw_done
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
656 banksel common
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
657 bsf analog_sw1_pressed ; right button inverted
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
658 get_analog_sw_done:
475
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
659 banksel common
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
660 movlw b'10001101' ; Restore to right justified
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
661 movwf ADCON2
451
66049b6f2c0b speedup analog presses
heinrichsweikamp
parents: 448
diff changeset
662 btfsc analog_sw1_pressed
66049b6f2c0b speedup analog presses
heinrichsweikamp
parents: 448
diff changeset
663 return
66049b6f2c0b speedup analog presses
heinrichsweikamp
parents: 448
diff changeset
664 btfsc analog_sw2_pressed
66049b6f2c0b speedup analog presses
heinrichsweikamp
parents: 448
diff changeset
665 return
66049b6f2c0b speedup analog presses
heinrichsweikamp
parents: 448
diff changeset
666 setf TMR1H ; No button pressed, enhance timer1 to overflow quickly
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
667 return
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
668
0
heinrichsweikamp
parents:
diff changeset
669 END