annotate src/i2c.asm @ 608:d866684249bd

work on 2.99 stable
author heinrichsweikamp
date Mon, 07 Jan 2019 21:13:43 +0100
parents ca4556fb60b9
children b87f23fae743
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 WaitMSSP:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
52 decfsz i2c_temp1,F ; check for timeout during I2C action
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
53 bra WaitMSSP2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
54 bra I2CFail ; timeout occurred
0
heinrichsweikamp
parents:
diff changeset
55 WaitMSSP2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
56 btfss PIR1,SSP1IF
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
57 bra WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
58 clrf i2c_temp1
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
59 bcf PIR1,SSP1IF
0
heinrichsweikamp
parents:
diff changeset
60 return
heinrichsweikamp
parents:
diff changeset
61
heinrichsweikamp
parents:
diff changeset
62 I2C_WaitforACK:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
63 btfss SSP1CON2,ACKSTAT ; checks for ACK bit from slave
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
64 return
0
heinrichsweikamp
parents:
diff changeset
65 I2CFail:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
66 rcall I2CReset ; I2C Reset
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
67 bcf PIR1,SSP1IF
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
68 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
69 bsf i2c_error_flag ; set error flag
0
heinrichsweikamp
parents:
diff changeset
70 return
heinrichsweikamp
parents:
diff changeset
71
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
72 I2CReset: ; something went wrong (slave holds SDA low?)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
73 clrf SSP1CON1 ; wake-up slave and reset entire module
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
74 clrf SSP1CON2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
75 clrf SSP1STAT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
76 bcf TRISC,3 ; SCL OUTPUT
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
77 bsf TRISC,4 ; SDA input
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
78 bcf PORTC,3
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
79 movlw d'9'
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
80 movwf i2c_temp1 ; clock-out 9 clock cycles manually
0
heinrichsweikamp
parents:
diff changeset
81 I2CReset_1:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
82 bsf PORTC,3 ; SCL = 1
0
heinrichsweikamp
parents:
diff changeset
83 nop
heinrichsweikamp
parents:
diff changeset
84 nop
heinrichsweikamp
parents:
diff changeset
85 nop
heinrichsweikamp
parents:
diff changeset
86 nop
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
87 btfsc PORTC,4 ; SDA = 1 ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
88 bra I2CReset_2 ; YES - =1, SDA has been released from slave
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
89 bcf PORTC,3 ; NO - set SCL = 0
0
heinrichsweikamp
parents:
diff changeset
90 nop
heinrichsweikamp
parents:
diff changeset
91 nop
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
92 bcf PORTC,3
0
heinrichsweikamp
parents:
diff changeset
93 nop
heinrichsweikamp
parents:
diff changeset
94 nop
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
95 decfsz i2c_temp1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
96 bra I2CReset_1 ; check for nine clock cycles
0
heinrichsweikamp
parents:
diff changeset
97 I2CReset_2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
98 bsf TRISC,3 ; SCL Input
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
99 clrf SSP1CON1 ; setup I²C mode
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
100 WAITMS d'10' ; reset-timeout for I2C devices
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
101 movlw b'00000000' ; with slew rate control
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
102 movwf SSP1STAT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
103 movlw b'00101000'
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
104 movwf SSP1CON1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
105 movlw b'00000000'
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
106 movwf SSP1CON2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
107 movlw 0x27
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
108 movwf SSP1ADD
0
heinrichsweikamp
parents:
diff changeset
109 return
heinrichsweikamp
parents:
diff changeset
110
heinrichsweikamp
parents:
diff changeset
111 I2C_TX:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
112 movwf SSP1BUF
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
113 rcall WaitMSSP
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
114 bra I2C_WaitforACK ; returns...
0
heinrichsweikamp
parents:
diff changeset
115
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
116 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
117 rcall I2C_OneByteRX ; get one byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
118 movff SSP1BUF,hi ; data byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
119 rcall I2C_OneByteRX ; get one byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
120 movff SSP1BUF,lo ; data byte
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
121 I2C_TwoBytesRX_div16_2: ; divide lo:hi/16 (signed) only
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
122 bcf STATUS,C
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
123 btfsc hi,7 ; copy sign bit to carry
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
124 bsf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
125 rrcf hi ; /2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
126 rrcf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
127 I2C_TwoBytesRX_div8_2: ; divide lo:hi/8 (signed) only
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
128 bcf STATUS,C
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
129 btfsc hi,7 ; copy sign bit to carry
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
130 bsf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
131 rrcf hi ; /4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
132 rrcf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
133 bcf STATUS,C
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
134 btfsc hi,7 ; copy sign bit to carry
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
135 bsf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
136 rrcf hi ; /8
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
137 rrcf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
138 bcf STATUS,C
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
139 btfsc hi,7 ; copy sign bit to carry
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
140 bsf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
141 rrcf hi ; /16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
142 rrcf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
143 return
0
heinrichsweikamp
parents:
diff changeset
144
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
145 global I2C_RX_accelerometer
0
heinrichsweikamp
parents:
diff changeset
146 I2C_RX_accelerometer:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
147 btfsc compass_type2 ; compass2 ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
148 bra I2C_RX_accelerometer_compass2 ; YES
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
149 btfsc compass_type ; compass1 ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
150 bra I2C_RX_accelerometer_compass1 ; YES
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
151 I2C_RX_accelerometer_compass0:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
152 bsf SSP1CON2,SEN ; start condition
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
153 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
154 movlw 0x38 ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
155 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
156 movlw 0x00
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
157 rcall I2C_TX
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
158 bsf SSP1CON2,RSEN ; repeated start condition
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
159 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
160 movlw 0x39 ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
161 rcall I2C_TX
0
heinrichsweikamp
parents:
diff changeset
162
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
163 rcall I2C_OneByteRX ; get status byte
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
164 movf SSP1BUF,W
158
683321c09cfa nicer boot into surfacemode
heinrichsweikamp
parents: 113
diff changeset
165
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
166 ; Non-flipped screen:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
167 ; Chip orientation on the PCB requires
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
168 ; Original = corrected
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
169 ; x = -x
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
170 ; y = -y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
171 ; z = -z
0
heinrichsweikamp
parents:
diff changeset
172
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
173 ; Flipped screen:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
174 ; Chip orientation on the PCB requires
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
175 ; Original = corrected
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
176 ; x = x
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
177 ; y = y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
178 ; z = -z
166
30ebaf72170d BUGFIX: Flip compass with flipped screen, too
heinrichsweikamp
parents: 158
diff changeset
179
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
180 rcall I2C_TwoBytesRX_div16 ; get two bytes and divide /16 (signed)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
181 btfsc flip_screen ; 180° rotation ?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
182 bra I2C_RX_accelerometer2 ; YES
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
183 comf hi ; 16 bit sign change
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
184 negf lo
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
185 btfsc STATUS,C ; carry to propagate ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
186 incf hi,F ; YES - do it
166
30ebaf72170d BUGFIX: Flip compass with flipped screen, too
heinrichsweikamp
parents: 158
diff changeset
187 I2C_RX_accelerometer2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
188 movff lo,accel_DX+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
189 movff hi,accel_DX+1 ; Copy result
0
heinrichsweikamp
parents:
diff changeset
190
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
191 rcall I2C_TwoBytesRX_div16 ; Get two bytes and divide /16 (signed)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
192 btfsc flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
193 bra I2C_RX_accelerometer3 ; Yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
194 comf hi ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
195 negf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
196 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
197 incf hi,F ; YES: do it.
166
30ebaf72170d BUGFIX: Flip compass with flipped screen, too
heinrichsweikamp
parents: 158
diff changeset
198 I2C_RX_accelerometer3:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
199 movff lo,accel_DY+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
200 movff hi,accel_DY+1 ; Copy result
0
heinrichsweikamp
parents:
diff changeset
201
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
202 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
203 movff SSP1BUF,hi ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
204 bsf SSP1CON2, RCEN ; Enable receive mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
205 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
206 ; 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
207 movff SSP1BUF,lo ; Data Byte
0
heinrichsweikamp
parents:
diff changeset
208
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
209 rcall I2C_TwoBytesRX_div16_2 ; divide lo:hi/16 (signed) only
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
210 comf hi ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
211 negf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
212 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
213 incf hi,F ; YES: do it.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
214 movff lo,accel_DZ+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
215 movff hi,accel_DZ+1 ; Copy result
0
heinrichsweikamp
parents:
diff changeset
216
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
217 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
218 bra WaitMSSP ; (And return)
0
heinrichsweikamp
parents:
diff changeset
219
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
220 I2C_RX_accelerometer_compass1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
221 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
222 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
223 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
224 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
225 movlw b'10101000' ; 0x28 with auto-increment (MSB=1)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
226 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
227 bsf SSP1CON2,RSEN ; Repeated start condition (!)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
228 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
229 movlw 0x3D ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
230 I2C_RX_accelerometer_compass1_xx: ; compass2 continues here...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
231 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
232
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
233 ; Non-flipped screen:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
234 ; Chip orientation on the PCB requires
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
235 ; Original = Corrected
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
236 ; x = -x (Compass 1)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
237 ; x = x (Compass 2)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
238 ; y = -y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
239 ; z = -z
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
240
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
241 ; Flipped screen:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
242 ; Chip orientation on the PCB requires
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
243 ; Original = Corrected
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
244 ; x = x (Compass 1)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
245 ; x = -x (Compass 2)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
246 ; y = y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
247 ; z = -z
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
248
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
249 ; Dump the accelerator data
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
250 rcall I2C_OneByteRX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
251 movff SSP1BUF,lo ; accel_DX+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
252 rcall I2C_OneByteRX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
253 movff SSP1BUF,hi ;accel_DX+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
254 rcall I2C_TwoBytesRX_div16_2 ; divide lo:hi/16 (signed) only
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
255 btfss compass_type2 ; compass 2?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
256 bra I2C_RX_accelerometer1_c1 ; No, compass 1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
257 ; compass 2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
258 btfss flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
259 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
260 ; flipped compass 2, negate x
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
261 comf hi ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
262 negf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
263 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
264 incf hi,F ; YES: do it.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
265 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
266
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
267 I2C_RX_accelerometer1_c1:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
268 btfsc flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
269 bra I2C_RX_accelerometer2_c1 ; Yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
270 ; non-flipped compass 1, negate x
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
271 comf hi ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
272 negf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
273 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
274 incf hi,F ; YES: do it.
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
275 I2C_RX_accelerometer2_c1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
276 ; flipped compass 1, non-flipped compass 2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
277 movff lo,accel_DX+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
278 movff hi,accel_DX+1 ; Copy result
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
279 rcall I2C_OneByteRX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
280 movff SSP1BUF,lo ; accel_DY+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
281 rcall I2C_OneByteRX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
282 movff SSP1BUF,hi ; accel_DY+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
283
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
284 rcall I2C_TwoBytesRX_div16_2 ; divide lo:hi/16 (signed) only
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
285 btfsc flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
286 bra I2C_RX_accelerometer3_c1 ; Yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
287 comf hi ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
288 negf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
289 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
290 incf hi,F ; YES: do it.
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
291 I2C_RX_accelerometer3_c1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
292 movff lo,accel_DY+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
293 movff hi,accel_DY+1 ; Copy result
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
294
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
295 rcall I2C_OneByteRX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
296 movff SSP1BUF,lo ;accel_DZ+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
297 bsf SSP1CON2, RCEN ; Enable receive mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
298 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
299 ; 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
300 movff SSP1BUF,hi ;accel_DZ+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
301 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
302 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
303 rcall I2C_TwoBytesRX_div16_2 ; divide lo:hi/16 (signed) only
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
304 comf hi ; 16bit sign change for Z
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
305 negf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
306 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
307 incf hi,F ; YES: do it.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
308 movff lo,accel_DZ+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
309 movff hi,accel_DZ+1 ; Copy result
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
310 return
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
311
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
312 I2C_RX_accelerometer_compass2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
313 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
314 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
315 movlw 0x32 ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
316 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
317 movlw b'10101000' ; 0x28 with auto-increment (MSB=1)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
318 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
319 bsf SSP1CON2,RSEN ; Repeated start condition (!)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
320 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
321 movlw 0x33 ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
322 bra I2C_RX_accelerometer_compass1_xx
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
323
0
heinrichsweikamp
parents:
diff changeset
324 I2C_OneByteRX:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
325 bsf SSP1CON2,RCEN ; Enable receive mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
326 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
327 bsf SSP1CON2,ACKEN ; Master acknowledge
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
328 bra WaitMSSP ; And return!
0
heinrichsweikamp
parents:
diff changeset
329
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
330 global I2C_RX_compass
0
heinrichsweikamp
parents:
diff changeset
331 I2C_RX_compass:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
332 btfsc compass_type2 ; compass2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
333 bra I2C_RX_compass2 ; yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
334 btfsc compass_type ; compass1?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
335 bra I2C_RX_compass1 ; yes
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
336 I2C_RX_compass0:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
337 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
338 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
339 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
340 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
341 movlw 0x03
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
342 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
343 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
344 rcall WaitMSSP
0
heinrichsweikamp
parents:
diff changeset
345
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
346 bcf PIR1,SSP1IF
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
347 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
348 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
349 movlw 0x3D ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
350 rcall I2C_TX
0
heinrichsweikamp
parents:
diff changeset
351
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
352 ; Compass IC sends data in following order:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
353 ; x MSB
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
354 ; x LSB
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
355 ; z MSB
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
356 ; z LSB
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
357 ; y MSB
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
358 ; y LSB
0
heinrichsweikamp
parents:
diff changeset
359
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
360 ; Non-flipped screen
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
361 ; Chip orientation on the PCB requires
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
362 ; Original = Corrected
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
363 ; x = -y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
364 ; z = z
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
365 ; y = x
0
heinrichsweikamp
parents:
diff changeset
366
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
367 ; Flipped screen
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
368 ; Chip orientation on the PCB requires
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
369 ; Original = Corrected
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
370 ; x = y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
371 ; z = z
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
372 ; y = -x
166
30ebaf72170d BUGFIX: Flip compass with flipped screen, too
heinrichsweikamp
parents: 158
diff changeset
373
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
374 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
375 movff SSP1BUF,compass_DY+1 ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
376 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
377 movff SSP1BUF,compass_DY+0 ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
378 btfsc flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
379 bra I2C_RX_compass0_2 ; Yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
380 banksel compass_DY
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
381 comf compass_DY+1 ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
382 negf compass_DY+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
383 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
384 incf compass_DY+1,F ; YES: do it.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
385 I2C_RX_compass0_2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
386 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
387 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
388 movff SSP1BUF,compass_DZ+1 ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
389 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
390 movff SSP1BUF,compass_DZ+0 ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
391 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
392 movff SSP1BUF,compass_DX+1 ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
393 bsf SSP1CON2, RCEN ; Enable receive mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
394 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
395 movff SSP1BUF,compass_DX+0 ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
396 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
397 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
398 btfss flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
399 return ; No, done.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
400 ; Yes, flip X
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
401 banksel compass_DX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
402 comf compass_DX+1 ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
403 negf compass_DX+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
404 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
405 incf compass_DX+1,F ; YES: do it.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
406 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
407 return
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
408
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
409 I2C_RX_compass1: ; New compass
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
410 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
411 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
412 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
413 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
414 movlw b'10001000' ; 0x08 with auto-increment (MSB=1)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
415 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
416 bsf SSP1CON2,RSEN ; Repeated start condition (!)
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 movlw 0x3D ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
419 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
420 ;rcall WaitMSSP ; Needed? (mH)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
421 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
422 movff SSP1BUF,lo ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
423 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
424 movff SSP1BUF,hi ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
425 rcall I2C_TwoBytesRX_div8_2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
426 movff lo,compass_DX+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
427 movff hi,compass_DX+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
428 btfss flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
429 bra I2C_RX_compass1_1 ; Yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
430 ; Yes, flip X
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
431 banksel compass_DX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
432 comf compass_DX+1 ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
433 negf compass_DX+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
434 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
435 incf compass_DX+1,F ; YES: do it.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
436 banksel common
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
437 I2C_RX_compass1_1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
438 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
439 movff SSP1BUF,lo ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
440 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
441 movff SSP1BUF,hi ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
442 rcall I2C_TwoBytesRX_div8_2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
443 movff lo,compass_DY+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
444 movff hi,compass_DY+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
445 btfss flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
446 bra I2C_RX_compass1_2 ; Yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
447 ; Yes, flip Y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
448 banksel compass_DY
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
449 comf compass_DY+1 ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
450 negf compass_DY+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
451 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
452 incf compass_DY+1,F ; YES: do it.
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
453 I2C_RX_compass1_2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
454 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
455 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
456 movff SSP1BUF,lo ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
457 bsf SSP1CON2, RCEN ; Enable receive mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
458 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
459 movff SSP1BUF,hi ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
460 rcall I2C_TwoBytesRX_div8_2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
461 movff lo,compass_DZ+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
462 movff hi,compass_DZ+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
463 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
464 bra WaitMSSP ;(And return)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
465
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
466 I2C_RX_compass2: ; newest compass
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
467 bsf SSP1CON2,SEN ; Start condition
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 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
470 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
471 movlw 0xE8 ; 0x68 with auto-increment (MSB=1)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
472 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
473 bsf SSP1CON2,RSEN ; Repeated start condition (!)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
474 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
475 movlw 0x3D ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
476 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
477 ; rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
478 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
479 movff SSP1BUF,lo ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
480 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
481 movff SSP1BUF,hi ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
482 ; rcall I2C_TwoBytesRX_div8_2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
483 btfsc flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
484 bra I2C_RX_compass2_1 ; Yes, do nothing with X
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
485 ; No, flip X
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
486 comf hi ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
487 negf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
488 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
489 incf hi,F ; YES: do it.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
490 I2C_RX_compass2_1:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
491 movff lo,compass_DX+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
492 movff hi,compass_DX+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
493 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
494 movff SSP1BUF,lo ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
495 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
496 movff SSP1BUF,hi ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
497 ; rcall I2C_TwoBytesRX_div8_2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
498 btfss flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
499 bra I2C_RX_compass2_2 ; No, do nothing with Y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
500 ; Yes, flip Y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
501 comf hi ; 16bit sign change.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
502 negf lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
503 btfsc STATUS,C ; Carry to propagate ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
504 incf hi,F ; YES: do it.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
505 I2C_RX_compass2_2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
506 movff lo,compass_DY+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
507 movff hi,compass_DY+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
508 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
509 movff SSP1BUF,lo ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
510 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
511 movff SSP1BUF,hi ; Data Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
512 ; rcall I2C_TwoBytesRX_div8_2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
513 movff lo,compass_DZ+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
514 movff hi,compass_DZ+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
515 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
516 bra WaitMSSP ;(And return)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
517
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
518
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
519 global I2C_init_compass
0
heinrichsweikamp
parents:
diff changeset
520 I2C_init_compass:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
521 bsf compass_enabled
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
522 bcf compass_type2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
523 ; probe compass 2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
524 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
525 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
526 movlw 0x32 ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
527 movwf SSP1BUF ; control byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
528 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
529 btfss SSP1CON2,ACKSTAT ; ACK?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
530 bsf compass_type2 ; ACK send. compass2 present
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
531 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
532 rcall WaitMSSP
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
533
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
534 btfsc compass_type2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
535 bra I2C_init_compass2 ; Compass2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
536 ; Check for compass0 or compass1...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
537 bsf compass_type ; set flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
538 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
539 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
540 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
541 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
542 movlw 0x0F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
543 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
544 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
545 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
546 bcf PIR1,SSP1IF
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
547 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
548 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
549 movlw 0x3D ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
550 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
551 rcall I2C_OneByteRX ; Get one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
552 movlw 0x49 ; 0x49 = Compass1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
553 cpfseq SSP1BUF
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
554 bcf compass_type ; clear flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
555 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
556 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
557
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
558 btfsc compass_type ; compass1?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
559 bra I2C_init_compass1 ; yes
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
560 ; init compass0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
561 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
562 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
563 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
564 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
565 movlw 0x00
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
566 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
567 ; movlw b'01101001' ; ConfigA: 3Hz, 8 Samples averaged, Test Mode (Positive Bias)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
568 movlw b'01101000' ; ConfigA: 3Hz, 8 Samples averaged
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
569 rcall I2C_TX
20
9b7dd3103545 minor cleanup
heinrichsweikamp
parents: 18
diff changeset
570 I2C_init_compass_common:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
571 movff opt_compass_gain,i2c_temp1 ; 0-7 (230LSB/Gauss to 1370LSB/Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
572 swapf i2c_temp1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
573 comf i2c_temp1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
574 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
575 rlcf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
576 movf i2c_temp1,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
577 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
578 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
579 movlw b'00000000' ; Continuous Mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
580 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
581 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
582 bra WaitMSSP ; (And return)
0
heinrichsweikamp
parents:
diff changeset
583
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
584 I2C_init_compass1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
585 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
586 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
587 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
588 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
589 movlw 0x9F ; 1F with auto-increment (MSB=1)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
590 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
591 movlw b'00000000' ; CTRL0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
592 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
593 movlw b'00101111' ; CTRL1 (6,25Hz, BDU=0, x,y,z = ON)
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 b'11000000' ; CTRL2 (50Hz, +/-2g,
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'00000000' ; CTRL3
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'00000000' ; CTRL4
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'01100100' ; CTRL5 HIGH res, 6,25Hz
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
602 rcall I2C_TX
429
4b93354b7738 hardware_flag handling
heinrichsweikamp
parents: 427
diff changeset
603 init_compass1_common:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
604 movff opt_compass_gain,i2c_temp1 ; 0-7 (230LSB/Gauss to 1370LSB/Gauss) +++
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
605 movlw b'01100000' ; CTRL6 Full scale (+/-12 Gauss -> 2730LSB/Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
606 dcfsnz i2c_temp1,F ; = 1?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
607 movlw b'01100000' ; Yes, CTRL6 Full scale (+/-12 Gauss -> 2730LSB/Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
608 dcfsnz i2c_temp1,F ; = 2?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
609 movlw b'01000000' ; Yes, CTRL6 (+/-8 Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
610 dcfsnz i2c_temp1,F ; = 3?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
611 movlw b'01000000' ; Yes, CTRL6 (+/-8 Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
612 dcfsnz i2c_temp1,F ; = 4?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
613 movlw b'00100000' ; Yes, CTRL6 (+/-4 Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
614 dcfsnz i2c_temp1,F ; = 5?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
615 movlw b'00100000' ; Yes, CTRL6 (+/-4 Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
616 dcfsnz i2c_temp1,F ; = 6?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
617 movlw b'00000000' ; Yes, CTRL6 (+/-2 Gauss)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
618 dcfsnz i2c_temp1,F ; = 7?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
619 movlw b'00000000' ; Yes, CTRL6 (+/-2 Gauss)
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 b'00000000' ; CTRL7 Continuous Mode
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 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
624 bra WaitMSSP ; (And return)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
625
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
626 I2C_init_compass2:
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
627 bsf SSP1CON2,SEN ; Start condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
628 rcall WaitMSSP
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
629 movlw 0x3C ; address
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
630 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
631 movlw 0xE0 ; 0x60 with auto-increment (MSB=1)
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
632 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
633 movlw b'00000000' ; CFG_REG_A_M (10Hz, Continuous) 0x60
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
634 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
635 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
636 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
637 movlw b'00000000' ; CFG_REG_C_M BDU=0 0x62
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
638 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
639 bsf SSP1CON2,PEN ; Stop condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
640 bra WaitMSSP ;(And return)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
641
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
642
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
643 global I2C_sleep_compass
0
heinrichsweikamp
parents:
diff changeset
644 I2C_sleep_compass:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
645 bcf compass_enabled
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
646 btfsc compass_type2 ; compass2?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
647 bra I2C_sleep_compass2 ; yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
648 btfsc compass_type ; compass1?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
649 bra I2C_sleep_compass1 ; yes
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
650 I2C_sleep_compass0:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
651 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
652 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
653 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
654 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
655 movlw 0x00
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
656 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
657 movlw b'01101000' ; ConfigA
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
658 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
659 movlw b'00100000' ; ConfigB
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
660 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
661 movlw b'00000010' ; Idle Mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
662 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
663 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
664 bra WaitMSSP ; (And return)
0
heinrichsweikamp
parents:
diff changeset
665
427
ceb1b7329dce add code for new compass chip
heinrichsweikamp
parents: 275
diff changeset
666 I2C_sleep_compass1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
667 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
668 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
669 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
670 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
671 movlw 0x20 ; CTRL_REG1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
672 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
673 movlw b'00000000' ; data for CTRL_REG1: acceleration sensor Power-down mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
674 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
675 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
676 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
677 bsf SSP1CON2,SEN ; Start condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
678 rcall WaitMSSP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
679 movlw 0x3C ; address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
680 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
681 movlw 0x26 ; CTRL_REG7
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
682 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
683 movlw b'00000010' ; data for CTRL_REG7: magnetic sensor Power-down mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
684 rcall I2C_TX
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
685 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
686 bra WaitMSSP ;(And return)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
687
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
688 I2C_sleep_compass2:
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
689 ; magnetic
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
690 bsf SSP1CON2,SEN ; Start condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
691 rcall WaitMSSP
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
692 movlw 0x3C ; address
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
693 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
694 movlw 0xE0 ; 0x60 with auto-increment (MSB=1)
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
695 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
696 movlw b'00000011' ; CFG_REG_A_M (Idle mode) 0x60
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
697 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
698 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
699 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
700 movlw b'01010001' ; CFG_REG_C_M 0x62
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
701 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
702 movlw b'00000000' ; INT_CTRL_REG_M 0x63
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
703 rcall I2C_TX
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
704
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
705 bsf SSP1CON2,PEN ; Stop condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
706 bra WaitMSSP ; (And return)
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
707
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
708 I2C_sleep_accelerometer2:
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
709 ; accelerometer
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
710 bsf SSP1CON2,SEN ; Start condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
711 rcall WaitMSSP
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
712 movlw 0x32 ; address
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
713 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
714 movlw 0x9F ; 1F with auto-increment (MSB=1)
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
715 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
716 movlw b'00000000' ; TEMP_CFG_REG_A (Temp sensor off) 0x1F
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
717 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
718 movlw b'00000000' ; CTRL_REG1_A (All off) 0x20
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
719 rcall I2C_TX
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
720 bsf SSP1CON2,PEN ; Stop condition
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
721 bra WaitMSSP ; (And return)
0
heinrichsweikamp
parents:
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
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
875 ; divide xC (32bit)/65535 for result in mV (16bit)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
876 movlw .16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
877 movwf i2c_temp1
113
heinrichsweikamp
parents: 20
diff changeset
878 lt2942_get_voltage2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
879 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
880 rrcf xC+3,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
881 rrcf xC+2,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
882 rrcf xC+1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
883 rrcf xC+0,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
884 decfsz i2c_temp1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
885 bra lt2942_get_voltage2
113
heinrichsweikamp
parents: 20
diff changeset
886
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
887 ; Update battery voltage in mV
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
888 movff xC+1,batt_voltage+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
889 movff xC+0,batt_voltage+0
466
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
890
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
891 tstfsz batt_voltage+1 ; <256mV?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
892 return ; No, done.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
893 bra lt2942_init ;(and return)
113
heinrichsweikamp
parents: 20
diff changeset
894
heinrichsweikamp
parents: 20
diff changeset
895 ; global lt2942_get_temperature
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
896 ;lt2942_get_temperature: ; Read temperature registers
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
897 ; clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
898 ; movlw 0x0C ; Point to temperature registers
113
heinrichsweikamp
parents: 20
diff changeset
899 ; call I2C_TX_GAUGE
heinrichsweikamp
parents: 20
diff changeset
900 ; call I2C_RX
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
901 ; bsf SSP1CON2,ACKEN ; Master acknowledge
113
heinrichsweikamp
parents: 20
diff changeset
902 ; rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
903 ; movff SSP1BUF,xA+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
904 ; bsf SSP1CON2, RCEN ; Enable receive mode
113
heinrichsweikamp
parents: 20
diff changeset
905 ; rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
906 ; movff SSP1BUF,xA+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
907 ; bsf SSP1CON2,PEN ; Stop condition
113
heinrichsweikamp
parents: 20
diff changeset
908 ; rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
909 ;
heinrichsweikamp
parents: 20
diff changeset
910 ;; banksel common
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
911 ; ; xA:2 loaded with raw values
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
912 ; movlw LOW .6000
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
913 ; movwf xB+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
914 ; movlw HIGH .6000
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
915 ; movwf xB+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
916 ; call mult16x16 ; xA*xB=xC
113
heinrichsweikamp
parents: 20
diff changeset
917 ;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
918 ; ; devide xC (32bit)/65535 for result in 0.1K (16bit)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
919 ; movlw .16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
920 ; movwf i2c_temp1
113
heinrichsweikamp
parents: 20
diff changeset
921 ;lt2942_get_temperature2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
922 ; bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
923 ; rrcf xC+3,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
924 ; rrcf xC+2,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
925 ; rrcf xC+1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
926 ; rrcf xC+0,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
927 ; decfsz i2c_temp1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
928 ; bra lt2942_get_temperature2
113
heinrichsweikamp
parents: 20
diff changeset
929 ;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
930 ; movff xC+1,sub_a+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
931 ; movff xC+0,sub_a+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
932 ; movlw LOW .2731 ; Kelvin to Celsius offset
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
933 ; movwf sub_b+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
934 ; movlw HIGH .2731 ; Kelvin to Celsius offset
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
935 ; movwf sub_b+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
936 ; call subU16 ; sub_c = sub_a - sub_b (with UNSIGNED values)
113
heinrichsweikamp
parents: 20
diff changeset
937 ;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
938 ; ; Update batttery_temperature in 0.1°C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
939 ; movff sub_c+1,battery_temperature+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
940 ; movff sub_c+0,battery_temperature+0
113
heinrichsweikamp
parents: 20
diff changeset
941 ; return
heinrichsweikamp
parents: 20
diff changeset
942
heinrichsweikamp
parents: 20
diff changeset
943 global lt2942_get_accumulated_charge
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
944 lt2942_get_accumulated_charge: ; Read accumulated charge and compute percent
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
945 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
946 movlw 0x00 ; Point to status register
467
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
947 rcall I2C_TX_GAUGE
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
948 rcall I2C_RX_GAUGE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
949 bsf SSP1CON2,ACKEN ; Master acknowledge
113
heinrichsweikamp
parents: 20
diff changeset
950 rcall WaitMSSP
466
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
951 movff SSP1BUF,gauge_status_byte
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
952
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
953 bsf SSP1CON2, RCEN ; Enable receive mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
954 rcall WaitMSSP ; Dummy read (Control byte)
467
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
955 movf SSP1BUF,W
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
956 bsf SSP1CON2,ACKEN ; Master acknowledge
467
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
957 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
958
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
959 bsf SSP1CON2, RCEN ; Enable receive mode
113
heinrichsweikamp
parents: 20
diff changeset
960 rcall WaitMSSP
466
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
961 movff SSP1BUF,sub_a+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
962 bsf SSP1CON2,ACKEN ; Master acknowledge
467
6ca155fc1509 battery gauge handling
heinrichsweikamp
parents: 466
diff changeset
963 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
964
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
965 bsf SSP1CON2, RCEN ; Enable receive mode
466
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
966 rcall WaitMSSP
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 449
diff changeset
967 movff SSP1BUF,sub_a+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
968 bsf SSP1CON2,PEN ; Stop condition
113
heinrichsweikamp
parents: 20
diff changeset
969 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
970
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
971 movff gauge_status_byte,sub_b+0 ; copy into bank common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
972 btfsc sub_b+0,0 ; =1: UVLO Event
556
dd28d4efd4d2 fix a potential issue in the battery managment
heinrichsweikamp
parents: 498
diff changeset
973 rcall lt2942_init_again
113
heinrichsweikamp
parents: 20
diff changeset
974
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
975 movff sub_a+1,battery_acumulated_charge+1 ; Save raw value
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
976 movff sub_a+0,battery_acumulated_charge+0 ; Save raw value
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
977
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
978 ; Compute batt_percent
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
979 ; (charge-battery_offset)/365
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
980 movff battery_offset+0,sub_b+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
981 movff battery_offset+1,sub_b+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
982 call subU16 ; sub_c = sub_a - sub_b (with signed values)
113
heinrichsweikamp
parents: 20
diff changeset
983
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
984 clrf batt_percent ; Set to zero
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
985 btfsc neg_flag ; result negative?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
986 bra lt2942_set_to_zero_percent ; Yes, keep LT2942 at zero percent and return
113
heinrichsweikamp
parents: 20
diff changeset
987
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
988 ; > Zero, set batt_percent properly
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
989 movff sub_c+0,xA+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
990 movff sub_c+1,xA+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
991 movff battery_capacity+0,xB+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
992 movff battery_capacity+1,xB+1
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
993 call div16x16 ; xC = xA / xB with xA as remainder
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
994 movff xC+0,batt_percent
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
995 return
113
heinrichsweikamp
parents: 20
diff changeset
996
449
heinrichsweikamp
parents: 448
diff changeset
997 lt2942_set_to_zero_percent:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
998 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
999 movlw 0x02 ; Point to accumulated charge registers
449
heinrichsweikamp
parents: 448
diff changeset
1000 rcall I2C_TX_GAUGE
heinrichsweikamp
parents: 448
diff changeset
1001 movff battery_offset+1,SSP1BUF
heinrichsweikamp
parents: 448
diff changeset
1002 rcall WaitMSSP
heinrichsweikamp
parents: 448
diff changeset
1003 rcall I2C_WaitforACK
heinrichsweikamp
parents: 448
diff changeset
1004 movff battery_offset+0,SSP1BUF
heinrichsweikamp
parents: 448
diff changeset
1005 rcall WaitMSSP
heinrichsweikamp
parents: 448
diff changeset
1006 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1007 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1008 bra WaitMSSP ; (and return)
449
heinrichsweikamp
parents: 448
diff changeset
1009
113
heinrichsweikamp
parents: 20
diff changeset
1010 global lt2942_charge_done
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1011 lt2942_charge_done: ; Reset accumulating registers to 0xFFFF
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1012 clrf i2c_temp1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1013 movlw 0x02 ; Point to accumulated charge registers
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 429
diff changeset
1014 rcall I2C_TX_GAUGE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1015 setf SSP1BUF ; Data Byte
113
heinrichsweikamp
parents: 20
diff changeset
1016 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
1017 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1018 setf SSP1BUF ; Data Byte
113
heinrichsweikamp
parents: 20
diff changeset
1019 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
1020 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1021 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1022 bra WaitMSSP ; (and return)
113
heinrichsweikamp
parents: 20
diff changeset
1023
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1024 I2C_TX_GAUGE: ; Sends a byte to the LT2942 Gauge IC
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1025 movwf i2c_temp2 ; Data byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1026 bsf SSP1CON2,SEN ; Start condition
113
heinrichsweikamp
parents: 20
diff changeset
1027 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1028 movlw b'11001000' ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1029 movwf SSP1BUF ; control byte
113
heinrichsweikamp
parents: 20
diff changeset
1030 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
1031 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1032 movf i2c_temp2,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1033 bra I2C_TX ; (and return)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1034
113
heinrichsweikamp
parents: 20
diff changeset
1035 I2C_RX_GAUGE:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1036 bsf SSP1CON2,SEN ; Start condition
113
heinrichsweikamp
parents: 20
diff changeset
1037 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1038 movlw b'11001001' ; Address byte + Read bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1039 movwf SSP1BUF ; control byte
113
heinrichsweikamp
parents: 20
diff changeset
1040 rcall WaitMSSP
heinrichsweikamp
parents: 20
diff changeset
1041 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1042 bsf SSP1CON2, RCEN ; Enable receive mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1043 bra WaitMSSP ; (and return)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1044
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1045
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1046 ;-----------------------------------------------------------------------------
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1047 ; Transmitter Functions
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1048
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1049 IFDEF _rx_functions
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1050
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1051 global I2C_probe_OSTC_rx
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1052 I2C_probe_OSTC_rx:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1053 movlw .5
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1054 movwf lo_temp
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1055 I2C_probe_OSTC_rx_1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1056 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1057 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1058 movlw 0x50 ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1059 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1060 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1061 btfss SSP1CON2,ACKSTAT ; ACK?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1062 bsf ostc_rx_present ; ACK sent - OSTC_RX present!
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
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1065 btfss ostc_rx_present ; Do we have the RX?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1066 return ; No, Done.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1067 WAITMS .1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1068 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1069 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1070 movlw 0x50 ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1071 movwf SSP1BUF ; control byte
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 rcall I2C_WaitforACK
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1074 movlw 0x1B
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1075 movwf SSP1BUF ; Data Byte (Get firmware)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1076 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1077 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1078 bsf SSP1CON2,PEN ; Stop condition
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 WAITMS .1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1081 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1082 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1083 movlw 0x51 ; Address byte + Read bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1084 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1085 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1086 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1087 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1088 movff SSP1BUF,rx_firmware+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1089 bsf SSP1CON2,ACKEN ; Master acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1090 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1091
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1092 ; 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
1093 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1094 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1095 movff SSP1BUF,rx_firmware+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1096 bsf SSP1CON2,ACKDT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1097 bsf SSP1CON2,ACKEN ; Master NOT acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1098 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1099 bcf SSP1CON2,ACKDT ; Reset ACKDT flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1100 bsf SSP1CON2,PEN ; Stop condition
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1101 rcall WaitMSSP
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1102
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1103 ; 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
1104 movff rx_firmware+1,i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1105 movlw .147
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1106 cpfseq i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1107 bra I2C_probe_OSTC_rx_2 ; not equal
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1108 movff rx_firmware+0,i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1109 movlw .27
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1110 cpfseq i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1111 bra I2C_probe_OSTC_rx_2 ; not equal
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1112 bsf active_reset_ostc_rx
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1113 WAITMS .5
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1114 bcf active_reset_ostc_rx
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1115 WAITMS .250
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1116 WAITMS .250
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1117 clrf i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1118 decfsz lo_temp,F ; try max. 5 times
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1119 bra I2C_probe_OSTC_rx_1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1120 bcf ostc_rx_present ; Clear flag. Something is wrong
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1121 I2C_probe_OSTC_rx_2:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1122 clrf i2c_temp1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1123 return
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1124
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1125
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1126 global I2C_get_tankdata
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1127 I2C_get_tankdata:
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 0x50 ; Address byte + Write 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 0x1E ; Read buffer2 (48 Bytes)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1135 movwf SSP1BUF ; Data Byte
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1136 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1137 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1138 bsf SSP1CON2,PEN ; Stop condition
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 WAITMS .1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1141
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1142 ; read 48 bytes
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1143 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1144 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1145 movlw 0x51 ; Address byte + read bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1146 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1147 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1148 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1149 movlw .47 ; 47 with ACK + 1 w/o ACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1150 movwf i2c_temp2
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1151 lfsr FSR2,rx_buffer+0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1152 I2C_get_tankdata_loop_read:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1153 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1154 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1155 movff SSP1BUF,POSTINC2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1156 bcf SSP1CON2,ACKDT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1157 bsf SSP1CON2,ACKEN ; Master acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1158 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1159 decfsz i2c_temp2,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1160 bra I2C_get_tankdata_loop_read
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1161
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1162 ; 1 w/o ACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1163 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1164 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1165 movff SSP1BUF,POSTINC2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1166 bsf SSP1CON2,ACKDT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1167 bsf SSP1CON2,ACKEN ; Master NOT acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1168 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1169 bcf SSP1CON2,ACKDT ; Reset ACKDT flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1170
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1171 bsf SSP1CON2,PEN ; Stop condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1172 bra WaitMSSP ;(and return)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1173
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1174
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1175 global I2C_update_OSTC_rx
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1176 I2C_update_OSTC_rx: ; 992*64byte master loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1177 bcf i2c_error_flag ; clear error flag
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1178 ; write 64 bytes
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1179 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1180 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1181 movlw 0x50 ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1182 movwf SSP1BUF ; control byte
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 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1185 lfsr FSR2,buffer ; send buffer for verify
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1186 movlw .64
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1187 movwf i2c_temp2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1188 I2C_update_OSTC_loop: ; 64byte flash page loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1189 movff up,POSTINC2 ; store for verify
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1190 movff up,SSP1BUF
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
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1193 call ext_flash_read_block ; Read one byte
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1194 movwf up ; prepare for transmit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1195 decfsz i2c_temp2,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1196 bra I2C_update_OSTC_loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1197 bsf SSP1CON2,PEN ; Stop condition
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 WAITMS .1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1200
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1201 ; read 64 bytes
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1202 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1203 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1204 movlw 0x51 ; Address byte + read bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1205 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1206 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1207 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1208 lfsr FSR2,buffer ; send buffer for verify
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1209 movlw .63 ; 63 with ACK + 1 w/o ACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1210 movwf i2c_temp2
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1211 I2C_update_OSTC_loop_read:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1212 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1213 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1214 movf SSP1BUF,W
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1215 cpfseq POSTINC2 ; compare read-back with original
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1216 bsf i2c_error_flag ; Not equal, set flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1217 bcf SSP1CON2,ACKDT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1218 bsf SSP1CON2,ACKEN ; Master acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1219 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1220 decfsz i2c_temp2,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1221 bra I2C_update_OSTC_loop_read
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1222
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1223 ; 1 w/o ACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1224 bsf SSP1CON2, RCEN ; Enable receive mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1225 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1226 movf SSP1BUF,W
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1227 cpfseq POSTINC2 ; compare read-back with original
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1228 bsf i2c_error_flag ; Not equal, set flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1229 bsf SSP1CON2,ACKDT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1230 bsf SSP1CON2,ACKEN ; Master NOT acknowledge
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1231 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1232 bcf SSP1CON2,ACKDT ; Reset ACKDT flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1233
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1234 bsf SSP1CON2,PEN ; Stop condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1235 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1236 WAITMS .1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1237
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1238 bsf SSP1CON2,SEN ; Start condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1239 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1240 movlw 0x50 ; Address byte + Write bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1241 movwf SSP1BUF ; control byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1242 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1243 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1244 movlw 0x1F ; Write command!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1245 movwf SSP1BUF ; Data Byte
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1246 rcall WaitMSSP
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1247 rcall I2C_WaitforACK
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1248 bsf SSP1CON2,PEN ; Stop condition
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1249 rcall WaitMSSP
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1250 WAITMS .5 ; Required waiting time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1251
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 556
diff changeset
1252 btfss i2c_error_flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1253 retlw .0 ; All ok
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1254 retlw .255 ; an error occurred
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1255
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1256 ENDIF
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
1257
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1258 END