annotate src/adc_lightsensor.asm @ 621:1ad0531e9078

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