Mercurial > public > mk2
annotate code_part1/OSTC_code_asm_part1/i2c_eeprom.asm @ 315:cce563347c94 @5 variant
german translation update
author | heinrichsweikamp |
---|---|
date | Wed, 04 May 2011 08:13:27 +0200 |
parents | dee88c962653 |
children | 7250ca7c8d24 |
rev | line source |
---|---|
0 | 1 |
2 ; OSTC - diving computer code | |
3 ; Copyright (C) 2008 HeinrichsWeikamp GbR | |
4 ; This program is free software: you can redistribute it and/or modify | |
5 ; it under the terms of the GNU General Public License as published by | |
6 ; the Free Software Foundation, either version 3 of the License, or | |
7 ; (at your option) any later version. | |
8 ; This program is distributed in the hope that it will be useful, | |
9 ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 ; GNU General Public License for more details. | |
12 ; You should have received a copy of the GNU General Public License | |
13 ; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
14 ; provides routines for external EEPROM via I2C | |
15 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com | |
16 ; written: 10/30/05 | |
17 ; last updated: 08/21/06 | |
18 ; known bugs: | |
19 ; ToDo: use 2nd 32KB from external EEPROM for something | |
20 | |
21 incf_eeprom_address macro ext_ee_temp1 ; Will increase eeprom_address:2 with the 8Bit value "ext_ee_temp1" and takes | |
148 | 22 movlw ext_ee_temp1 ; care of bank switching at 0x8000 |
23 call incf_eeprom_address0 | |
0 | 24 endm |
25 | |
26 incf_eeprom_address0: | |
148 | 27 addwf eeprom_address+0,F ; increase address |
28 movlw d'0' | |
29 addwfc eeprom_address+1,F | |
0 | 30 |
148 | 31 btfss eeprom_address+1,7 ; at address 8000? |
32 return ; No, continue | |
33 | |
34 ; Yes, clear eeprom_address:2 | |
35 clrf eeprom_address+0 ; Clear eeprom address | |
36 clrf eeprom_address+1 | |
37 return ; Done. | |
38 | |
39 ;============================================================================= | |
40 ; Will decrease eeprom_address:2 with the 8Bit value "ext_ee_temp1" and takes | |
41 ; care of bank switching at 0x8000 | |
42 | |
43 decf_eeprom_address macro ext_ee_temp1 | |
44 movlw ext_ee_temp1 | |
45 call decf_eeprom_address0 | |
46 endm | |
0 | 47 |
48 decf_eeprom_address0: | |
148 | 49 subwf eeprom_address+0,F ; decrease address: do a 16-8bits substract. |
50 movlw d'0' | |
51 subwfb eeprom_address+1,F | |
0 | 52 |
148 | 53 btfss eeprom_address+1,7 ; at address 8000? |
54 return ; No, done. | |
0 | 55 |
148 | 56 movlw b'01111111' ; yes, reset highbyte |
57 movwf eeprom_address+1 | |
58 return ; Done. | |
59 | |
60 ;============================================================================= | |
0 | 61 |
62 write_external_eeprom: ; data in WREG | |
63 ; increase address eeprom_address+0:eeprom_address+1 after write | |
64 ; with banking after 7FFF | |
81
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
65 #ifdef TESTING |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
66 ; When Simulating with MPLabSIM, there is no way to emulate external EEPROM... |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
67 return |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
68 #endif |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
69 |
0 | 70 rcall I2CWRITE ; writes WREG into EEPROM@eeprom_address |
71 movlw d'1' ; increase address | |
72 addwf eeprom_address+0,F | |
73 movlw d'0' | |
74 addwfc eeprom_address+1,F | |
75 bcf eeprom_overflow | |
76 btfss eeprom_address+1,7 ; at address 8000? | |
77 return ; no, return | |
78 | |
79 clrf eeprom_address+0 ; Clear eeprom address | |
80 clrf eeprom_address+1 | |
81 bsf eeprom_overflow ; and set overflow bit | |
82 return | |
83
3e351e25f5d1
adding anti-aliased fonts frame and merging some patches from Jeando
heinrichsweikamp
parents:
81
diff
changeset
|
83 |
0 | 84 write_external_eeprom_block: ; Writes a block of 64Byte (one page in external EEPROM without stop condition |
81
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
85 #ifdef TESTING |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
86 ; When Simulating with MPLabSIM, there is no way to emulate external EEPROM... |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
87 return |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
88 #endif |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
89 |
0 | 90 btfsc eeprom_blockwrite ; Blockwrite continue? |
91 rcall I2CWRITE_BLOCK2 | |
92 btfss eeprom_blockwrite ; Blockwrite start? | |
93 rcall I2CWRITE_BLOCK | |
94 bsf eeprom_blockwrite ; After the start, do blockwriting for the next 63Bytes! | |
95 | |
96 movlw d'0' ; increase address | |
97 incf eeprom_address+0,F | |
98 addwfc eeprom_address+1,F | |
99 bcf eeprom_overflow | |
100 | |
101 btfss eeprom_address+1,7 ; at address 8000 | |
102 return ; no, return | |
103 | |
104 clrf eeprom_address+0 ; Clear eeprom address | |
105 clrf eeprom_address+1 | |
106 bsf eeprom_overflow ; and set overflow bit | |
107 return | |
108 I2CWRITE_BLOCK: | |
109 movwf ext_ee_temp1 ; Data byte in WREG | |
110 bsf SSPCON2,SEN ; Start condition | |
111 rcall WaitMSSP | |
112 movlw b'10100110' ; Bit0=0: WRITE, Bit0=1: READ | |
113 movwf SSPBUF ; control byte | |
114 rcall WaitMSSP | |
115 rcall I2C_WaitforACK | |
116 movff eeprom_address+1,SSPBUF ; High Address byte | |
117 rcall WaitMSSP | |
118 rcall I2C_WaitforACK | |
119 movff eeprom_address+0,SSPBUF ; Low Address byte | |
120 rcall WaitMSSP | |
121 rcall I2C_WaitforACK | |
122 I2CWRITE_BLOCK2: | |
123 movff ext_ee_temp1, SSPBUF ; Data Byte | |
124 rcall WaitMSSP | |
125 rcall I2C_WaitforACK | |
126 return | |
127 | |
128 | |
129 get_free_EEPROM_location: ; Searches 0xFD, 0xFD, 0xFE and sets Pointer to 0xFE | |
81
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
130 |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
131 #ifdef TESTING |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
132 ; In testing mode, find 0x100 (internal EEPROM) as the first free location... |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
133 clrf eeprom_address+0 ; Not found in entire EEPROM, set to address 0 |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
134 movlw 0x1 |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
135 movwf eeprom_address+1 |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
136 return |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
137 #endif |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
138 |
0 | 139 clrf ext_ee_temp1 ; low address counter |
140 clrf ext_ee_temp2 ; high address counter | |
141 bcf second_FD ; clear flags | |
142 bcf first_FD | |
143 get_free_EEPROM_location3: | |
144 bsf SSPCON2, PEN ; Stop condition | |
145 rcall WaitMSSP | |
146 bsf SSPCON2,SEN ; Start condition | |
147 rcall WaitMSSP | |
148 movlw b'10100110' ; Bit0=0: WRITE, Bit0=1: READ | |
149 movwf SSPBUF ; control byte | |
150 rcall WaitMSSP | |
151 btfsc SSPCON2,ACKSTAT | |
152 bra get_free_EEPROM_location3 ; EEPROM NOT acknowledged, retry! | |
153 | |
154 movff ext_ee_temp2,SSPBUF ; High Address byte | |
155 rcall WaitMSSP | |
156 rcall I2C_WaitforACK | |
157 movff ext_ee_temp1,SSPBUF ; Low Address byte | |
158 rcall WaitMSSP | |
159 rcall I2C_WaitforACK | |
160 | |
161 bsf SSPCON2,RSEN ; Start condition | |
162 rcall WaitMSSP | |
163 movlw b'10100111' ; Bit0=0: WRITE, Bit0=1: READ | |
164 movwf SSPBUF ; control byte | |
165 rcall WaitMSSP | |
166 rcall I2C_WaitforACK | |
167 | |
168 get_free_EEPROM_location2: | |
169 bsf SSPCON2, RCEN ; Enable recieve mode | |
170 rcall WaitMSSP | |
171 btfsc first_FD | |
172 bra test_2nd_FD | |
173 bsf first_FD ; found first 0xFD? | |
174 movlw 0xFD | |
175 cpfseq SSPBUF | |
176 bcf first_FD ; No | |
177 bra get_free_EEPROM_location2c | |
178 | |
179 test_2nd_FD: | |
180 btfsc second_FD | |
181 bra test_FE | |
182 bsf second_FD ; found second 0xFD? | |
183 movlw 0xFD | |
184 cpfseq SSPBUF | |
185 bra get_free_EEPROM_location2b ;No, clear both flags | |
186 bra get_free_EEPROM_location2c | |
187 test_FE: | |
188 movlw 0xFE ; found the final 0xFE? | |
189 cpfseq SSPBUF | |
190 bra get_free_EEPROM_location2b ;No, clear both flags | |
191 movff ext_ee_temp1,eeprom_address+0 ;Yes, copy ext_ee_temp1->eeprom_address+0 and | |
192 movff ext_ee_temp2,eeprom_address+1 ;ext_ee_temp2->eeprom_address+1 | |
193 bra get_free_EEPROM_location4 ; Done. | |
194 | |
195 get_free_EEPROM_location2b: | |
196 bcf second_FD ; clear both flags! | |
197 bcf first_FD | |
198 get_free_EEPROM_location2c: | |
199 movlw d'1' ; and increase search address | |
200 addwf ext_ee_temp1,F | |
201 movlw d'0' | |
202 addwfc ext_ee_temp2,F | |
203 | |
42 | 204 btfsc ext_ee_temp2,7 ; 0x8000 reached? |
0 | 205 bra get_free_EEPROM_location3b ; yes |
206 | |
207 bsf SSPCON2, ACKEN ; no, send Ack | |
208 rcall WaitMSSP | |
209 bra get_free_EEPROM_location2 ; and continue search | |
210 get_free_EEPROM_location3b: | |
211 clrf eeprom_address+0 ; Not found in entire EEPROM, set to address 0 | |
212 clrf eeprom_address+1 | |
213 get_free_EEPROM_location4: | |
214 bsf SSPCON2, PEN ; Stop | |
215 rcall WaitMSSP | |
216 | |
217 bcf second_FD ; clear flags | |
218 bcf first_FD | |
219 return ; return | |
220 | |
221 | |
222 I2CREAD: | |
245
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
223 rcall I2CREAD_COMMON |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
224 bsf SSPCON2, PEN ; Stop |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
225 rcall WaitMSSP |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
226 return |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
227 |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
228 I2CREAD2: ; same as I2CREAD but with automatic address increase |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
229 rcall I2CREAD |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
230 I2CREAD2_2: |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
231 movlw d'1' |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
232 addwf eeprom_address+0,F |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
233 movlw d'0' |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
234 addwfc eeprom_address+1,F |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
235 bcf eeprom_overflow |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
236 btfss eeprom_address+1,7 ; at 0x8000? |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
237 return ; no, return |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
238 |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
239 clrf eeprom_address+0 ; Yes, clear address |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
240 clrf eeprom_address+1 |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
241 bsf eeprom_overflow ; and set overflow bit |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
242 return |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
243 |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
244 I2CREAD3: ; block read start with automatic address increase |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
245 rcall I2CREAD_COMMON |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
246 ; no Stop condition here |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
247 bra I2CREAD2_2 |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
248 |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
249 I2CREAD4: ; block read with automatic address increase |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
250 bsf SSPCON2,ACKEN ; Master acknowlegde |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
251 rcall WaitMSSP |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
252 bsf SSPCON2, RCEN ; Enable recieve mode |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
253 rcall WaitMSSP |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
254 movf SSPBUF,W ; copy read byte into WREG |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
255 ; no Stop condition here |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
256 bra I2CREAD2_2 |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
257 |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
258 |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
259 I2CREAD_COMMON: |
0 | 260 bsf SSPCON2, PEN ; Stop |
261 rcall WaitMSSP | |
262 bsf SSPCON2,SEN ; Start condition | |
263 rcall WaitMSSP | |
264 movlw b'10100110' ; Bit0=0: WRITE, Bit0=1: READ | |
265 movwf SSPBUF ; control byte | |
266 rcall WaitMSSP | |
267 btfsc SSPCON2,ACKSTAT | |
268 bra I2CREAD ; EEPROM NOT acknowledged, retry! | |
269 movff eeprom_address+1,SSPBUF ; High Address byte | |
270 rcall WaitMSSP | |
271 rcall I2C_WaitforACK | |
272 movff eeprom_address+0,SSPBUF ; Low Address byte | |
273 rcall WaitMSSP | |
274 rcall I2C_WaitforACK | |
275 | |
276 bsf SSPCON2,RSEN ; Start condition | |
277 rcall WaitMSSP | |
278 movlw b'10100111' ; Bit0=0: WRITE, Bit0=1: READ | |
279 movwf SSPBUF ; control byte | |
280 rcall WaitMSSP | |
281 rcall I2C_WaitforACK | |
282 | |
283 bsf SSPCON2, RCEN ; Enable recieve mode | |
284 rcall WaitMSSP | |
285 movf SSPBUF,W ; copy read byte into WREG | |
286 return | |
287 | |
245
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
288 |
0 | 289 I2CWRITE: |
290 movwf ext_ee_temp1 ; Data byte | |
291 bsf SSPCON2,SEN ; Start condition | |
292 rcall WaitMSSP | |
293 movlw b'10100110' ; Bit0=0: WRITE, Bit0=1: READ | |
294 movwf SSPBUF ; control byte | |
295 rcall WaitMSSP | |
296 rcall I2C_WaitforACK | |
297 movff eeprom_address+1,SSPBUF ; High Address byte | |
298 rcall WaitMSSP | |
299 rcall I2C_WaitforACK | |
300 movff eeprom_address+0,SSPBUF ; Low Address byte | |
301 rcall WaitMSSP | |
302 rcall I2C_WaitforACK | |
303 movff ext_ee_temp1, SSPBUF ; Data Byte | |
304 rcall WaitMSSP | |
305 rcall I2C_WaitforACK | |
306 bsf SSPCON2,PEN ; Stop condition | |
307 rcall WaitMSSP | |
245
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
308 WAITMS d'5' ; Write delay |
0 | 309 return |
310 | |
311 I2C_WaitforACK: | |
312 btfsc SSPCON2,ACKSTAT ; checks for ACK bit from slave | |
313 rcall I2CFail | |
314 return | |
315 | |
316 I2CFail: | |
317 ostc_debug 'M' ; Sends debug-information to screen if debugmode active | |
21 | 318 bsf LED_red |
0 | 319 rcall I2CReset ; I2C Reset |
320 bcf PIR1,SSPIF | |
321 clrf i2c_temp | |
322 return | |
323 | |
324 WaitMSSP: | |
325 decfsz i2c_temp,F ; check for timeout during I2C action | |
326 bra WaitMSSP2 | |
327 bra I2CFail ; timeout occured | |
328 WaitMSSP2: | |
329 btfss PIR1,SSPIF | |
330 bra WaitMSSP | |
331 clrf i2c_temp | |
332 bcf PIR1,SSPIF | |
333 return | |
334 | |
335 I2CReset: ; Something went wrong (Slave holds SDA low?) | |
336 clrf SSPCON1 ; wake-up slave and reset entire module | |
337 ostc_debug 'N' ; Sends debug-information to screen if debugmode active | |
338 clrf SSPCON2 | |
339 clrf SSPSTAT | |
340 bcf TRISC,3 ; SCL OUTPUT | |
341 bsf TRISC,4 ; SDA Input | |
342 bcf PORTC,3 | |
343 movlw d'9' | |
344 movwf i2c_temp ; clock-out 9 clock cycles manually | |
345 I2CReset_1: | |
346 bsf PORTC,3 ; SCL=1 | |
347 nop | |
348 btfsc PORTC,4 ; SDA=1? | |
349 bra I2CReset_2 ; =1, SDA has been released from slave | |
350 bcf PORTC,3 ; SCL=0 | |
351 bcf PORTC,3 | |
352 decfsz i2c_temp,F | |
353 bra I2CReset_1 ; check for nine clock cycles | |
354 I2CReset_2: | |
355 bsf TRISC,3 ; SCL Input | |
356 clrf SSPCON1 ; set I²C Mode | |
357 WAITMS d'10' ; Reset-Timeout for I2C devices | |
358 movlw b'00000000' | |
359 movwf SSPSTAT | |
360 movlw b'00101000' | |
361 movwf SSPCON1 | |
362 movlw b'00000000' | |
363 movwf SSPCON2 | |
364 movlw d'8' ; 400kHz I2C clock @ 16MHz Fcy | |
365 movwf SSPADD | |
21 | 366 bcf LED_red |
0 | 367 ostc_debug 'O' ; Sends debug-information to screen if debugmode active |
368 return | |
53 | 369 |
370 ;I2C_TX: | |
371 ; movwf i2c_temp2 ; Data byte | |
372 ; bsf SSPCON2,SEN ; Start condition | |
373 ; rcall WaitMSSP | |
374 ; movlw b'10010000' ; Bit0=0: WRITE, Bit0=1: READ | |
375 ; movwf SSPBUF ; control byte | |
376 ; rcall WaitMSSP | |
377 ; rcall I2C_WaitforACK | |
378 ; movff i2c_temp2, SSPBUF ; Data Byte | |
379 ; rcall WaitMSSP | |
380 ; rcall I2C_WaitforACK | |
381 ; bsf SSPCON2,PEN ; Stop condition | |
382 ; rcall WaitMSSP | |
383 ; return | |
384 ;I2C_RX: | |
385 ; bcf PIR1,SSPIF | |
386 ; bsf SSPCON2,SEN ; Start condition | |
387 ; rcall WaitMSSP | |
388 ; movlw b'10010001' ; Bit0=0: WRITE, Bit0=1: READ | |
389 ; movwf SSPBUF ; control byte | |
390 ; rcall WaitMSSP | |
391 ; rcall I2C_WaitforACK | |
392 ; bsf SSPCON2, RCEN ; Enable recieve mode | |
393 ; rcall WaitMSSP | |
394 ; movff SSPBUF,i2c_temp2 ; Data Byte | |
395 ; bsf SSPCON2,ACKEN ; Master acknowlegde | |
396 ; rcall WaitMSSP | |
397 ; bsf SSPCON2,PEN ; Stop condition | |
398 ; rcall WaitMSSP | |
399 ; return |