annotate src/adc_lightsensor.asm @ 205:618191753d2b

Preparations for 1.7
author heinrichsweikamp
date Wed, 26 Nov 2014 14:30:25 +0100
parents 93085f540746
children f5d909e03f52
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"
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
200
dcd513840c6c cleanup
heinrichsweikamp
parents: 196
diff changeset
30 btfss cr_hardware
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
120
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
35 bcf LEDr
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
36 bcf TRISJ,2 ; Chrg-Out output
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
37 bsf CHRG_OUT
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
38
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
39 btfss CHRG_IN
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
40 bra cc_active
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
41
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
42 bcf CHRG_OUT
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
43 bsf TRISJ,2 ; Chrg-Out high impedance
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
44
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
45 WAITMS d'1'
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
46
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
47 btfsc CHRG_IN
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
48 return
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
49 ;cv_active:
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
50 bsf LEDr ; Indicate charging
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
51 call lt2942_charge_done ; Reset accumulating registers to 0xFFFF
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
52 WAITMS d'10'
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
53 bcf LEDr ; Indicate charging
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
54 return
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
55
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
56 cc_active:
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
57 bsf LEDr ; Indicate charging
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
58 bcf CHRG_OUT
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
59 bsf TRISJ,2 ; Chrg-Out high impedance
113
heinrichsweikamp
parents: 44
diff changeset
60 return
heinrichsweikamp
parents: 44
diff changeset
61
heinrichsweikamp
parents: 44
diff changeset
62 get_battery_voltage1:
0
heinrichsweikamp
parents:
diff changeset
63 bsf adc_running ; =1: The ADC is in use
heinrichsweikamp
parents:
diff changeset
64 movlw b'00100000' ; 2.048V Vref+ -> 1LSB = 500µV
heinrichsweikamp
parents:
diff changeset
65 movwf ADCON1
heinrichsweikamp
parents:
diff changeset
66 movlw b'00011001' ; power on ADC, select AN6
heinrichsweikamp
parents:
diff changeset
67 rcall wait_adc
heinrichsweikamp
parents:
diff changeset
68
heinrichsweikamp
parents:
diff changeset
69 movff ADRESH,batt_voltage+1 ; store value
heinrichsweikamp
parents:
diff changeset
70 movff ADRESL,batt_voltage+0 ; store value
heinrichsweikamp
parents:
diff changeset
71 bcf ADCON0,0 ; power off ADC
heinrichsweikamp
parents:
diff changeset
72
heinrichsweikamp
parents:
diff changeset
73 ; Multiply with 2,006 to be excact here...
heinrichsweikamp
parents:
diff changeset
74 ; bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
75 ; rlcf xA+0,F
heinrichsweikamp
parents:
diff changeset
76 ;
heinrichsweikamp
parents:
diff changeset
77 ; rlcf xA+1,F ; x2
heinrichsweikamp
parents:
diff changeset
78
heinrichsweikamp
parents:
diff changeset
79 ; movff xA+0,batt_voltage+0 ; store value
heinrichsweikamp
parents:
diff changeset
80 ; movff xA+1,batt_voltage+1
heinrichsweikamp
parents:
diff changeset
81
heinrichsweikamp
parents:
diff changeset
82 movlw LOW lithium_36v_low
heinrichsweikamp
parents:
diff changeset
83 movwf sub_a+0
heinrichsweikamp
parents:
diff changeset
84 movlw HIGH lithium_36v_low
heinrichsweikamp
parents:
diff changeset
85 movwf sub_a+1
heinrichsweikamp
parents:
diff changeset
86 movff batt_voltage+0,sub_b+0
heinrichsweikamp
parents:
diff changeset
87 movff batt_voltage+1,sub_b+1
heinrichsweikamp
parents:
diff changeset
88 call subU16 ; sub_c = sub_a - sub_b
heinrichsweikamp
parents:
diff changeset
89 ; Battery is 3,6V (>lithium_36v_low?)
heinrichsweikamp
parents:
diff changeset
90 btfss neg_flag
heinrichsweikamp
parents:
diff changeset
91 bra get_battery_voltage4 ; No, use 1,5V
heinrichsweikamp
parents:
diff changeset
92
heinrichsweikamp
parents:
diff changeset
93 bsf battery_is_36v ; Yes, set flag (Cleared in power-on reset only!)
heinrichsweikamp
parents:
diff changeset
94
heinrichsweikamp
parents:
diff changeset
95 ; Check if the battery is near-dead already
heinrichsweikamp
parents:
diff changeset
96 movlw LOW lithium_36v_empty
heinrichsweikamp
parents:
diff changeset
97 movwf sub_a+0
heinrichsweikamp
parents:
diff changeset
98 movlw HIGH lithium_36v_empty
heinrichsweikamp
parents:
diff changeset
99 movwf sub_a+1
heinrichsweikamp
parents:
diff changeset
100 call subU16 ; sub_c = sub_a - sub_b
heinrichsweikamp
parents:
diff changeset
101 ; Battery is not dead yet (>lithium_36v_empty?)
heinrichsweikamp
parents:
diff changeset
102 btfsc neg_flag
heinrichsweikamp
parents:
diff changeset
103 bra get_battery_voltage2 ; Yes, battery is still ok
heinrichsweikamp
parents:
diff changeset
104
heinrichsweikamp
parents:
diff changeset
105 ; Battery is probably dead very soon
heinrichsweikamp
parents:
diff changeset
106 ; Set ">=24Ah used" into battery gauge registers
heinrichsweikamp
parents:
diff changeset
107 movlw .128
heinrichsweikamp
parents:
diff changeset
108 movff WREG,battery_gauge+5
heinrichsweikamp
parents:
diff changeset
109
heinrichsweikamp
parents:
diff changeset
110 get_battery_voltage2:
heinrichsweikamp
parents:
diff changeset
111 ; Use 3,6V battery gauging mode
heinrichsweikamp
parents:
diff changeset
112 movff battery_gauge+5,xC+3
heinrichsweikamp
parents:
diff changeset
113 movff battery_gauge+4,xC+2
heinrichsweikamp
parents:
diff changeset
114 movff battery_gauge+3,xC+1
heinrichsweikamp
parents:
diff changeset
115 movff battery_gauge+2,xC+0
heinrichsweikamp
parents:
diff changeset
116 ; battery_gauge:6 is nAs
heinrichsweikamp
parents:
diff changeset
117 ; devide through 65536
heinrichsweikamp
parents:
diff changeset
118 ; devide through 364
heinrichsweikamp
parents:
diff changeset
119 ; Result is in percent of a 2,4Ah Battery
heinrichsweikamp
parents:
diff changeset
120 movlw LOW .364
heinrichsweikamp
parents:
diff changeset
121 movwf xB+0
heinrichsweikamp
parents:
diff changeset
122 movlw HIGH .364
heinrichsweikamp
parents:
diff changeset
123 movwf xB+1
heinrichsweikamp
parents:
diff changeset
124 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
125 movff xC+0,lo
heinrichsweikamp
parents:
diff changeset
126 ; Limit to 100
heinrichsweikamp
parents:
diff changeset
127 movlw .100
heinrichsweikamp
parents:
diff changeset
128 cpfslt lo
heinrichsweikamp
parents:
diff changeset
129 movwf lo
heinrichsweikamp
parents:
diff changeset
130 ; lo will be between 0 (Full) and 100 (empty)
heinrichsweikamp
parents:
diff changeset
131 movf lo,W
heinrichsweikamp
parents:
diff changeset
132 sublw .100
heinrichsweikamp
parents:
diff changeset
133 movwf lo
heinrichsweikamp
parents:
diff changeset
134 get_battery_voltage3:
heinrichsweikamp
parents:
diff changeset
135 movlw .100
heinrichsweikamp
parents:
diff changeset
136 cpfslt lo
heinrichsweikamp
parents:
diff changeset
137 movwf lo
heinrichsweikamp
parents:
diff changeset
138 ; 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
139
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
140 ; 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
141 ; 75%
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
142 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
143 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
144 movlw LOW lithium_36v_75
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
145 movwf sub_a+0
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
146 movlw HIGH lithium_36v_75
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
147 movwf sub_a+1
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
148 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
149 btfsc neg_flag
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
150 bra get_battery_voltage3a
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
151 movlw .75
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
152 movwf lo
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
153 get_battery_voltage3a:
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
154 ; 50%
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
155 movlw LOW lithium_36v_50
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
156 movwf sub_a+0
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
157 movlw HIGH lithium_36v_50
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
158 movwf sub_a+1
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
159 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
160 btfsc neg_flag
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
161 bra get_battery_voltage3b
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
162 movlw .50
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
163 movwf lo
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
164 get_battery_voltage3b:
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
165 ; 25%
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
166 movlw LOW lithium_36v_25
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
167 movwf sub_a+0
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
168 movlw HIGH lithium_36v_25
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
169 movwf sub_a+1
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
170 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
171 btfsc neg_flag
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
172 bra get_battery_voltage3c
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
173 movlw .25
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
174 movwf lo
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
175 get_battery_voltage3c:
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
176 ; 10%
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
177 movlw LOW lithium_36v_10
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
178 movwf sub_a+0
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
179 movlw HIGH lithium_36v_10
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
180 movwf sub_a+1
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
181 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
182 btfsc neg_flag
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
183 bra get_battery_voltage3d
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
184 movlw .10
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
185 movwf lo
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
186 get_battery_voltage3d:
44
18fe4e668baa BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents: 37
diff changeset
187 movlw .100
18fe4e668baa BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents: 37
diff changeset
188 cpfslt lo
18fe4e668baa BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents: 37
diff changeset
189 movwf lo
18fe4e668baa BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents: 37
diff changeset
190 ; lo will be between 100 (Full) and 0 (empty)
0
heinrichsweikamp
parents:
diff changeset
191 movf batt_percent,W
heinrichsweikamp
parents:
diff changeset
192 cpfsgt lo ; keep batt_percent on the lowest value found
heinrichsweikamp
parents:
diff changeset
193 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
194 ; 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
195 ; movff lo,batt_percent ; store value
0
heinrichsweikamp
parents:
diff changeset
196 bcf adc_running ; =1: The ADC is in use
heinrichsweikamp
parents:
diff changeset
197 return
heinrichsweikamp
parents:
diff changeset
198
heinrichsweikamp
parents:
diff changeset
199 get_battery_voltage4:
heinrichsweikamp
parents:
diff changeset
200 ; Use 1,5V battery voltage mode
heinrichsweikamp
parents:
diff changeset
201 ; Use approximation (batt_voltage:2-aa_15v_low)/4 = lo
heinrichsweikamp
parents:
diff changeset
202 movff batt_voltage+0,sub_a+0
heinrichsweikamp
parents:
diff changeset
203 movff batt_voltage+1,sub_a+1
heinrichsweikamp
parents:
diff changeset
204 movlw LOW aa_15v_low
heinrichsweikamp
parents:
diff changeset
205 movwf sub_b+0
heinrichsweikamp
parents:
diff changeset
206 movlw HIGH aa_15v_low
heinrichsweikamp
parents:
diff changeset
207 movwf sub_b+1
heinrichsweikamp
parents:
diff changeset
208 call subU16 ; sub_c = sub_a - sub_b
heinrichsweikamp
parents:
diff changeset
209 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
210 rrcf sub_c+1
heinrichsweikamp
parents:
diff changeset
211 rrcf sub_c+0 ; /2
heinrichsweikamp
parents:
diff changeset
212 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
213 rrcf sub_c+1
heinrichsweikamp
parents:
diff changeset
214 rrcf sub_c+0 ; /4
heinrichsweikamp
parents:
diff changeset
215 movff sub_c+0,lo
44
18fe4e668baa BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents: 37
diff changeset
216 bra get_battery_voltage3d ; Check limits and return
0
heinrichsweikamp
parents:
diff changeset
217
heinrichsweikamp
parents:
diff changeset
218 global get_ambient_level
heinrichsweikamp
parents:
diff changeset
219 get_ambient_level: ; starts ADC and waits until finished
heinrichsweikamp
parents:
diff changeset
220 btfsc adc_running ; ADC in use?
heinrichsweikamp
parents:
diff changeset
221 return ; Yes, return
heinrichsweikamp
parents:
diff changeset
222
200
dcd513840c6c cleanup
heinrichsweikamp
parents: 196
diff changeset
223 btfss cr_hardware
113
heinrichsweikamp
parents: 44
diff changeset
224 bra get_ambient_level1 ; Normal ostc3 hardware
203
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
225
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
226 banksel isr_backup ; Back to Bank0 ISR data
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
227 movff opt_brightness,isr1_temp
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
228 incf isr1_temp,F ; adjust 0-2 to 1-3
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
229 movlw ambient_light_max_high_cr; cR hardware brightest setting
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
230 dcfsnz isr1_temp,F
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
231 movlw ambient_light_max_eco ; brightest setting
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
232 dcfsnz isr1_temp,F
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
233 movlw ambient_light_max_medium; brightest setting
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
234
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
235 movff WREG,ambient_light+0 ; Set to max.
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
236 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
237 return
113
heinrichsweikamp
parents: 44
diff changeset
238
heinrichsweikamp
parents: 44
diff changeset
239 get_ambient_level1:
0
heinrichsweikamp
parents:
diff changeset
240 movlw b'00000000' ; Vref+ = Vdd
heinrichsweikamp
parents:
diff changeset
241 movwf ADCON1
heinrichsweikamp
parents:
diff changeset
242 movlw b'00011101' ; power on ADC, select AN7
heinrichsweikamp
parents:
diff changeset
243 rcall wait_adc
heinrichsweikamp
parents:
diff changeset
244
heinrichsweikamp
parents:
diff changeset
245 movff ADRESH,ambient_light+1
heinrichsweikamp
parents:
diff changeset
246 movff ADRESL,ambient_light+0
heinrichsweikamp
parents:
diff changeset
247 bcf ADCON0,0 ; power off ADC
heinrichsweikamp
parents:
diff changeset
248
heinrichsweikamp
parents:
diff changeset
249 ; ambient_light:2 is between 4096 (direct sunlight) and about 200 (darkness)
heinrichsweikamp
parents:
diff changeset
250 ; First: Devide through 16
heinrichsweikamp
parents:
diff changeset
251 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
252 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
253 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
254 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
255 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
256 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
257 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
258 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
259 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
260 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
261 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
262 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
263 ; Result: ambient_light:2/16
heinrichsweikamp
parents:
diff changeset
264 ; Now, make sure to have value between ambient_light_low and ambient_light_max
heinrichsweikamp
parents:
diff changeset
265
heinrichsweikamp
parents:
diff changeset
266 movlw .254
heinrichsweikamp
parents:
diff changeset
267 tstfsz ambient_light+1 ; >255?
heinrichsweikamp
parents:
diff changeset
268 movwf ambient_light+0 ; avoid ADC clipping
heinrichsweikamp
parents:
diff changeset
269
heinrichsweikamp
parents:
diff changeset
270 incfsz ambient_light+0,W ; =255?
heinrichsweikamp
parents:
diff changeset
271 bra get_ambient_level2 ; No, continue
heinrichsweikamp
parents:
diff changeset
272
heinrichsweikamp
parents:
diff changeset
273 movlw .254
heinrichsweikamp
parents:
diff changeset
274 movwf ambient_light+0 ; avoid ADC clipping
heinrichsweikamp
parents:
diff changeset
275
heinrichsweikamp
parents:
diff changeset
276 get_ambient_level2:
201
82faedf8fd58 lower minimum backlight in eco mode
heinrichsweikamp
parents: 200
diff changeset
277 movlw .10
82faedf8fd58 lower minimum backlight in eco mode
heinrichsweikamp
parents: 200
diff changeset
278 subwf ambient_light+0,F ; Subtract 10 (ADC Offset)
82faedf8fd58 lower minimum backlight in eco mode
heinrichsweikamp
parents: 200
diff changeset
279 btfsc STATUS,N
82faedf8fd58 lower minimum backlight in eco mode
heinrichsweikamp
parents: 200
diff changeset
280 movwf ambient_light+0 ; avoid clipping
82faedf8fd58 lower minimum backlight in eco mode
heinrichsweikamp
parents: 200
diff changeset
281
0
heinrichsweikamp
parents:
diff changeset
282 banksel isr_backup ; Back to Bank0 ISR data
heinrichsweikamp
parents:
diff changeset
283 movff opt_brightness,isr1_temp
heinrichsweikamp
parents:
diff changeset
284
heinrichsweikamp
parents:
diff changeset
285 btfsc RCSTA1,7 ; UART module on?
heinrichsweikamp
parents:
diff changeset
286 clrf isr1_temp ; Yes, set temporally to eco mode
heinrichsweikamp
parents:
diff changeset
287
heinrichsweikamp
parents:
diff changeset
288 incf isr1_temp,F ; adjust 0-2 to 1-3
heinrichsweikamp
parents:
diff changeset
289
heinrichsweikamp
parents:
diff changeset
290 banksel common ; flag is in bank1
200
dcd513840c6c cleanup
heinrichsweikamp
parents: 196
diff changeset
291 movlw ambient_light_max_high_cr; cR hardware brightest setting
dcd513840c6c cleanup
heinrichsweikamp
parents: 196
diff changeset
292 btfss cr_hardware
136
9a637c9bb19a rename Deco Planner to Simulator
heinrichsweikamp
parents: 120
diff changeset
293 movlw ambient_light_max_high_15V; 1,5V battery brightest setting
9a637c9bb19a rename Deco Planner to Simulator
heinrichsweikamp
parents: 120
diff changeset
294 btfsc battery_is_36v ; 3,6V battery in use?
9a637c9bb19a rename Deco Planner to Simulator
heinrichsweikamp
parents: 120
diff changeset
295 movlw ambient_light_max_high_36V ; 3,6V battery brightest setting
0
heinrichsweikamp
parents:
diff changeset
296 banksel isr_backup ; Back to Bank0 ISR data
heinrichsweikamp
parents:
diff changeset
297
heinrichsweikamp
parents:
diff changeset
298 dcfsnz isr1_temp,F
heinrichsweikamp
parents:
diff changeset
299 movlw ambient_light_max_eco ; brightest setting
heinrichsweikamp
parents:
diff changeset
300 dcfsnz isr1_temp,F
heinrichsweikamp
parents:
diff changeset
301 movlw ambient_light_max_medium; brightest setting
heinrichsweikamp
parents:
diff changeset
302
heinrichsweikamp
parents:
diff changeset
303 banksel common ; ambient_light is in Bank1
heinrichsweikamp
parents:
diff changeset
304 incf ambient_light+0,F ; +1
heinrichsweikamp
parents:
diff changeset
305 cpfslt ambient_light+0 ; smaller then WREG?
heinrichsweikamp
parents:
diff changeset
306 movwf ambient_light+0 ; No, set to max.
heinrichsweikamp
parents:
diff changeset
307
heinrichsweikamp
parents:
diff changeset
308 banksel isr_backup ; Back to Bank0 ISR data
heinrichsweikamp
parents:
diff changeset
309 movff opt_brightness,isr1_temp
heinrichsweikamp
parents:
diff changeset
310 incf isr1_temp,F ; adjust 0-2 to 1-3
heinrichsweikamp
parents:
diff changeset
311 movlw ambient_light_min_high ; darkest setting
heinrichsweikamp
parents:
diff changeset
312
heinrichsweikamp
parents:
diff changeset
313 dcfsnz isr1_temp,F
heinrichsweikamp
parents:
diff changeset
314 movlw ambient_light_min_eco ; darkest setting
heinrichsweikamp
parents:
diff changeset
315 dcfsnz isr1_temp,F
heinrichsweikamp
parents:
diff changeset
316 movlw ambient_light_min_medium; darkest setting
heinrichsweikamp
parents:
diff changeset
317 dcfsnz isr1_temp,F
heinrichsweikamp
parents:
diff changeset
318 movlw ambient_light_min_high ; darkest setting
heinrichsweikamp
parents:
diff changeset
319
heinrichsweikamp
parents:
diff changeset
320 banksel common ; ambient_light is in Bank1
heinrichsweikamp
parents:
diff changeset
321 cpfsgt ambient_light+0 ; bigger then WREG?
heinrichsweikamp
parents:
diff changeset
322 movwf ambient_light+0 ; No, set to min
heinrichsweikamp
parents:
diff changeset
323
heinrichsweikamp
parents:
diff changeset
324 movff ambient_light+0,max_CCPR1L ; Store value for dimming in TMR7 interrupt
heinrichsweikamp
parents:
diff changeset
325 return
heinrichsweikamp
parents:
diff changeset
326
113
heinrichsweikamp
parents: 44
diff changeset
327 global get_analog_inputs
heinrichsweikamp
parents: 44
diff changeset
328 get_analog_inputs: ; starts ADC and waits until finished
0
heinrichsweikamp
parents:
diff changeset
329 bsf adc_running ; =1: The ADC is in use
113
heinrichsweikamp
parents: 44
diff changeset
330 btfsc TFT_PWM
heinrichsweikamp
parents: 44
diff changeset
331 bra get_analog_inputs ; Wait for PWM low
heinrichsweikamp
parents: 44
diff changeset
332 movlw b'00100000' ; 2.048V Vref+ -> 1LSB = 500µV
heinrichsweikamp
parents: 44
diff changeset
333 movwf ADCON1
heinrichsweikamp
parents: 44
diff changeset
334 movlw b'00100001' ; power on ADC, select AN8
heinrichsweikamp
parents: 44
diff changeset
335 rcall wait_adc
heinrichsweikamp
parents: 44
diff changeset
336 bcf STATUS,C
heinrichsweikamp
parents: 44
diff changeset
337 rrcf ADRESH,F ; /2
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
338 rrcf ADRESL,W
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
339 ; add to o2_mv_sensor1:2
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
340 addwf o2_mv_sensor1+0,F
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
341 movf ADRESH,W
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
342 addwfc o2_mv_sensor1+1,F
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
343 ; Devide by 2
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
344 bcf STATUS,C
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
345 rrcf o2_mv_sensor1+1,F ; /2
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
346 rrcf o2_mv_sensor1+0,F
196
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
347
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
348 movlw HIGH ignore_mv
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
349 cpfsgt o2_mv_sensor1+1 ; >ignore_mv?
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
350 bra get_analog_inputs2a ; No
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
351 ; Yes, ignore this reading
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
352 clrf o2_mv_sensor1+1
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
353 clrf o2_mv_sensor1+0
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
354 get_analog_inputs2a:
187
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
355 ; Ignore 1,2mV noise for not-connected inputs
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
356 tstfsz o2_mv_sensor1+1 ; >25,5mV?
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
357 bra get_analog_inputs2 ; Yes, skip here
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
358 movlw .12
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
359 cpfsgt o2_mv_sensor1+0 ; >1,2mV?
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
360 clrf o2_mv_sensor1+0 ; no, clear result
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
361 get_analog_inputs2:
113
heinrichsweikamp
parents: 44
diff changeset
362 movlw b'00100101' ; power on ADC, select AN9
0
heinrichsweikamp
parents:
diff changeset
363 rcall wait_adc
113
heinrichsweikamp
parents: 44
diff changeset
364 bcf STATUS,C
heinrichsweikamp
parents: 44
diff changeset
365 rrcf ADRESH,F ; /2
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
366 rrcf ADRESL,W
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
367 ; add to o2_mv_sensor2:2
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
368 addwf o2_mv_sensor2+0,F
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
369 movf ADRESH,W
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
370 addwfc o2_mv_sensor2+1,F
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
371 ; Devide by 2
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
372 bcf STATUS,C
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
373 rrcf o2_mv_sensor2+1,F ; /2
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
374 rrcf o2_mv_sensor2+0,F
196
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
375
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
376 movlw HIGH ignore_mv
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
377 cpfsgt o2_mv_sensor2+1 ; >ignore_mv?
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
378 bra get_analog_inputs3a ; No
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
379 ; Yes, ignore this reading
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
380 clrf o2_mv_sensor2+1
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
381 clrf o2_mv_sensor2+0
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
382 get_analog_inputs3a:
187
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
383 ; Ignore 1,2mV noise for not-connected inputs
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
384 tstfsz o2_mv_sensor2+1 ; >25,5mV?
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
385 bra get_analog_inputs3 ; Yes, skip here
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
386 movlw .12
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
387 cpfsgt o2_mv_sensor2+0 ; >1,2mV?
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
388 clrf o2_mv_sensor2+0 ; no, clear result
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
389 get_analog_inputs3:
113
heinrichsweikamp
parents: 44
diff changeset
390 movlw b'00101001' ; power on ADC, select AN10
heinrichsweikamp
parents: 44
diff changeset
391 rcall wait_adc
heinrichsweikamp
parents: 44
diff changeset
392 bcf STATUS,C
heinrichsweikamp
parents: 44
diff changeset
393 rrcf ADRESH,F ; /2
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
394 rrcf ADRESL,W
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
395 ; add to o2_mv_sensor3:2
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
396 addwf o2_mv_sensor3+0,F
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
397 movf ADRESH,W
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
398 addwfc o2_mv_sensor3+1,F
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
399 ; Devide by 2
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
400 bcf STATUS,C
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
401 rrcf o2_mv_sensor3+1,F ; /2
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
402 rrcf o2_mv_sensor3+0,F
196
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
403
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
404 movlw HIGH ignore_mv
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
405 cpfsgt o2_mv_sensor3+1 ; >ignore_mv?
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
406 bra get_analog_inputs4a ; No
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
407 ; Yes, ignore this reading
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
408 clrf o2_mv_sensor3+1
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
409 clrf o2_mv_sensor3+0
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
410 get_analog_inputs4a:
187
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
411 ; Ignore 1,2mV noise for not-connected inputs
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
412 tstfsz o2_mv_sensor3+1 ; >25,5mV?
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
413 bra get_analog_inputs4 ; Yes, skip here
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
414 movlw .12
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
415 cpfsgt o2_mv_sensor3+0 ; >1,2mV?
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
416 clrf o2_mv_sensor3+0 ; no, clear result
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
417 get_analog_inputs4:
0
heinrichsweikamp
parents:
diff changeset
418 bcf ADCON0,0 ; power off ADC
heinrichsweikamp
parents:
diff changeset
419 bcf adc_running ; =1: The ADC is in use
heinrichsweikamp
parents:
diff changeset
420 return
heinrichsweikamp
parents:
diff changeset
421
113
heinrichsweikamp
parents: 44
diff changeset
422 global piezo_config ; Sets up piezo sensitivity of heinrichs weikamp Piezo buttons (~30ms)
117
heinrichsweikamp
parents: 113
diff changeset
423 piezo_config: ; Settings between 20 and 200
158
683321c09cfa nicer boot into surfacemode
heinrichsweikamp
parents: 154
diff changeset
424 movlw .75 ; right button
117
heinrichsweikamp
parents: 113
diff changeset
425 rcall piezo_config_tx
158
683321c09cfa nicer boot into surfacemode
heinrichsweikamp
parents: 154
diff changeset
426 movlw .75 ; left button
117
heinrichsweikamp
parents: 113
diff changeset
427 rcall piezo_config_tx
heinrichsweikamp
parents: 113
diff changeset
428 movlw .200 ; reserved
heinrichsweikamp
parents: 113
diff changeset
429 rcall piezo_config_tx
heinrichsweikamp
parents: 113
diff changeset
430 movlw .200 ; reserved
heinrichsweikamp
parents: 113
diff changeset
431 rcall piezo_config_tx
113
heinrichsweikamp
parents: 44
diff changeset
432 return
heinrichsweikamp
parents: 44
diff changeset
433
204
heinrichsweikamp
parents: 203
diff changeset
434 global piezo_config_dive ; Sets up piezo sensitivity of heinrichs weikamp Piezo buttons (~30ms)
heinrichsweikamp
parents: 203
diff changeset
435 piezo_config_dive: ; Settings between 20 and 200
heinrichsweikamp
parents: 203
diff changeset
436 movlw .60 ; right button
heinrichsweikamp
parents: 203
diff changeset
437 rcall piezo_config_tx
heinrichsweikamp
parents: 203
diff changeset
438 movlw .60 ; left button
heinrichsweikamp
parents: 203
diff changeset
439 rcall piezo_config_tx
heinrichsweikamp
parents: 203
diff changeset
440 movlw .200 ; reserved
heinrichsweikamp
parents: 203
diff changeset
441 rcall piezo_config_tx
heinrichsweikamp
parents: 203
diff changeset
442 movlw .200 ; reserved
heinrichsweikamp
parents: 203
diff changeset
443 rcall piezo_config_tx
heinrichsweikamp
parents: 203
diff changeset
444 return
heinrichsweikamp
parents: 203
diff changeset
445
117
heinrichsweikamp
parents: 113
diff changeset
446 piezo_config_tx: ; Send one byte
113
heinrichsweikamp
parents: 44
diff changeset
447 movwf uart1_temp ; Store byte
heinrichsweikamp
parents: 44
diff changeset
448 movlw .8
heinrichsweikamp
parents: 44
diff changeset
449 movwf uart2_temp ; Bit counter
heinrichsweikamp
parents: 44
diff changeset
450 bcf TX3_PIEZO_CFG ; Startbit
heinrichsweikamp
parents: 44
diff changeset
451 rcall piezo_config_wait_bit
heinrichsweikamp
parents: 44
diff changeset
452 piezo_config_tx_loop:
heinrichsweikamp
parents: 44
diff changeset
453 btfss uart1_temp,0 ; LSB first
heinrichsweikamp
parents: 44
diff changeset
454 bcf TX3_PIEZO_CFG
heinrichsweikamp
parents: 44
diff changeset
455 btfsc uart1_temp,0 ; LSB first
heinrichsweikamp
parents: 44
diff changeset
456 bsf TX3_PIEZO_CFG
heinrichsweikamp
parents: 44
diff changeset
457 rcall piezo_config_wait_bit
heinrichsweikamp
parents: 44
diff changeset
458 rrncf uart1_temp,F
heinrichsweikamp
parents: 44
diff changeset
459 decfsz uart2_temp,F
heinrichsweikamp
parents: 44
diff changeset
460 bra piezo_config_tx_loop
heinrichsweikamp
parents: 44
diff changeset
461 bsf TX3_PIEZO_CFG ; Stopbit
heinrichsweikamp
parents: 44
diff changeset
462 rcall piezo_config_wait_bit
heinrichsweikamp
parents: 44
diff changeset
463 return
heinrichsweikamp
parents: 44
diff changeset
464
heinrichsweikamp
parents: 44
diff changeset
465 piezo_config_wait_bit:
heinrichsweikamp
parents: 44
diff changeset
466 setf TMR5H
heinrichsweikamp
parents: 44
diff changeset
467 movlw .255-.26 ;26 x 31,5µs = 819us
heinrichsweikamp
parents: 44
diff changeset
468 movwf TMR5L
heinrichsweikamp
parents: 44
diff changeset
469 bcf PIR5,TMR5IF ; Clear flag
heinrichsweikamp
parents: 44
diff changeset
470 piezo_config_wait_bit3:
heinrichsweikamp
parents: 44
diff changeset
471 btfss PIR5,TMR5IF
heinrichsweikamp
parents: 44
diff changeset
472 bra piezo_config_wait_bit3 ; Wait loop
heinrichsweikamp
parents: 44
diff changeset
473 return
heinrichsweikamp
parents: 44
diff changeset
474
0
heinrichsweikamp
parents:
diff changeset
475 global reset_battery_pointer
heinrichsweikamp
parents:
diff changeset
476 reset_battery_pointer: ; Resets battery pointer 0x07-0x0C and battery_gauge:5
113
heinrichsweikamp
parents: 44
diff changeset
477 extern lt2942_charge_done
heinrichsweikamp
parents: 44
diff changeset
478 call lt2942_charge_done ; Reset accumulating registers to 0xFFFF
heinrichsweikamp
parents: 44
diff changeset
479 clrf EEADRH
0
heinrichsweikamp
parents:
diff changeset
480 clrf EEDATA ; Delete to zero
heinrichsweikamp
parents:
diff changeset
481 write_int_eeprom 0x07
heinrichsweikamp
parents:
diff changeset
482 write_int_eeprom 0x08
heinrichsweikamp
parents:
diff changeset
483 write_int_eeprom 0x09
heinrichsweikamp
parents:
diff changeset
484 write_int_eeprom 0x0A
heinrichsweikamp
parents:
diff changeset
485 write_int_eeprom 0x0B
heinrichsweikamp
parents:
diff changeset
486 write_int_eeprom 0x0C
heinrichsweikamp
parents:
diff changeset
487 banksel battery_gauge+0
heinrichsweikamp
parents:
diff changeset
488 clrf battery_gauge+0
heinrichsweikamp
parents:
diff changeset
489 clrf battery_gauge+1
heinrichsweikamp
parents:
diff changeset
490 clrf battery_gauge+2
heinrichsweikamp
parents:
diff changeset
491 clrf battery_gauge+3
heinrichsweikamp
parents:
diff changeset
492 clrf battery_gauge+4
heinrichsweikamp
parents:
diff changeset
493 clrf battery_gauge+5
heinrichsweikamp
parents:
diff changeset
494 banksel common
heinrichsweikamp
parents:
diff changeset
495 movlw .100
heinrichsweikamp
parents:
diff changeset
496 movwf batt_percent
heinrichsweikamp
parents:
diff changeset
497 return
heinrichsweikamp
parents:
diff changeset
498
heinrichsweikamp
parents:
diff changeset
499
heinrichsweikamp
parents:
diff changeset
500 END