annotate src/adc_lightsensor.asm @ 53:2825f1d2262f

NEW: Dynamic Gaslist in OC mode (Divemode, Customview 7)
author heinrichsweikamp
date Sun, 29 Sep 2013 18:53:22 +0200
parents 18fe4e668baa
children f3062a611eef
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
heinrichsweikamp
parents:
diff changeset
11 #include "ostc3.inc"
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"
heinrichsweikamp
parents:
diff changeset
15
heinrichsweikamp
parents:
diff changeset
16 sensors CODE
heinrichsweikamp
parents:
diff changeset
17
heinrichsweikamp
parents:
diff changeset
18 wait_adc:
heinrichsweikamp
parents:
diff changeset
19 movwf ADCON0
heinrichsweikamp
parents:
diff changeset
20 nop
heinrichsweikamp
parents:
diff changeset
21 bsf ADCON0,1 ; start ADC
heinrichsweikamp
parents:
diff changeset
22 wait_adc2:
heinrichsweikamp
parents:
diff changeset
23 btfsc ADCON0,1 ; Wait...
heinrichsweikamp
parents:
diff changeset
24 bra wait_adc2
heinrichsweikamp
parents:
diff changeset
25 return
heinrichsweikamp
parents:
diff changeset
26
heinrichsweikamp
parents:
diff changeset
27 global get_battery_voltage
heinrichsweikamp
parents:
diff changeset
28 get_battery_voltage: ; starts ADC and waits until fnished
heinrichsweikamp
parents:
diff changeset
29 bsf adc_running ; =1: The ADC is in use
heinrichsweikamp
parents:
diff changeset
30 movlw b'00100000' ; 2.048V Vref+ -> 1LSB = 500µV
heinrichsweikamp
parents:
diff changeset
31 movwf ADCON1
heinrichsweikamp
parents:
diff changeset
32 movlw b'00011001' ; power on ADC, select AN6
heinrichsweikamp
parents:
diff changeset
33 rcall wait_adc
heinrichsweikamp
parents:
diff changeset
34
heinrichsweikamp
parents:
diff changeset
35 movff ADRESH,batt_voltage+1 ; store value
heinrichsweikamp
parents:
diff changeset
36 movff ADRESL,batt_voltage+0 ; store value
heinrichsweikamp
parents:
diff changeset
37 bcf ADCON0,0 ; power off ADC
heinrichsweikamp
parents:
diff changeset
38
heinrichsweikamp
parents:
diff changeset
39 ; Multiply with 2,006 to be excact here...
heinrichsweikamp
parents:
diff changeset
40 ; bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
41 ; rlcf xA+0,F
heinrichsweikamp
parents:
diff changeset
42 ;
heinrichsweikamp
parents:
diff changeset
43 ; rlcf xA+1,F ; x2
heinrichsweikamp
parents:
diff changeset
44
heinrichsweikamp
parents:
diff changeset
45 ; movff xA+0,batt_voltage+0 ; store value
heinrichsweikamp
parents:
diff changeset
46 ; movff xA+1,batt_voltage+1
heinrichsweikamp
parents:
diff changeset
47
heinrichsweikamp
parents:
diff changeset
48 movlw LOW lithium_36v_low
heinrichsweikamp
parents:
diff changeset
49 movwf sub_a+0
heinrichsweikamp
parents:
diff changeset
50 movlw HIGH lithium_36v_low
heinrichsweikamp
parents:
diff changeset
51 movwf sub_a+1
heinrichsweikamp
parents:
diff changeset
52 movff batt_voltage+0,sub_b+0
heinrichsweikamp
parents:
diff changeset
53 movff batt_voltage+1,sub_b+1
heinrichsweikamp
parents:
diff changeset
54 call subU16 ; sub_c = sub_a - sub_b
heinrichsweikamp
parents:
diff changeset
55 ; Battery is 3,6V (>lithium_36v_low?)
heinrichsweikamp
parents:
diff changeset
56 btfss neg_flag
heinrichsweikamp
parents:
diff changeset
57 bra get_battery_voltage4 ; No, use 1,5V
heinrichsweikamp
parents:
diff changeset
58
heinrichsweikamp
parents:
diff changeset
59 bsf battery_is_36v ; Yes, set flag (Cleared in power-on reset only!)
heinrichsweikamp
parents:
diff changeset
60
heinrichsweikamp
parents:
diff changeset
61 ; Check if the battery is near-dead already
heinrichsweikamp
parents:
diff changeset
62 movlw LOW lithium_36v_empty
heinrichsweikamp
parents:
diff changeset
63 movwf sub_a+0
heinrichsweikamp
parents:
diff changeset
64 movlw HIGH lithium_36v_empty
heinrichsweikamp
parents:
diff changeset
65 movwf sub_a+1
heinrichsweikamp
parents:
diff changeset
66 call subU16 ; sub_c = sub_a - sub_b
heinrichsweikamp
parents:
diff changeset
67 ; Battery is not dead yet (>lithium_36v_empty?)
heinrichsweikamp
parents:
diff changeset
68 btfsc neg_flag
heinrichsweikamp
parents:
diff changeset
69 bra get_battery_voltage2 ; Yes, battery is still ok
heinrichsweikamp
parents:
diff changeset
70
heinrichsweikamp
parents:
diff changeset
71 ; Battery is probably dead very soon
heinrichsweikamp
parents:
diff changeset
72 ; Set ">=24Ah used" into battery gauge registers
heinrichsweikamp
parents:
diff changeset
73 movlw .128
heinrichsweikamp
parents:
diff changeset
74 movff WREG,battery_gauge+5
heinrichsweikamp
parents:
diff changeset
75
heinrichsweikamp
parents:
diff changeset
76 get_battery_voltage2:
heinrichsweikamp
parents:
diff changeset
77 ; Use 3,6V battery gauging mode
heinrichsweikamp
parents:
diff changeset
78 movff battery_gauge+5,xC+3
heinrichsweikamp
parents:
diff changeset
79 movff battery_gauge+4,xC+2
heinrichsweikamp
parents:
diff changeset
80 movff battery_gauge+3,xC+1
heinrichsweikamp
parents:
diff changeset
81 movff battery_gauge+2,xC+0
heinrichsweikamp
parents:
diff changeset
82 ; battery_gauge:6 is nAs
heinrichsweikamp
parents:
diff changeset
83 ; devide through 65536
heinrichsweikamp
parents:
diff changeset
84 ; devide through 364
heinrichsweikamp
parents:
diff changeset
85 ; Result is in percent of a 2,4Ah Battery
heinrichsweikamp
parents:
diff changeset
86 movlw LOW .364
heinrichsweikamp
parents:
diff changeset
87 movwf xB+0
heinrichsweikamp
parents:
diff changeset
88 movlw HIGH .364
heinrichsweikamp
parents:
diff changeset
89 movwf xB+1
heinrichsweikamp
parents:
diff changeset
90 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
91 movff xC+0,lo
heinrichsweikamp
parents:
diff changeset
92 ; Limit to 100
heinrichsweikamp
parents:
diff changeset
93 movlw .100
heinrichsweikamp
parents:
diff changeset
94 cpfslt lo
heinrichsweikamp
parents:
diff changeset
95 movwf lo
heinrichsweikamp
parents:
diff changeset
96 ; lo will be between 0 (Full) and 100 (empty)
heinrichsweikamp
parents:
diff changeset
97 movf lo,W
heinrichsweikamp
parents:
diff changeset
98 sublw .100
heinrichsweikamp
parents:
diff changeset
99 movwf lo
heinrichsweikamp
parents:
diff changeset
100 get_battery_voltage3:
heinrichsweikamp
parents:
diff changeset
101 movlw .100
heinrichsweikamp
parents:
diff changeset
102 cpfslt lo
heinrichsweikamp
parents:
diff changeset
103 movwf lo
heinrichsweikamp
parents:
diff changeset
104 ; 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
105
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
106 ; 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
107 ; 75%
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
108 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
109 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
110 movlw LOW lithium_36v_75
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
111 movwf sub_a+0
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
112 movlw HIGH lithium_36v_75
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
113 movwf sub_a+1
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
114 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
115 btfsc neg_flag
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
116 bra get_battery_voltage3a
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
117 movlw .75
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
118 movwf lo
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
119 get_battery_voltage3a:
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
120 ; 50%
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
121 movlw LOW lithium_36v_50
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
122 movwf sub_a+0
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
123 movlw HIGH lithium_36v_50
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
124 movwf sub_a+1
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
125 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
126 btfsc neg_flag
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
127 bra get_battery_voltage3b
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
128 movlw .50
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
129 movwf lo
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
130 get_battery_voltage3b:
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
131 ; 25%
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
132 movlw LOW lithium_36v_25
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
133 movwf sub_a+0
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
134 movlw HIGH lithium_36v_25
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
135 movwf sub_a+1
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
136 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
137 btfsc neg_flag
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
138 bra get_battery_voltage3c
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
139 movlw .25
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
140 movwf lo
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
141 get_battery_voltage3c:
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
142 ; 10%
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
143 movlw LOW lithium_36v_10
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
144 movwf sub_a+0
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
145 movlw HIGH lithium_36v_10
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
146 movwf sub_a+1
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
147 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
148 btfsc neg_flag
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
149 bra get_battery_voltage3d
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
150 movlw .10
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
151 movwf lo
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
152 get_battery_voltage3d:
44
18fe4e668baa BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents: 37
diff changeset
153 movlw .100
18fe4e668baa BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents: 37
diff changeset
154 cpfslt lo
18fe4e668baa BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents: 37
diff changeset
155 movwf lo
18fe4e668baa BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents: 37
diff changeset
156 ; lo will be between 100 (Full) and 0 (empty)
0
heinrichsweikamp
parents:
diff changeset
157 movf batt_percent,W
heinrichsweikamp
parents:
diff changeset
158 cpfsgt lo ; keep batt_percent on the lowest value found
heinrichsweikamp
parents:
diff changeset
159 movff lo,batt_percent ; store value
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
160 ; btfsc battery_is_36v ; but always use computed value for 3,6V battery
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
161 ; movff lo,batt_percent ; store value
0
heinrichsweikamp
parents:
diff changeset
162 bcf adc_running ; =1: The ADC is in use
heinrichsweikamp
parents:
diff changeset
163 return
heinrichsweikamp
parents:
diff changeset
164
heinrichsweikamp
parents:
diff changeset
165 get_battery_voltage4:
heinrichsweikamp
parents:
diff changeset
166 ; Use 1,5V battery voltage mode
heinrichsweikamp
parents:
diff changeset
167 ; Use approximation (batt_voltage:2-aa_15v_low)/4 = lo
heinrichsweikamp
parents:
diff changeset
168 movff batt_voltage+0,sub_a+0
heinrichsweikamp
parents:
diff changeset
169 movff batt_voltage+1,sub_a+1
heinrichsweikamp
parents:
diff changeset
170 movlw LOW aa_15v_low
heinrichsweikamp
parents:
diff changeset
171 movwf sub_b+0
heinrichsweikamp
parents:
diff changeset
172 movlw HIGH aa_15v_low
heinrichsweikamp
parents:
diff changeset
173 movwf sub_b+1
heinrichsweikamp
parents:
diff changeset
174 call subU16 ; sub_c = sub_a - sub_b
heinrichsweikamp
parents:
diff changeset
175 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
176 rrcf sub_c+1
heinrichsweikamp
parents:
diff changeset
177 rrcf sub_c+0 ; /2
heinrichsweikamp
parents:
diff changeset
178 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
179 rrcf sub_c+1
heinrichsweikamp
parents:
diff changeset
180 rrcf sub_c+0 ; /4
heinrichsweikamp
parents:
diff changeset
181 movff sub_c+0,lo
44
18fe4e668baa BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents: 37
diff changeset
182 bra get_battery_voltage3d ; Check limits and return
0
heinrichsweikamp
parents:
diff changeset
183
heinrichsweikamp
parents:
diff changeset
184 global get_ambient_level
heinrichsweikamp
parents:
diff changeset
185 get_ambient_level: ; starts ADC and waits until finished
heinrichsweikamp
parents:
diff changeset
186 btfsc adc_running ; ADC in use?
heinrichsweikamp
parents:
diff changeset
187 return ; Yes, return
heinrichsweikamp
parents:
diff changeset
188
heinrichsweikamp
parents:
diff changeset
189 movlw b'00000000' ; Vref+ = Vdd
heinrichsweikamp
parents:
diff changeset
190 movwf ADCON1
heinrichsweikamp
parents:
diff changeset
191 movlw b'00011101' ; power on ADC, select AN7
heinrichsweikamp
parents:
diff changeset
192 rcall wait_adc
heinrichsweikamp
parents:
diff changeset
193
heinrichsweikamp
parents:
diff changeset
194 movff ADRESH,ambient_light+1
heinrichsweikamp
parents:
diff changeset
195 movff ADRESL,ambient_light+0
heinrichsweikamp
parents:
diff changeset
196 bcf ADCON0,0 ; power off ADC
heinrichsweikamp
parents:
diff changeset
197
heinrichsweikamp
parents:
diff changeset
198 ; ambient_light:2 is between 4096 (direct sunlight) and about 200 (darkness)
heinrichsweikamp
parents:
diff changeset
199 ; First: Devide through 16
heinrichsweikamp
parents:
diff changeset
200 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
201 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
202 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
203 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
204 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
205 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
206 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
207 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
208 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
209 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
210 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
211 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
212 ; Result: ambient_light:2/16
heinrichsweikamp
parents:
diff changeset
213 ; Now, make sure to have value between ambient_light_low and ambient_light_max
heinrichsweikamp
parents:
diff changeset
214
heinrichsweikamp
parents:
diff changeset
215 movlw .254
heinrichsweikamp
parents:
diff changeset
216 tstfsz ambient_light+1 ; >255?
heinrichsweikamp
parents:
diff changeset
217 movwf ambient_light+0 ; avoid ADC clipping
heinrichsweikamp
parents:
diff changeset
218
heinrichsweikamp
parents:
diff changeset
219 incfsz ambient_light+0,W ; =255?
heinrichsweikamp
parents:
diff changeset
220 bra get_ambient_level2 ; No, continue
heinrichsweikamp
parents:
diff changeset
221
heinrichsweikamp
parents:
diff changeset
222 movlw .254
heinrichsweikamp
parents:
diff changeset
223 movwf ambient_light+0 ; avoid ADC clipping
heinrichsweikamp
parents:
diff changeset
224
heinrichsweikamp
parents:
diff changeset
225 get_ambient_level2:
heinrichsweikamp
parents:
diff changeset
226 banksel isr_backup ; Back to Bank0 ISR data
heinrichsweikamp
parents:
diff changeset
227 movff opt_brightness,isr1_temp
heinrichsweikamp
parents:
diff changeset
228
heinrichsweikamp
parents:
diff changeset
229 btfsc RCSTA1,7 ; UART module on?
heinrichsweikamp
parents:
diff changeset
230 clrf isr1_temp ; Yes, set temporally to eco mode
heinrichsweikamp
parents:
diff changeset
231
heinrichsweikamp
parents:
diff changeset
232 incf isr1_temp,F ; adjust 0-2 to 1-3
heinrichsweikamp
parents:
diff changeset
233
heinrichsweikamp
parents:
diff changeset
234 banksel common ; flag is in bank1
heinrichsweikamp
parents:
diff changeset
235 movlw ambient_light_max_high ; brightest setting
heinrichsweikamp
parents:
diff changeset
236 btfsc battery_is_36v ; 3,6V battery in use?
heinrichsweikamp
parents:
diff changeset
237 movlw ambient_light_max_high_36V ; Yes...
heinrichsweikamp
parents:
diff changeset
238 banksel isr_backup ; Back to Bank0 ISR data
heinrichsweikamp
parents:
diff changeset
239
heinrichsweikamp
parents:
diff changeset
240 dcfsnz isr1_temp,F
heinrichsweikamp
parents:
diff changeset
241 movlw ambient_light_max_eco ; brightest setting
heinrichsweikamp
parents:
diff changeset
242 dcfsnz isr1_temp,F
heinrichsweikamp
parents:
diff changeset
243 movlw ambient_light_max_medium; brightest setting
heinrichsweikamp
parents:
diff changeset
244
heinrichsweikamp
parents:
diff changeset
245 banksel common ; ambient_light is in Bank1
heinrichsweikamp
parents:
diff changeset
246 incf ambient_light+0,F ; +1
heinrichsweikamp
parents:
diff changeset
247 cpfslt ambient_light+0 ; smaller then WREG?
heinrichsweikamp
parents:
diff changeset
248 movwf ambient_light+0 ; No, set to max.
heinrichsweikamp
parents:
diff changeset
249
heinrichsweikamp
parents:
diff changeset
250 banksel isr_backup ; Back to Bank0 ISR data
heinrichsweikamp
parents:
diff changeset
251 movff opt_brightness,isr1_temp
heinrichsweikamp
parents:
diff changeset
252 incf isr1_temp,F ; adjust 0-2 to 1-3
heinrichsweikamp
parents:
diff changeset
253 movlw ambient_light_min_high ; darkest setting
heinrichsweikamp
parents:
diff changeset
254
heinrichsweikamp
parents:
diff changeset
255 dcfsnz isr1_temp,F
heinrichsweikamp
parents:
diff changeset
256 movlw ambient_light_min_eco ; darkest setting
heinrichsweikamp
parents:
diff changeset
257 dcfsnz isr1_temp,F
heinrichsweikamp
parents:
diff changeset
258 movlw ambient_light_min_medium; darkest setting
heinrichsweikamp
parents:
diff changeset
259 dcfsnz isr1_temp,F
heinrichsweikamp
parents:
diff changeset
260 movlw ambient_light_min_high ; darkest setting
heinrichsweikamp
parents:
diff changeset
261
heinrichsweikamp
parents:
diff changeset
262 banksel common ; ambient_light is in Bank1
heinrichsweikamp
parents:
diff changeset
263 cpfsgt ambient_light+0 ; bigger then WREG?
heinrichsweikamp
parents:
diff changeset
264 movwf ambient_light+0 ; No, set to min
heinrichsweikamp
parents:
diff changeset
265
heinrichsweikamp
parents:
diff changeset
266 movff ambient_light+0,max_CCPR1L ; Store value for dimming in TMR7 interrupt
heinrichsweikamp
parents:
diff changeset
267 return
heinrichsweikamp
parents:
diff changeset
268
heinrichsweikamp
parents:
diff changeset
269 global get_rssi_level
heinrichsweikamp
parents:
diff changeset
270 get_rssi_level: ; starts ADC and waits until fnished
heinrichsweikamp
parents:
diff changeset
271 bsf adc_running ; =1: The ADC is in use
heinrichsweikamp
parents:
diff changeset
272 movlw b'00100000' ; 2.048V Vref+
heinrichsweikamp
parents:
diff changeset
273 movwf ADCON1
heinrichsweikamp
parents:
diff changeset
274 movlw b'01000101' ; power on ADC, select AN17
heinrichsweikamp
parents:
diff changeset
275 rcall wait_adc
heinrichsweikamp
parents:
diff changeset
276
heinrichsweikamp
parents:
diff changeset
277 movff ADRESL,rssi_value
heinrichsweikamp
parents:
diff changeset
278 bcf ADCON0,0 ; power off ADC
heinrichsweikamp
parents:
diff changeset
279 bcf adc_running ; =1: The ADC is in use
heinrichsweikamp
parents:
diff changeset
280 return
heinrichsweikamp
parents:
diff changeset
281
heinrichsweikamp
parents:
diff changeset
282 global reset_battery_pointer
heinrichsweikamp
parents:
diff changeset
283 reset_battery_pointer: ; Resets battery pointer 0x07-0x0C and battery_gauge:5
heinrichsweikamp
parents:
diff changeset
284 clrf EEADRH
heinrichsweikamp
parents:
diff changeset
285 clrf EEDATA ; Delete to zero
heinrichsweikamp
parents:
diff changeset
286 write_int_eeprom 0x07
heinrichsweikamp
parents:
diff changeset
287 write_int_eeprom 0x08
heinrichsweikamp
parents:
diff changeset
288 write_int_eeprom 0x09
heinrichsweikamp
parents:
diff changeset
289 write_int_eeprom 0x0A
heinrichsweikamp
parents:
diff changeset
290 write_int_eeprom 0x0B
heinrichsweikamp
parents:
diff changeset
291 write_int_eeprom 0x0C
heinrichsweikamp
parents:
diff changeset
292 banksel battery_gauge+0
heinrichsweikamp
parents:
diff changeset
293 clrf battery_gauge+0
heinrichsweikamp
parents:
diff changeset
294 clrf battery_gauge+1
heinrichsweikamp
parents:
diff changeset
295 clrf battery_gauge+2
heinrichsweikamp
parents:
diff changeset
296 clrf battery_gauge+3
heinrichsweikamp
parents:
diff changeset
297 clrf battery_gauge+4
heinrichsweikamp
parents:
diff changeset
298 clrf battery_gauge+5
heinrichsweikamp
parents:
diff changeset
299 banksel common
heinrichsweikamp
parents:
diff changeset
300 movlw .100
heinrichsweikamp
parents:
diff changeset
301 movwf batt_percent
heinrichsweikamp
parents:
diff changeset
302 return
heinrichsweikamp
parents:
diff changeset
303
heinrichsweikamp
parents:
diff changeset
304
heinrichsweikamp
parents:
diff changeset
305 END