annotate src/i2c.asm @ 621:1ad0531e9078

3.01 release
author heinrichsweikamp
date Sat, 23 Feb 2019 16:51:14 +0100
parents cd986267a5ca
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: 582
diff changeset
3 ; File i2c.asm V2.99c
0
heinrichsweikamp
parents:
diff changeset
4 ;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
5 ; I2C Interface
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
6 ;
0
heinrichsweikamp
parents:
diff changeset
7 ; Copyright (c) 2012, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
8 ;=============================================================================
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
9 ;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
10 ; Compass0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
11 ; --------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
12 ; HMC5883L's read address (8-Bit): 0x3D
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
13 ; HMC5883L's write address (8-Bit): 0x3C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
14 ; MMA8452Q's read address (8-Bit): 0x39
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
15 ; MMA8452Q's write address (8-Bit): 0x38
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
16 ;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
17 ; Compass1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
18 ; --------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
19 ; LSM303D's read address (8-Bit): 0x3D
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
20 ; LSM303D's write address (8-Bit): 0x3C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
21 ;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
22 ; Compass2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
23 ; --------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
24 ; LSM303AGR's Compass read address (8-Bit): 0x3D
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
25 ; LSM303AGR's Compass write address (8-Bit): 0x3C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
26 ; LSM303AGR's Acceleration read address (8-Bit): 0x33
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
27 ; LSM303AGR's Acceleration write address (8-Bit): 0x32
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
28 ;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
29 ; RX Circuity
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
30 ; -----------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
31 ; RX Circuity read address (8-Bit): 0x51
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
32 ; RX Circuity write address (8-Bit): 0x50
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
33 ;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
34 ;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
35
0
heinrichsweikamp
parents:
diff changeset
36 ; HISTORY
heinrichsweikamp
parents:
diff changeset
37 ; 2012-08-22 : [mH] Creation
565
0ba88db66492 CHANGE: Limit button sensitivity to 80%
heinrichsweikamp
parents: 564
diff changeset
38 ; 2018-02-18 : [mH] Sync with hwOS Sport release
0
heinrichsweikamp
parents:
diff changeset
39
heinrichsweikamp
parents:
diff changeset
40
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
41 #include "hwos.inc" ; Mandatory header
0
heinrichsweikamp
parents:
diff changeset
42 #include "wait.inc"
113
heinrichsweikamp
parents: 20
diff changeset
43 #include "math.inc"
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
44 #include "external_flash.inc"
113
heinrichsweikamp
parents: 20
diff changeset
45
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
46
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
47 i2c CODE
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
48
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
49 ;=============================================================================
0
heinrichsweikamp
parents:
diff changeset
50
heinrichsweikamp
parents:
diff changeset
51 I2C_TX:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
52 movwf SSP1BUF
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
53 rcall WaitMSSP
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
54 bra I2C_WaitforACK ; returns...
0
heinrichsweikamp
parents:
diff changeset
55
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
56 I2C_TwoBytesRX_div16: ; get two bytes and divide lo:hi/16 (signed)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
57 rcall I2C_OneByteRX ; get one byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
58 movff SSP1BUF,hi ; data byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
59 rcall I2C_OneByteRX ; get one byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
60 movff SSP1BUF,lo ; data byte
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
61 I2C_TwoBytesRX_div16_2: ; divide lo:hi/16 (signed) only
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
62 bcf STATUS,C
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
63 btfsc hi,7 ; copy sign bit to carry
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
64 bsf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
65 rrcf hi ; /2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
66 rrcf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
67 I2C_TwoBytesRX_div8_2: ; divide lo:hi/8 (signed) only
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
68 bcf STATUS,C
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
69 btfsc hi,7 ; copy sign bit to carry
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
70 bsf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
71 rrcf hi ; /4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
72 rrcf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
73 bcf STATUS,C
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
74 btfsc hi,7 ; copy sign bit to carry
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
75 bsf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
76 rrcf hi ; /8
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
77 rrcf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
78 bcf STATUS,C
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
79 btfsc hi,7 ; copy sign bit to carry
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
80 bsf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
81 rrcf hi ; /16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
82 rrcf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
83 return
0
heinrichsweikamp
parents:
diff changeset
84
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
85 global I2C_RX_accelerometer
0
heinrichsweikamp
parents:
diff changeset
86 I2C_RX_accelerometer:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
87 btfsc compass_type2 ; compass2 ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
88 bra I2C_RX_accelerometer_compass2 ; YES
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
89 btfsc compass_type ; compass1 ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
90 bra I2C_RX_accelerometer_compass1 ; YES
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
91 I2C_RX_accelerometer_compass0:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
92 bsf SSP1CON2,SEN ; start condition
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
93 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
94 movlw 0x38 ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
95 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
96 movlw 0x00
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
97 rcall I2C_TX
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
98 bsf SSP1CON2,RSEN ; repeated start condition
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
99 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
100 movlw 0x39 ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
101 rcall I2C_TX
0
heinrichsweikamp
parents:
diff changeset
102
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
103 rcall I2C_OneByteRX ; get status byte
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
104 movf SSP1BUF,W
158
683321c09cfa nicer boot into surfacemode
heinrichsweikamp
parents: 113
diff changeset
105
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
106 ; Non-flipped screen:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
107 ; Chip orientation on the PCB requires
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
108 ; Original = corrected
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
109 ; x = -x
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
110 ; y = -y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
111 ; z = -z
0
heinrichsweikamp
parents:
diff changeset
112
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
113 ; Flipped screen:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
114 ; Chip orientation on the PCB requires
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
115 ; Original = corrected
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
116 ; x = x
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
117 ; y = y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
118 ; z = -z
166
30ebaf72170d BUGFIX: Flip compass with flipped screen, too
heinrichsweikamp
parents: 158
diff changeset
119
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
120 rcall I2C_TwoBytesRX_div16 ; get two bytes and divide /16 (signed)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
121 btfsc flip_screen ; 180° rotation ?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
122 bra I2C_RX_accelerometer2 ; YES
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
123 comf hi ; 16 bit sign change
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
124 negf lo
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
125 btfsc STATUS,C ; carry to propagate ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
126 incf hi,F ; YES - do it
166
30ebaf72170d BUGFIX: Flip compass with flipped screen, too
heinrichsweikamp
parents: 158
diff changeset
127 I2C_RX_accelerometer2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
128 movff lo,accel_DX+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
129 movff hi,accel_DX+1 ; Copy result
0
heinrichsweikamp
parents:
diff changeset
130
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
131 rcall I2C_TwoBytesRX_div16 ; Get two bytes and divide /16 (signed)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
132 btfsc flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
133 bra I2C_RX_accelerometer3 ; Yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
134 comf hi ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
135 negf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
136 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
137 incf hi,F ; YES: do it.
166
30ebaf72170d BUGFIX: Flip compass with flipped screen, too
heinrichsweikamp
parents: 158
diff changeset
138 I2C_RX_accelerometer3:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
139 movff lo,accel_DY+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
140 movff hi,accel_DY+1 ; Copy result
0
heinrichsweikamp
parents:
diff changeset
141
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
142 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
143 movff SSP1BUF,hi ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
144 bsf SSP1CON2, RCEN ; Enable receive mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
145 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
146 ; According to data sheet there should be no Master Acknowledge for the last Byte (accel_DZ+0)...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
147 movff SSP1BUF,lo ; Data Byte
0
heinrichsweikamp
parents:
diff changeset
148
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
149 rcall I2C_TwoBytesRX_div16_2 ; divide lo:hi/16 (signed) only
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
150 comf hi ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
151 negf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
152 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
153 incf hi,F ; YES: do it.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
154 movff lo,accel_DZ+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
155 movff hi,accel_DZ+1 ; Copy result
0
heinrichsweikamp
parents:
diff changeset
156
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
157 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
158 bra WaitMSSP ; (And return)
0
heinrichsweikamp
parents:
diff changeset
159
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
160 I2C_RX_accelerometer_compass1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
161 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
162 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
163 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
164 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
165 movlw b'10101000' ; 0x28 with auto-increment (MSB=1)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
166 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
167 bsf SSP1CON2,RSEN ; Repeated start condition (!)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
168 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
169 movlw 0x3D ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
170 I2C_RX_accelerometer_compass1_xx: ; compass2 continues here...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
171 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
172
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
173 ; Non-flipped screen:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
174 ; Chip orientation on the PCB requires
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
175 ; Original = Corrected
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
176 ; x = -x (Compass 1)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
177 ; x = x (Compass 2)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
178 ; y = -y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
179 ; z = -z
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
180
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
181 ; Flipped screen:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
182 ; Chip orientation on the PCB requires
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
183 ; Original = Corrected
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
184 ; x = x (Compass 1)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
185 ; x = -x (Compass 2)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
186 ; y = y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
187 ; z = -z
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
188
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
189 ; Dump the accelerator data
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
190 rcall I2C_OneByteRX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
191 movff SSP1BUF,lo ; accel_DX+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
192 rcall I2C_OneByteRX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
193 movff SSP1BUF,hi ;accel_DX+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
194 rcall I2C_TwoBytesRX_div16_2 ; divide lo:hi/16 (signed) only
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
195 btfss compass_type2 ; compass 2?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
196 bra I2C_RX_accelerometer1_c1 ; No, compass 1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
197 ; compass 2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
198 btfss flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
199 bra I2C_RX_accelerometer2_c1 ; No, continue with normal compass1 routines for Y and Z
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
200 ; flipped compass 2, negate x
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
201 comf hi ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
202 negf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
203 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
204 incf hi,F ; YES: do it.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
205 bra I2C_RX_accelerometer2_c1 ; continue with normal compass1 routines for Y and Z
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
206
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
207 I2C_RX_accelerometer1_c1:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
208 btfsc flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
209 bra I2C_RX_accelerometer2_c1 ; Yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
210 ; non-flipped compass 1, negate x
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
211 comf hi ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
212 negf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
213 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
214 incf hi,F ; YES: do it.
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
215 I2C_RX_accelerometer2_c1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
216 ; flipped compass 1, non-flipped compass 2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
217 movff lo,accel_DX+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
218 movff hi,accel_DX+1 ; Copy result
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
219 rcall I2C_OneByteRX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
220 movff SSP1BUF,lo ; accel_DY+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
221 rcall I2C_OneByteRX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
222 movff SSP1BUF,hi ; accel_DY+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
223
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
224 rcall I2C_TwoBytesRX_div16_2 ; divide lo:hi/16 (signed) only
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
225 btfsc flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
226 bra I2C_RX_accelerometer3_c1 ; Yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
227 comf hi ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
228 negf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
229 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
230 incf hi,F ; YES: do it.
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
231 I2C_RX_accelerometer3_c1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
232 movff lo,accel_DY+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
233 movff hi,accel_DY+1 ; Copy result
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
234
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
235 rcall I2C_OneByteRX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
236 movff SSP1BUF,lo ;accel_DZ+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
237 bsf SSP1CON2, RCEN ; Enable receive mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
238 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
239 ; According to data sheet there should be no Master Acknowledge for the last Byte (accel_DZ+1)...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
240 movff SSP1BUF,hi ;accel_DZ+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
241 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
242 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
243 rcall I2C_TwoBytesRX_div16_2 ; divide lo:hi/16 (signed) only
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
244 comf hi ; 16bit sign change for Z
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
245 negf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
246 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
247 incf hi,F ; YES: do it.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
248 movff lo,accel_DZ+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
249 movff hi,accel_DZ+1 ; Copy result
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
250 return
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
251
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
252 I2C_RX_accelerometer_compass2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
253 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
254 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
255 movlw 0x32 ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
256 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
257 movlw b'10101000' ; 0x28 with auto-increment (MSB=1)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
258 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
259 bsf SSP1CON2,RSEN ; Repeated start condition (!)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
260 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
261 movlw 0x33 ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
262 bra I2C_RX_accelerometer_compass1_xx
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
263
0
heinrichsweikamp
parents:
diff changeset
264 I2C_OneByteRX:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
265 bsf SSP1CON2,RCEN ; Enable receive mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
266 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
267 bsf SSP1CON2,ACKEN ; Master acknowledge
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
268 bra WaitMSSP ; And return!
0
heinrichsweikamp
parents:
diff changeset
269
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
270 global I2C_RX_compass
0
heinrichsweikamp
parents:
diff changeset
271 I2C_RX_compass:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
272 btfsc compass_type2 ; compass2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
273 bra I2C_RX_compass2 ; yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
274 btfsc compass_type ; compass1?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
275 bra I2C_RX_compass1 ; yes
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
276 I2C_RX_compass0:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
277 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
278 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
279 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
280 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
281 movlw 0x03
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
282 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
283 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
284 rcall WaitMSSP
0
heinrichsweikamp
parents:
diff changeset
285
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
286 bcf PIR1,SSP1IF
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
287 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
288 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
289 movlw 0x3D ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
290 rcall I2C_TX
0
heinrichsweikamp
parents:
diff changeset
291
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
292 ; Compass IC sends data in following order:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
293 ; x MSB
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
294 ; x LSB
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
295 ; z MSB
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
296 ; z LSB
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
297 ; y MSB
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
298 ; y LSB
0
heinrichsweikamp
parents:
diff changeset
299
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
300 ; Non-flipped screen
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
301 ; Chip orientation on the PCB requires
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
302 ; Original = Corrected
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
303 ; x = -y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
304 ; z = z
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
305 ; y = x
0
heinrichsweikamp
parents:
diff changeset
306
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
307 ; Flipped screen
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
308 ; Chip orientation on the PCB requires
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
309 ; Original = Corrected
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
310 ; x = y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
311 ; z = z
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
312 ; y = -x
166
30ebaf72170d BUGFIX: Flip compass with flipped screen, too
heinrichsweikamp
parents: 158
diff changeset
313
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
314 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
315 movff SSP1BUF,compass_DY+1 ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
316 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
317 movff SSP1BUF,compass_DY+0 ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
318 btfsc flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
319 bra I2C_RX_compass0_2 ; Yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
320 banksel compass_DY
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
321 comf compass_DY+1 ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
322 negf compass_DY+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
323 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
324 incf compass_DY+1,F ; YES: do it.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
325 I2C_RX_compass0_2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
326 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
327 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
328 movff SSP1BUF,compass_DZ+1 ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
329 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
330 movff SSP1BUF,compass_DZ+0 ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
331 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
332 movff SSP1BUF,compass_DX+1 ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
333 bsf SSP1CON2, RCEN ; Enable receive mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
334 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
335 movff SSP1BUF,compass_DX+0 ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
336 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
337 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
338 btfss flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
339 return ; No, done.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
340 ; Yes, flip X
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
341 banksel compass_DX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
342 comf compass_DX+1 ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
343 negf compass_DX+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
344 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
345 incf compass_DX+1,F ; YES: do it.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
346 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
347 return
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
348
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
349 I2C_RX_compass1: ; New compass
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
350 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
351 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
352 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
353 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
354 movlw b'10001000' ; 0x08 with auto-increment (MSB=1)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
355 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
356 bsf SSP1CON2,RSEN ; Repeated start condition (!)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
357 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
358 movlw 0x3D ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
359 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
360 ;rcall WaitMSSP ; Needed? (mH)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
361 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
362 movff SSP1BUF,lo ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
363 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
364 movff SSP1BUF,hi ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
365 rcall I2C_TwoBytesRX_div8_2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
366 movff lo,compass_DX+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
367 movff hi,compass_DX+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
368 btfss flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
369 bra I2C_RX_compass1_1 ; Yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
370 ; Yes, flip X
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
371 banksel compass_DX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
372 comf compass_DX+1 ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
373 negf compass_DX+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
374 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
375 incf compass_DX+1,F ; YES: do it.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
376 banksel common
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
377 I2C_RX_compass1_1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
378 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
379 movff SSP1BUF,lo ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
380 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
381 movff SSP1BUF,hi ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
382 rcall I2C_TwoBytesRX_div8_2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
383 movff lo,compass_DY+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
384 movff hi,compass_DY+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
385 btfss flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
386 bra I2C_RX_compass1_2 ; Yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
387 ; Yes, flip Y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
388 banksel compass_DY
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
389 comf compass_DY+1 ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
390 negf compass_DY+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
391 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
392 incf compass_DY+1,F ; YES: do it.
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
393 I2C_RX_compass1_2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
394 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
395 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
396 movff SSP1BUF,lo ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
397 bsf SSP1CON2, RCEN ; Enable receive mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
398 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
399 movff SSP1BUF,hi ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
400 rcall I2C_TwoBytesRX_div8_2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
401 movff lo,compass_DZ+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
402 movff hi,compass_DZ+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
403 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
404 bra WaitMSSP ;(And return)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
405
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
406 I2C_RX_compass2: ; newest compass
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
407 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
408 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
409 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
410 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
411 movlw 0xE8 ; 0x68 with auto-increment (MSB=1)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
412 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
413 bsf SSP1CON2,RSEN ; Repeated start condition (!)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
414 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
415 movlw 0x3D ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
416 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
417 ; rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
418 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
419 movff SSP1BUF,lo ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
420 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
421 movff SSP1BUF,hi ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
422 ; rcall I2C_TwoBytesRX_div8_2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
423 btfsc flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
424 bra I2C_RX_compass2_1 ; Yes, do nothing with X
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
425 ; No, flip X
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
426 comf hi ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
427 negf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
428 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
429 incf hi,F ; YES: do it.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
430 I2C_RX_compass2_1:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
431 movff lo,compass_DX+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
432 movff hi,compass_DX+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
433 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
434 movff SSP1BUF,lo ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
435 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
436 movff SSP1BUF,hi ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
437 ; rcall I2C_TwoBytesRX_div8_2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
438 btfss flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
439 bra I2C_RX_compass2_2 ; No, do nothing with Y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
440 ; Yes, flip Y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
441 comf hi ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
442 negf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
443 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
444 incf hi,F ; YES: do it.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
445 I2C_RX_compass2_2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
446 movff lo,compass_DY+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
447 movff hi,compass_DY+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
448 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
449 movff SSP1BUF,lo ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
450 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
451 movff SSP1BUF,hi ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
452 ; rcall I2C_TwoBytesRX_div8_2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
453 movff lo,compass_DZ+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
454 movff hi,compass_DZ+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
455 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
456 bra WaitMSSP ;(And return)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
457
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
458
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
459 global I2C_init_compass
0
heinrichsweikamp
parents:
diff changeset
460 I2C_init_compass:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
461 bsf compass_enabled
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
462 bcf compass_type2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
463 ; probe compass 2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
464 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
465 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
466 movlw 0x32 ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
467 movwf SSP1BUF ; control byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
468 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
469 btfss SSP1CON2,ACKSTAT ; ACK?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
470 bsf compass_type2 ; ACK send. compass2 present
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
471 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
472 rcall WaitMSSP
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
473
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
474 btfsc compass_type2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
475 bra I2C_init_compass2 ; Compass2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
476 ; Check for compass0 or compass1...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
477 bsf compass_type ; set flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
478 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
479 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
480 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
481 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
482 movlw 0x0F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
483 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
484 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
485 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
486 bcf PIR1,SSP1IF
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
487 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
488 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
489 movlw 0x3D ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
490 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
491 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
492 movlw 0x49 ; 0x49 = Compass1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
493 cpfseq SSP1BUF
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
494 bcf compass_type ; clear flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
495 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
496 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
497
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
498 btfsc compass_type ; compass1?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
499 bra I2C_init_compass1 ; yes
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
500 ; init compass0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
501 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
502 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
503 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
504 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
505 movlw 0x00
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
506 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
507 ; movlw b'01101001' ; ConfigA: 3Hz, 8 Samples averaged, Test Mode (Positive Bias)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
508 movlw b'01101000' ; ConfigA: 3Hz, 8 Samples averaged
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
509 rcall I2C_TX
20
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
510 I2C_init_compass_common:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
511 movff opt_compass_gain,i2c_temp1 ; 0-7 (230LSB/Gauss to 1370LSB/Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
512 swapf i2c_temp1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
513 comf i2c_temp1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
514 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
515 rlcf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
516 movf i2c_temp1,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
517 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
518 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
519 movlw b'00000000' ; Continuous Mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
520 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
521 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
522 bra WaitMSSP ; (And return)
0
heinrichsweikamp
parents:
diff changeset
523
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
524 I2C_init_compass1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
525 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
526 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
527 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
528 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
529 movlw 0x9F ; 1F with auto-increment (MSB=1)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
530 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
531 movlw b'00000000' ; CTRL0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
532 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
533 movlw b'00101111' ; CTRL1 (6,25Hz, BDU=0, x,y,z = ON)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
534 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
535 movlw b'11000000' ; CTRL2 (50Hz, +/-2g,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
536 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
537 movlw b'00000000' ; CTRL3
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
538 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
539 movlw b'00000000' ; CTRL4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
540 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
541 movlw b'01100100' ; CTRL5 HIGH res, 6,25Hz
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
542 rcall I2C_TX
429
4b93354b7738 hardware_flag handling
heinrichsweikamp
parents: 427
diff changeset
543 init_compass1_common:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
544 movff opt_compass_gain,i2c_temp1 ; 0-7 (230LSB/Gauss to 1370LSB/Gauss) +++
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
545 movlw b'01100000' ; CTRL6 Full scale (+/-12 Gauss -> 2730LSB/Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
546 dcfsnz i2c_temp1,F ; = 1?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
547 movlw b'01100000' ; Yes, CTRL6 Full scale (+/-12 Gauss -> 2730LSB/Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
548 dcfsnz i2c_temp1,F ; = 2?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
549 movlw b'01000000' ; Yes, CTRL6 (+/-8 Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
550 dcfsnz i2c_temp1,F ; = 3?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
551 movlw b'01000000' ; Yes, CTRL6 (+/-8 Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
552 dcfsnz i2c_temp1,F ; = 4?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
553 movlw b'00100000' ; Yes, CTRL6 (+/-4 Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
554 dcfsnz i2c_temp1,F ; = 5?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
555 movlw b'00100000' ; Yes, CTRL6 (+/-4 Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
556 dcfsnz i2c_temp1,F ; = 6?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
557 movlw b'00000000' ; Yes, CTRL6 (+/-2 Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
558 dcfsnz i2c_temp1,F ; = 7?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
559 movlw b'00000000' ; Yes, CTRL6 (+/-2 Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
560 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
561 movlw b'00000000' ; CTRL7 Continuous Mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
562 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
563 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
564 bra WaitMSSP ; (And return)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
565
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
566 I2C_init_compass2:
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
567 bsf SSP1CON2,SEN ; Start condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
568 rcall WaitMSSP
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
569 movlw 0x3C ; address
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
570 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
571 movlw 0xE0 ; 0x60 with auto-increment (MSB=1)
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
572 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
573 movlw b'00000000' ; CFG_REG_A_M (10Hz, Continuous) 0x60
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
574 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
575 movlw b'00000000' ; CFG_REG_B_M (Low-Pass Filter off) 0x61 (set pulse is released every 63 ODR)
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
576 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
577 movlw b'00000000' ; CFG_REG_C_M BDU=0 0x62
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
578 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
579 bsf SSP1CON2,PEN ; Stop condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
580 bra WaitMSSP ;(And return)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
581
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
583 global I2C_sleep_compass
0
heinrichsweikamp
parents:
diff changeset
584 I2C_sleep_compass:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
585 bcf compass_enabled
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
586 btfsc compass_type2 ; compass2?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
587 bra I2C_sleep_compass2 ; yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
588 btfsc compass_type ; compass1?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
589 bra I2C_sleep_compass1 ; yes
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
590 I2C_sleep_compass0:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
591 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
592 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
593 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
594 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
595 movlw 0x00
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
596 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
597 movlw b'01101000' ; ConfigA
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
598 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
599 movlw b'00100000' ; ConfigB
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
600 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
601 movlw b'00000010' ; Idle Mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
602 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
603 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
604 bra WaitMSSP ; (And return)
0
heinrichsweikamp
parents:
diff changeset
605
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
606 I2C_sleep_compass1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
607 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
608 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
609 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
610 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
611 movlw 0x20 ; CTRL_REG1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
612 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
613 movlw b'00000000' ; data for CTRL_REG1: acceleration sensor Power-down mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
614 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
615 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
616 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
617 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
618 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
619 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
620 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
621 movlw 0x26 ; CTRL_REG7
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
622 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
623 movlw b'00000010' ; data for CTRL_REG7: magnetic sensor Power-down mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
624 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
625 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
626 bra WaitMSSP ;(And return)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
627
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
628 I2C_sleep_compass2:
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
629 ; magnetic
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
630 bsf SSP1CON2,SEN ; Start condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
631 rcall WaitMSSP
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
632 movlw 0x3C ; address
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
633 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
634 movlw 0xE0 ; 0x60 with auto-increment (MSB=1)
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
635 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
636 movlw b'00000011' ; CFG_REG_A_M (Idle mode) 0x60
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
637 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
638 movlw b'00000100' ; CFG_REG_B_M 0x61 (set pulse is released only at power-on after PD condition)
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
639 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
640 movlw b'01010001' ; CFG_REG_C_M 0x62
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
641 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
642 movlw b'00000000' ; INT_CTRL_REG_M 0x63
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
643 rcall I2C_TX
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
644
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
645 bsf SSP1CON2,PEN ; Stop condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
646 bra WaitMSSP ; (And return)
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
647
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
648 I2C_sleep_accelerometer2:
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
649 ; accelerometer
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
650 bsf SSP1CON2,SEN ; Start condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
651 rcall WaitMSSP
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
652 movlw 0x32 ; address
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
653 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
654 movlw 0x9F ; 1F with auto-increment (MSB=1)
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
655 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
656 movlw b'00000000' ; TEMP_CFG_REG_A (Temp sensor off) 0x1F
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
657 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
658 movlw b'00000000' ; CTRL_REG1_A (All off) 0x20
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
659 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
660 bsf SSP1CON2,PEN ; Stop condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
661 bra WaitMSSP ; (And return)
0
heinrichsweikamp
parents:
diff changeset
662
615
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
663 WaitMSSP:
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
664 decfsz i2c_temp1,F ; check for timeout during I2C action
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
665 bra WaitMSSP2
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
666 bra I2CFail ; timeout occurred
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
667 WaitMSSP2:
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
668 btfss PIR1,SSP1IF
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
669 bra WaitMSSP
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
670 clrf i2c_temp1
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
671 bcf PIR1,SSP1IF
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
672 return
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
673
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
674 I2C_WaitforACK:
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
675 btfss SSP1CON2,ACKSTAT ; checks for ACK bit from slave
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
676 return
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
677 I2CFail:
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
678 rcall I2CReset ; I2C Reset
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
679 bcf PIR1,SSP1IF
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
680 clrf i2c_temp1
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
681 bsf i2c_error_flag ; set error flag
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
682 return
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
683
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
684 I2CReset: ; something went wrong (slave holds SDA low?)
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
685 clrf SSP1CON1 ; wake-up slave and reset entire module
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
686 clrf SSP1CON2
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
687 clrf SSP1STAT
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
688 bcf TRISC,3 ; SCL OUTPUT
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
689 bsf TRISC,4 ; SDA input
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
690 bcf PORTC,3
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
691 movlw d'9'
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
692 movwf i2c_temp1 ; clock-out 9 clock cycles manually
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
693 I2CReset_1:
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
694 bsf PORTC,3 ; SCL = 1
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
695 nop
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
696 nop
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
697 nop
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
698 nop
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
699 btfsc PORTC,4 ; SDA = 1 ?
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
700 bra I2CReset_2 ; YES - =1, SDA has been released from slave
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
701 bcf PORTC,3 ; NO - set SCL = 0
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
702 nop
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
703 nop
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
704 bcf PORTC,3
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
705 nop
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
706 nop
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
707 decfsz i2c_temp1,F
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
708 bra I2CReset_1 ; check for nine clock cycles
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
709 I2CReset_2:
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
710 bsf TRISC,3 ; SCL Input
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
711 clrf SSP1CON1 ; setup I²C mode
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
712 WAITMS d'10' ; reset-timeout for I2C devices
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
713 movlw b'00000000' ; with slew rate control
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
714 movwf SSP1STAT
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
715 movlw b'00101000'
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
716 movwf SSP1CON1
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
717 movlw b'00000000'
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
718 movwf SSP1CON2
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
719 movlw 0x27
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
720 movwf SSP1ADD
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
721 return
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
722
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
723 global I2C_init_accelerometer
0
heinrichsweikamp
parents:
diff changeset
724 I2C_init_accelerometer:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
725 btfsc compass_type2 ; compass2?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
726 bra I2C_init_accelerometer2 ; Yes.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
727
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
728 btfsc compass_type ; compass1?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
729 return ; yes, ignore
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
730
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
731 rcall I2C_sleep_accelerometer ; Regs can only be changed in St.By mode
0
heinrichsweikamp
parents:
diff changeset
732
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
733 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
734 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
735 movlw 0x38 ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
736 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
737 movlw 0x0E ; XYZ_DATA_CFG
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
738 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
739 movlw b'00000000' ; High pass Filter=0 , +/- 2g range
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
740 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
741 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
742 rcall WaitMSSP
0
heinrichsweikamp
parents:
diff changeset
743
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
744 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
745 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
746 movlw 0x38 ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
747 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
748 movlw 0x2A ; CTRL_REG1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
749 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
750 ; movlw b'00110000' ; CTRL_REG1: 160ms data rate, St.By Mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
751 movlw b'00110100' ; CTRL_REG1: 160ms data rate, St.By Mode, reduced noise mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
752 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
753 movlw b'00000010' ; CTRL_REG2: High Res in Active mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
754 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
755 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
756 rcall WaitMSSP
0
heinrichsweikamp
parents:
diff changeset
757
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
758 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
759 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
760 movlw 0x38 ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
761 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
762 movlw 0x2A ; CTRL_REG1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
763 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
764 ; movlw b'00110001' ; CTRL_REG1: 160ms data rate, Active Mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
765 movlw b'00110101' ; CTRL_REG1: 160ms data rate, St.By Mode, reduced noise mode, Active Mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
766 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
767 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
768 bra WaitMSSP ; (And return)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
769
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
770 I2C_init_accelerometer2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
771 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
772 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
773 movlw 0x32 ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
774 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
775 movlw 0x9F ; 1F with auto-increment (MSB=1)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
776 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
777 movlw b'00000000' ; TEMP_CFG_REG_A (Temp sensor off)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
778 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
779 movlw b'01010111' ; CTRL_REG1_A (100Hz, x,y,z = ON)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
780 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
781 movlw b'00000000' ; CTRL_REG2_A
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
782 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
783 ; movlw b'00000000' ; CTRL_REG3_A
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
784 ; rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
785 ; movlw b'00000000' ; CTRL_REG4_A (BDU=0, +/-2g,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
786 ; rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
787 ; movlw b'00000000' ; CTRL_REG5_A
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
788 ; rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
789 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
790 bra WaitMSSP ; (And return)
0
heinrichsweikamp
parents:
diff changeset
791
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
792 global I2C_sleep_accelerometer
0
heinrichsweikamp
parents:
diff changeset
793 I2C_sleep_accelerometer:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
794 btfsc compass_type2 ; Compass2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
795 bra I2C_sleep_accelerometer2 ; Yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
796 btfsc compass_type ; compass1?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
797 return ; yes, ignore
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
798
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
799 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
800 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
801 movlw 0x38 ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
802 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
803 movlw 0x2A ; CTRL_REG1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
804 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
805 movlw b'00000000' ; St. By Mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
806 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
807 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
808 bra WaitMSSP ; (And return)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
809
556
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
810 lt2942_init_again:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
811 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
812 movlw 0x02 ; Point to accumulated charge registers
556
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
813 rcall I2C_TX_GAUGE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
814 movff battery_acumulated_charge+1,SSP1BUF ; Data Byte
556
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
815 rcall WaitMSSP
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
816 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
817 movff battery_acumulated_charge+0,SSP1BUF ; Data Byte
556
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
818 rcall WaitMSSP
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
819 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
820 bsf SSP1CON2,PEN ; Stop condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
821 rcall WaitMSSP
556
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
822 movff battery_acumulated_charge+1,sub_a+1
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
823 movff battery_acumulated_charge+0,sub_a+0
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
824 ; and init again...
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
825
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
826 global lt2942_init
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
827 lt2942_init: ; Setup Control register B
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
828 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
829 movlw 0x01 ; Point to control reg B
467
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
830 rcall I2C_TX_GAUGE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
831 movlw b'11111000' ; Automatic conversion every two seconds
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
832 movff WREG, SSP1BUF ; Data Byte
113
heinrichsweikamp
parents: 20
diff changeset
833 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
834 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
835 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
836 bra WaitMSSP ; (And return)
113
heinrichsweikamp
parents: 20
diff changeset
837
heinrichsweikamp
parents: 20
diff changeset
838 global lt2942_get_status
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
839 lt2942_get_status: ; Read status register
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
840 bcf battery_gauge_available ; Clear flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
841 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
842 movlw 0x00 ; Point to Status reg
467
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
843 rcall I2C_TX_GAUGE
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
844 rcall I2C_RX_GAUGE
113
heinrichsweikamp
parents: 20
diff changeset
845 movff SSP1BUF,WREG
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
846 btfss WREG,7 ; 2942 found?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
847 bsf battery_gauge_available ; Yes, set flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
848 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
849 bra WaitMSSP ; (And return)
113
heinrichsweikamp
parents: 20
diff changeset
850
heinrichsweikamp
parents: 20
diff changeset
851
heinrichsweikamp
parents: 20
diff changeset
852 global lt2942_get_voltage
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
853 lt2942_get_voltage: ; Read battery voltage registers
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
854 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
855 movlw 0x08 ; Point to voltage registers
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 429
diff changeset
856 rcall I2C_TX_GAUGE
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 429
diff changeset
857 rcall I2C_RX_GAUGE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
858 bsf SSP1CON2,ACKEN ; Master acknowledge
113
heinrichsweikamp
parents: 20
diff changeset
859 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
860 movff SSP1BUF,xA+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
861 bsf SSP1CON2, RCEN ; Enable receive mode
113
heinrichsweikamp
parents: 20
diff changeset
862 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
863 movff SSP1BUF,xA+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
864 bsf SSP1CON2,PEN ; Stop condition
113
heinrichsweikamp
parents: 20
diff changeset
865 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
866
heinrichsweikamp
parents: 20
diff changeset
867 ; banksel common
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
868 ; xA:2 loaded with raw values
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
869 movlw LOW .6000
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
870 movwf xB+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
871 movlw HIGH .6000
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
872 movwf xB+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
873 call mult16x16 ; xA*xB=xC
113
heinrichsweikamp
parents: 20
diff changeset
874
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 616
diff changeset
875 ; xC+3:xC+2 -> Result in mV
113
heinrichsweikamp
parents: 20
diff changeset
876
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
877 ; Update battery voltage in mV
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 616
diff changeset
878 movff xC+3,batt_voltage+1
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 616
diff changeset
879 movff xC+2,batt_voltage+0
466
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
880
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
881 tstfsz batt_voltage+1 ; <256mV?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
882 return ; No, done.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
883 bra lt2942_init ;(and return)
113
heinrichsweikamp
parents: 20
diff changeset
884
615
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
885 global lt2942_get_temperature
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
886 lt2942_get_temperature: ; Read temperature registers
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
887 clrf i2c_temp1
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
888 movlw 0x0C ; Point to temperature registers
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
889 call I2C_TX_GAUGE
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
890 call I2C_RX_GAUGE
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
891 bsf SSP1CON2,ACKEN ; Master acknowlegde
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
892 rcall WaitMSSP
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
893 movff SSP1BUF,xA+1
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
894 bsf SSP1CON2, RCEN ; Enable recieve mode
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
895 rcall WaitMSSP
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
896 movff SSP1BUF,xA+0
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
897 bsf SSP1CON2,PEN ; Stop condition
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
898 rcall WaitMSSP
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
899
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
900 ; banksel common
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
901 ; xA:2 loaded with raw values
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
902 movlw LOW .6000
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
903 movwf xB+0
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
904 movlw HIGH .6000
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
905 movwf xB+1
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
906 call mult16x16 ;xA*xB=xC
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
907
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 616
diff changeset
908 ; xC+3:xC+2 -> Result in 0.1K
615
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
909
616
935e20e16dff work on new battery menu
heinrichsweikamp
parents: 615
diff changeset
910 movlw LOW max_allowed_battery_temp ; in 0.1K
615
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
911 movwf sub_a+0
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
912 movlw HIGH max_allowed_battery_temp
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
913 movwf sub_a+1
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 616
diff changeset
914 movff xC+3,sub_b+1
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 616
diff changeset
915 movff xC+2,sub_b+0
615
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
916 call subU16 ; sub_c = sub_a - sub_b (with UNSIGNED values)
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
917 btfss neg_flag
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
918 return ; temp ok, return
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
919 ; too hot, disable charge if currently charging
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
920 btfss cc_active
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
921 return ; Not charging, return
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
922 ; charging: Disable now
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
923 bsf charge_disable
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
924 bcf TRISE,2
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
925 bsf battery_overtemp ; =1: The battery was charged and temp was too high (Only cleared on POR)
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
926 return
113
heinrichsweikamp
parents: 20
diff changeset
927
heinrichsweikamp
parents: 20
diff changeset
928 global lt2942_get_accumulated_charge
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
929 lt2942_get_accumulated_charge: ; Read accumulated charge and compute percent
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
930 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
931 movlw 0x00 ; Point to status register
467
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
932 rcall I2C_TX_GAUGE
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
933 rcall I2C_RX_GAUGE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
934 bsf SSP1CON2,ACKEN ; Master acknowledge
113
heinrichsweikamp
parents: 20
diff changeset
935 rcall WaitMSSP
466
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
936 movff SSP1BUF,gauge_status_byte
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
937
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
938 bsf SSP1CON2, RCEN ; Enable receive mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
939 rcall WaitMSSP ; Dummy read (Control byte)
467
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
940 movf SSP1BUF,W
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
941 bsf SSP1CON2,ACKEN ; Master acknowledge
467
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
942 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
943
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
944 bsf SSP1CON2, RCEN ; Enable receive mode
113
heinrichsweikamp
parents: 20
diff changeset
945 rcall WaitMSSP
466
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
946 movff SSP1BUF,sub_a+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
947 bsf SSP1CON2,ACKEN ; Master acknowledge
467
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
948 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
949
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
950 bsf SSP1CON2, RCEN ; Enable receive mode
466
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
951 rcall WaitMSSP
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
952 movff SSP1BUF,sub_a+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
953 bsf SSP1CON2,PEN ; Stop condition
113
heinrichsweikamp
parents: 20
diff changeset
954 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
955
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
956 movff gauge_status_byte,sub_b+0 ; copy into bank common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
957 btfsc sub_b+0,0 ; =1: UVLO Event
556
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
958 rcall lt2942_init_again
113
heinrichsweikamp
parents: 20
diff changeset
959
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
960 movff sub_a+1,battery_acumulated_charge+1 ; Save raw value
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
961 movff sub_a+0,battery_acumulated_charge+0 ; Save raw value
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
962
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
963 ; Compute batt_percent
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
964 ; (charge-battery_offset)/365
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
965 movff battery_offset+0,sub_b+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
966 movff battery_offset+1,sub_b+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
967 call subU16 ; sub_c = sub_a - sub_b (with signed values)
113
heinrichsweikamp
parents: 20
diff changeset
968
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
969 clrf batt_percent ; Set to zero
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
970 btfsc neg_flag ; result negative?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
971 bra lt2942_set_to_zero_percent ; Yes, keep LT2942 at zero percent and return
113
heinrichsweikamp
parents: 20
diff changeset
972
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
973 ; > Zero, set batt_percent properly
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
974 movff sub_c+0,xA+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
975 movff sub_c+1,xA+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
976 movff battery_capacity+0,xB+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
977 movff battery_capacity+1,xB+1
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
978 call div16x16 ; xC = xA / xB with xA as remainder
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
979 movff xC+0,batt_percent
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
980 return
113
heinrichsweikamp
parents: 20
diff changeset
981
449
heinrichsweikamp
parents: 448
diff changeset
982 lt2942_set_to_zero_percent:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
983 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
984 movlw 0x02 ; Point to accumulated charge registers
449
heinrichsweikamp
parents: 448
diff changeset
985 rcall I2C_TX_GAUGE
heinrichsweikamp
parents: 448
diff changeset
986 movff battery_offset+1,SSP1BUF
heinrichsweikamp
parents: 448
diff changeset
987 rcall WaitMSSP
heinrichsweikamp
parents: 448
diff changeset
988 rcall I2C_WaitforACK
heinrichsweikamp
parents: 448
diff changeset
989 movff battery_offset+0,SSP1BUF
heinrichsweikamp
parents: 448
diff changeset
990 rcall WaitMSSP
heinrichsweikamp
parents: 448
diff changeset
991 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
992 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
993 bra WaitMSSP ; (and return)
449
heinrichsweikamp
parents: 448
diff changeset
994
113
heinrichsweikamp
parents: 20
diff changeset
995 global lt2942_charge_done
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
996 lt2942_charge_done: ; Reset accumulating registers to 0xFFFF
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
997 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
998 movlw 0x02 ; Point to accumulated charge registers
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 429
diff changeset
999 rcall I2C_TX_GAUGE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1000 setf SSP1BUF ; Data Byte
113
heinrichsweikamp
parents: 20
diff changeset
1001 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
1002 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1003 setf SSP1BUF ; Data Byte
113
heinrichsweikamp
parents: 20
diff changeset
1004 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
1005 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1006 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1007 bra WaitMSSP ; (and return)
113
heinrichsweikamp
parents: 20
diff changeset
1008
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1009 I2C_TX_GAUGE: ; Sends a byte to the LT2942 Gauge IC
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1010 movwf i2c_temp2 ; Data byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1011 bsf SSP1CON2,SEN ; Start condition
113
heinrichsweikamp
parents: 20
diff changeset
1012 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1013 movlw b'11001000' ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1014 movwf SSP1BUF ; control byte
113
heinrichsweikamp
parents: 20
diff changeset
1015 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
1016 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1017 movf i2c_temp2,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1018 bra I2C_TX ; (and return)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1019
113
heinrichsweikamp
parents: 20
diff changeset
1020 I2C_RX_GAUGE:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1021 bsf SSP1CON2,SEN ; Start condition
113
heinrichsweikamp
parents: 20
diff changeset
1022 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1023 movlw b'11001001' ; Address byte + Read bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1024 movwf SSP1BUF ; control byte
113
heinrichsweikamp
parents: 20
diff changeset
1025 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
1026 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1027 bsf SSP1CON2, RCEN ; Enable receive mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1028 bra WaitMSSP ; (and return)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1029
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1030
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1031 ;-----------------------------------------------------------------------------
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1032 ; Transmitter Functions
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1033
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1034 IFDEF _rx_functions
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1035
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1036 global I2C_probe_OSTC_rx
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1037 I2C_probe_OSTC_rx:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1038 movlw .5
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1039 movwf lo_temp
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1040 I2C_probe_OSTC_rx_1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1041 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1042 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1043 movlw 0x50 ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1044 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1045 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1046 btfss SSP1CON2,ACKSTAT ; ACK?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1047 bsf ostc_rx_present ; ACK sent - OSTC_RX present!
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1048 bsf SSP1CON2,PEN ; Stop condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1049 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1050 btfss ostc_rx_present ; Do we have the RX?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1051 return ; No, Done.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1052 WAITMS .1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1053 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1054 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1055 movlw 0x50 ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1056 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1057 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1058 rcall I2C_WaitforACK
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1059 movlw 0x1B
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1060 movwf SSP1BUF ; Data Byte (Get firmware)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1061 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1062 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1063 bsf SSP1CON2,PEN ; Stop condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1064 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1065 WAITMS .1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1066 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1067 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1068 movlw 0x51 ; Address byte + Read bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1069 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1070 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1071 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1072 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1073 movff SSP1BUF,rx_firmware+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1074 bsf SSP1CON2,ACKEN ; Master acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1075 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1076
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1077 ; last byte in read from RX circuity always with a NACK!
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1078 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1079 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1080 movff SSP1BUF,rx_firmware+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1081 bsf SSP1CON2,ACKDT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1082 bsf SSP1CON2,ACKEN ; Master NOT acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1083 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1084 bcf SSP1CON2,ACKDT ; Reset ACKDT flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1085 bsf SSP1CON2,PEN ; Stop condition
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1086 rcall WaitMSSP
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1087
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1088 ; test for RX part not being ready during this read
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1089 movff rx_firmware+1,i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1090 movlw .147
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1091 cpfseq i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1092 bra I2C_probe_OSTC_rx_2 ; not equal
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1093 movff rx_firmware+0,i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1094 movlw .27
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1095 cpfseq i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1096 bra I2C_probe_OSTC_rx_2 ; not equal
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1097 bsf active_reset_ostc_rx
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1098 WAITMS .5
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1099 bcf active_reset_ostc_rx
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1100 WAITMS .250
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1101 WAITMS .250
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1102 clrf i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1103 decfsz lo_temp,F ; try max. 5 times
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1104 bra I2C_probe_OSTC_rx_1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1105 bcf ostc_rx_present ; Clear flag. Something is wrong
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1106 I2C_probe_OSTC_rx_2:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1107 clrf i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1108 return
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1109
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1110
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1111 global I2C_get_tankdata
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1112 I2C_get_tankdata:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1113 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1114 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1115 movlw 0x50 ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1116 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1117 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1118 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1119 movlw 0x1E ; Read buffer2 (48 Bytes)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1120 movwf SSP1BUF ; Data Byte
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1121 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1122 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1123 bsf SSP1CON2,PEN ; Stop condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1124 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1125 WAITMS .1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1126
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1127 ; read 48 bytes
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1128 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1129 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1130 movlw 0x51 ; Address byte + read bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1131 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1132 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1133 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1134 movlw .47 ; 47 with ACK + 1 w/o ACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1135 movwf i2c_temp2
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1136 lfsr FSR2,rx_buffer+0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1137 I2C_get_tankdata_loop_read:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1138 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1139 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1140 movff SSP1BUF,POSTINC2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1141 bcf SSP1CON2,ACKDT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1142 bsf SSP1CON2,ACKEN ; Master acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1143 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1144 decfsz i2c_temp2,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1145 bra I2C_get_tankdata_loop_read
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1146
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1147 ; 1 w/o ACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1148 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1149 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1150 movff SSP1BUF,POSTINC2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1151 bsf SSP1CON2,ACKDT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1152 bsf SSP1CON2,ACKEN ; Master NOT acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1153 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1154 bcf SSP1CON2,ACKDT ; Reset ACKDT flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1155
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1156 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1157 bra WaitMSSP ;(and return)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1158
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1159
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1160 global I2C_update_OSTC_rx
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1161 I2C_update_OSTC_rx: ; 992*64byte master loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1162 bcf i2c_error_flag ; clear error flag
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1163 ; write 64 bytes
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1164 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1165 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1166 movlw 0x50 ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1167 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1168 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1169 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1170 lfsr FSR2,buffer ; send buffer for verify
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1171 movlw .64
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1172 movwf i2c_temp2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1173 I2C_update_OSTC_loop: ; 64byte flash page loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1174 movff up,POSTINC2 ; store for verify
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1175 movff up,SSP1BUF
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1176 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1177 rcall I2C_WaitforACK
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1178 call ext_flash_read_block ; Read one byte
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1179 movwf up ; prepare for transmit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1180 decfsz i2c_temp2,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1181 bra I2C_update_OSTC_loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1182 bsf SSP1CON2,PEN ; Stop condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1183 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1184 WAITMS .1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1185
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1186 ; read 64 bytes
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1187 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1188 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1189 movlw 0x51 ; Address byte + read bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1190 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1191 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1192 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1193 lfsr FSR2,buffer ; send buffer for verify
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1194 movlw .63 ; 63 with ACK + 1 w/o ACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1195 movwf i2c_temp2
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1196 I2C_update_OSTC_loop_read:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1197 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1198 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1199 movf SSP1BUF,W
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1200 cpfseq POSTINC2 ; compare read-back with original
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1201 bsf i2c_error_flag ; Not equal, set flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1202 bcf SSP1CON2,ACKDT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1203 bsf SSP1CON2,ACKEN ; Master acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1204 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1205 decfsz i2c_temp2,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1206 bra I2C_update_OSTC_loop_read
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1207
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1208 ; 1 w/o ACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1209 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1210 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1211 movf SSP1BUF,W
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1212 cpfseq POSTINC2 ; compare read-back with original
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1213 bsf i2c_error_flag ; Not equal, set flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1214 bsf SSP1CON2,ACKDT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1215 bsf SSP1CON2,ACKEN ; Master NOT acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1216 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1217 bcf SSP1CON2,ACKDT ; Reset ACKDT flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1218
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1219 bsf SSP1CON2,PEN ; Stop condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1220 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1221 WAITMS .1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1222
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1223 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1224 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1225 movlw 0x50 ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1226 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1227 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1228 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1229 movlw 0x1F ; Write command!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1230 movwf SSP1BUF ; Data Byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1231 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1232 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1233 bsf SSP1CON2,PEN ; Stop condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1234 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1235 WAITMS .5 ; Required waiting time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1236
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1237 btfss i2c_error_flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1238 retlw .0 ; All ok
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1239 retlw .255 ; an error occurred
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1240
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1241 ENDIF
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1242
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1243 END