Mercurial > public > mk2
annotate code_part1/OSTC_code_asm_part1/i2c_eeprom.asm @ 451:f6f818edf333
BUGFIX bad first Tp? and ceiling in logbook curves.
* Computing Tp? max during logbook profile reading.
author | JeanDo |
---|---|
date | Thu, 18 Aug 2011 23:33:24 +0200 |
parents | a76c5a3e9e96 |
children | c512a868937c |
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 | |
350
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
21 incf_eeprom_address macro ext_ee_temp1 ; Will increase eeprom_address:2 with the 8Bit value "ext_ee_temp1" |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
22 movlw ext_ee_temp1 |
148 | 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 | |
350
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
30 return |
425 | 31 |
350
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
32 ;============================================================================= |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
33 ; Will decrease eeprom_address:2 with the 8Bit value "ext_ee_temp1" |
0 | 34 |
148 | 35 |
36 decf_eeprom_address macro ext_ee_temp1 | |
37 movlw ext_ee_temp1 | |
38 call decf_eeprom_address0 | |
39 endm | |
0 | 40 |
41 decf_eeprom_address0: | |
148 | 42 subwf eeprom_address+0,F ; decrease address: do a 16-8bits substract. |
43 movlw d'0' | |
44 subwfb eeprom_address+1,F | |
350
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
45 return |
148 | 46 |
47 ;============================================================================= | |
0 | 48 |
49 write_external_eeprom: ; data in WREG | |
50 ; increase address eeprom_address+0:eeprom_address+1 after write | |
51 ; with banking after 7FFF | |
81
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
52 #ifdef TESTING |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
53 ; 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
|
54 return |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
55 #endif |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
56 |
0 | 57 rcall I2CWRITE ; writes WREG into EEPROM@eeprom_address |
58 movlw d'1' ; increase address | |
59 addwf eeprom_address+0,F | |
60 movlw d'0' | |
61 addwfc eeprom_address+1,F | |
62 return | |
350
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
63 ; btfss eeprom_address+1,7 ; at address 8000? |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
64 ; return ; no, return |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
65 ; |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
66 ; clrf eeprom_address+0 ; Clear eeprom address |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
67 ; clrf eeprom_address+1 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
68 ; return |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
69 ; |
0 | 70 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
|
71 #ifdef TESTING |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
72 ; 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
|
73 return |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
74 #endif |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
75 |
0 | 76 btfsc eeprom_blockwrite ; Blockwrite continue? |
77 rcall I2CWRITE_BLOCK2 | |
78 btfss eeprom_blockwrite ; Blockwrite start? | |
79 rcall I2CWRITE_BLOCK | |
80 bsf eeprom_blockwrite ; After the start, do blockwriting for the next 63Bytes! | |
81 | |
82 movlw d'0' ; increase address | |
83 incf eeprom_address+0,F | |
84 addwfc eeprom_address+1,F | |
85 return | |
350
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
86 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
87 ; btfss eeprom_address+1,7 ; at address 8000 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
88 ; return ; no, return |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
89 ; |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
90 ; clrf eeprom_address+0 ; Clear eeprom address |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
91 ; clrf eeprom_address+1 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
92 ; return |
0 | 93 I2CWRITE_BLOCK: |
94 movwf ext_ee_temp1 ; Data byte in WREG | |
95 bsf SSPCON2,SEN ; Start condition | |
96 rcall WaitMSSP | |
350
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
97 movlw b'10101110' ; Bit0=0: WRITE, Bit0=1: READ, BLOCK2 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
98 btfss eeprom_address+1,7 ; Access Block2? |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
99 movlw b'10100110' ; No, -> Bit0=0: WRITE, Bit0=1: READ, BLOCK1 |
0 | 100 movwf SSPBUF ; control byte |
101 rcall WaitMSSP | |
102 rcall I2C_WaitforACK | |
103 movff eeprom_address+1,SSPBUF ; High Address byte | |
104 rcall WaitMSSP | |
105 rcall I2C_WaitforACK | |
106 movff eeprom_address+0,SSPBUF ; Low Address byte | |
107 rcall WaitMSSP | |
108 rcall I2C_WaitforACK | |
109 I2CWRITE_BLOCK2: | |
110 movff ext_ee_temp1, SSPBUF ; Data Byte | |
111 rcall WaitMSSP | |
112 rcall I2C_WaitforACK | |
113 return | |
114 | |
115 | |
116 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
|
117 |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
118 #ifdef TESTING |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
119 ; 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
|
120 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
|
121 movlw 0x1 |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
122 movwf eeprom_address+1 |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
123 return |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
124 #endif |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
53
diff
changeset
|
125 |
0 | 126 clrf ext_ee_temp1 ; low address counter |
127 clrf ext_ee_temp2 ; high address counter | |
128 bcf second_FD ; clear flags | |
129 bcf first_FD | |
130 get_free_EEPROM_location3: | |
131 bsf SSPCON2, PEN ; Stop condition | |
132 rcall WaitMSSP | |
133 bsf SSPCON2,SEN ; Start condition | |
134 rcall WaitMSSP | |
350
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
135 movlw b'10101110' ; Bit0=0: WRITE, Bit0=1: READ, BLOCK2 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
136 btfss ext_ee_temp2,7 ; Access Block2? |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
137 movlw b'10100110' ; No, -> Bit0=0: WRITE, Bit0=1: READ, BLOCK1 |
0 | 138 movwf SSPBUF ; control byte |
139 rcall WaitMSSP | |
140 btfsc SSPCON2,ACKSTAT | |
141 bra get_free_EEPROM_location3 ; EEPROM NOT acknowledged, retry! | |
142 | |
143 movff ext_ee_temp2,SSPBUF ; High Address byte | |
144 rcall WaitMSSP | |
145 rcall I2C_WaitforACK | |
146 movff ext_ee_temp1,SSPBUF ; Low Address byte | |
147 rcall WaitMSSP | |
148 rcall I2C_WaitforACK | |
149 | |
150 bsf SSPCON2,RSEN ; Start condition | |
151 rcall WaitMSSP | |
350
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
152 movlw b'10101111' ; Bit0=0: WRITE, Bit0=1: READ, BLOCK2 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
153 btfss ext_ee_temp2,7 ; Access Block2? |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
154 movlw b'10100111' ; No, -> Bit0=0: WRITE, Bit0=1: READ, BLOCK1 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
155 movwf SSPBUF ; control byte |
0 | 156 rcall WaitMSSP |
157 rcall I2C_WaitforACK | |
158 | |
159 get_free_EEPROM_location2: | |
160 bsf SSPCON2, RCEN ; Enable recieve mode | |
161 rcall WaitMSSP | |
162 btfsc first_FD | |
163 bra test_2nd_FD | |
164 bsf first_FD ; found first 0xFD? | |
165 movlw 0xFD | |
166 cpfseq SSPBUF | |
167 bcf first_FD ; No | |
168 bra get_free_EEPROM_location2c | |
169 | |
170 test_2nd_FD: | |
171 btfsc second_FD | |
172 bra test_FE | |
173 bsf second_FD ; found second 0xFD? | |
174 movlw 0xFD | |
175 cpfseq SSPBUF | |
176 bra get_free_EEPROM_location2b ;No, clear both flags | |
177 bra get_free_EEPROM_location2c | |
178 test_FE: | |
179 movlw 0xFE ; found the final 0xFE? | |
180 cpfseq SSPBUF | |
181 bra get_free_EEPROM_location2b ;No, clear both flags | |
182 movff ext_ee_temp1,eeprom_address+0 ;Yes, copy ext_ee_temp1->eeprom_address+0 and | |
183 movff ext_ee_temp2,eeprom_address+1 ;ext_ee_temp2->eeprom_address+1 | |
184 bra get_free_EEPROM_location4 ; Done. | |
185 | |
186 get_free_EEPROM_location2b: | |
187 bcf second_FD ; clear both flags! | |
188 bcf first_FD | |
189 get_free_EEPROM_location2c: | |
190 movlw d'1' ; and increase search address | |
191 addwf ext_ee_temp1,F | |
192 movlw d'0' | |
193 addwfc ext_ee_temp2,F | |
350
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
194 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
195 movlw 0xFF |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
196 cpfseq ext_ee_temp2 ; =0xFFFF |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
197 bra get_free_EEPROM_location2d ; No |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
198 cpfseq ext_ee_temp1 ; =0xFFFF |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
199 bra get_free_EEPROM_location2d ; No |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
200 |
0 | 201 bra get_free_EEPROM_location3b ; yes |
350
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
202 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
203 get_free_EEPROM_location2d: |
0 | 204 bsf SSPCON2, ACKEN ; no, send Ack |
205 rcall WaitMSSP | |
206 bra get_free_EEPROM_location2 ; and continue search | |
207 get_free_EEPROM_location3b: | |
208 clrf eeprom_address+0 ; Not found in entire EEPROM, set to address 0 | |
209 clrf eeprom_address+1 | |
210 get_free_EEPROM_location4: | |
211 bsf SSPCON2, PEN ; Stop | |
212 rcall WaitMSSP | |
213 | |
214 bcf second_FD ; clear flags | |
215 bcf first_FD | |
216 return ; return | |
217 | |
218 | |
219 I2CREAD: | |
245
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
220 rcall I2CREAD_COMMON |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
221 bsf SSPCON2, PEN ; Stop |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
222 rcall WaitMSSP |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
223 return |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
224 |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
225 I2CREAD2: ; same as I2CREAD but with automatic address increase |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
226 rcall I2CREAD |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
227 I2CREAD2_2: |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
228 movlw d'1' |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
229 addwf eeprom_address+0,F |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
230 movlw d'0' |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
231 addwfc eeprom_address+1,F |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
232 return |
350
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
233 ; btfss eeprom_address+1,7 ; at 0x8000? |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
234 ; return ; no, return |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
235 ; |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
236 ; clrf eeprom_address+0 ; Yes, clear address |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
237 ; clrf eeprom_address+1 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
238 ; return |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
239 ; |
245
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
240 I2CREAD3: ; block read start with automatic address increase |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
241 rcall I2CREAD_COMMON |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
242 ; no Stop condition here |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
243 bra I2CREAD2_2 |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
244 |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
245 I2CREAD4: ; block read with automatic address increase |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
246 bsf SSPCON2,ACKEN ; Master acknowlegde |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
247 rcall WaitMSSP |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
248 bsf SSPCON2, RCEN ; Enable recieve mode |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
249 rcall WaitMSSP |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
250 movf SSPBUF,W ; copy read byte into WREG |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
251 ; no Stop condition here |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
252 bra I2CREAD2_2 |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
253 |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
254 |
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
255 I2CREAD_COMMON: |
0 | 256 bsf SSPCON2, PEN ; Stop |
257 rcall WaitMSSP | |
258 bsf SSPCON2,SEN ; Start condition | |
259 rcall WaitMSSP | |
350
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
260 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
261 movlw b'10101110' ; Bit0=0: WRITE, Bit0=1: READ, BLOCK2 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
262 btfss eeprom_address+1,7 ; Access Block2? |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
263 movlw b'10100110' ; No, -> Bit0=0: WRITE, Bit0=1: READ, BLOCK1 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
264 movwf SSPBUF ; control byte |
0 | 265 rcall WaitMSSP |
266 btfsc SSPCON2,ACKSTAT | |
267 bra I2CREAD ; EEPROM NOT acknowledged, retry! | |
268 movff eeprom_address+1,SSPBUF ; High Address byte | |
269 rcall WaitMSSP | |
270 rcall I2C_WaitforACK | |
271 movff eeprom_address+0,SSPBUF ; Low Address byte | |
272 rcall WaitMSSP | |
273 rcall I2C_WaitforACK | |
274 | |
275 bsf SSPCON2,RSEN ; Start condition | |
276 rcall WaitMSSP | |
350
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
277 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
278 movlw b'10101111' ; Bit0=0: WRITE, Bit0=1: READ, BLOCK2 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
279 btfss eeprom_address+1,7 ; Access Block2? |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
280 movlw b'10100111' ; No, -> Bit0=0: WRITE, Bit0=1: READ, BLOCK1 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
281 movwf SSPBUF ; control byte |
0 | 282 rcall WaitMSSP |
283 rcall I2C_WaitforACK | |
284 | |
285 bsf SSPCON2, RCEN ; Enable recieve mode | |
286 rcall WaitMSSP | |
287 movf SSPBUF,W ; copy read byte into WREG | |
288 return | |
289 | |
245
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
290 |
0 | 291 I2CWRITE: |
292 movwf ext_ee_temp1 ; Data byte | |
293 bsf SSPCON2,SEN ; Start condition | |
294 rcall WaitMSSP | |
350
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
295 movlw b'10101110' ; Bit0=0: WRITE, Bit0=1: READ, BLOCK2 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
296 btfss eeprom_address+1,7 ; Access Block2? |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
297 movlw b'10100110' ; No, -> Bit0=0: WRITE, Bit0=1: READ, BLOCK1 |
7250ca7c8d24
64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents:
245
diff
changeset
|
298 movwf SSPBUF ; control byte |
0 | 299 rcall WaitMSSP |
300 rcall I2C_WaitforACK | |
301 movff eeprom_address+1,SSPBUF ; High Address byte | |
302 rcall WaitMSSP | |
303 rcall I2C_WaitforACK | |
304 movff eeprom_address+0,SSPBUF ; Low Address byte | |
305 rcall WaitMSSP | |
306 rcall I2C_WaitforACK | |
307 movff ext_ee_temp1, SSPBUF ; Data Byte | |
308 rcall WaitMSSP | |
309 rcall I2C_WaitforACK | |
310 bsf SSPCON2,PEN ; Stop condition | |
311 rcall WaitMSSP | |
245
dee88c962653
Some clean up and minor I2C speed improvements
heinrichsweikamp
parents:
148
diff
changeset
|
312 WAITMS d'5' ; Write delay |
0 | 313 return |
314 | |
315 I2C_WaitforACK: | |
316 btfsc SSPCON2,ACKSTAT ; checks for ACK bit from slave | |
317 rcall I2CFail | |
318 return | |
319 | |
320 I2CFail: | |
321 ostc_debug 'M' ; Sends debug-information to screen if debugmode active | |
21 | 322 bsf LED_red |
0 | 323 rcall I2CReset ; I2C Reset |
324 bcf PIR1,SSPIF | |
325 clrf i2c_temp | |
326 return | |
327 | |
328 WaitMSSP: | |
329 decfsz i2c_temp,F ; check for timeout during I2C action | |
330 bra WaitMSSP2 | |
331 bra I2CFail ; timeout occured | |
332 WaitMSSP2: | |
333 btfss PIR1,SSPIF | |
334 bra WaitMSSP | |
335 clrf i2c_temp | |
336 bcf PIR1,SSPIF | |
337 return | |
338 | |
339 I2CReset: ; Something went wrong (Slave holds SDA low?) | |
340 clrf SSPCON1 ; wake-up slave and reset entire module | |
341 ostc_debug 'N' ; Sends debug-information to screen if debugmode active | |
342 clrf SSPCON2 | |
343 clrf SSPSTAT | |
344 bcf TRISC,3 ; SCL OUTPUT | |
345 bsf TRISC,4 ; SDA Input | |
346 bcf PORTC,3 | |
347 movlw d'9' | |
348 movwf i2c_temp ; clock-out 9 clock cycles manually | |
349 I2CReset_1: | |
350 bsf PORTC,3 ; SCL=1 | |
351 nop | |
352 btfsc PORTC,4 ; SDA=1? | |
353 bra I2CReset_2 ; =1, SDA has been released from slave | |
354 bcf PORTC,3 ; SCL=0 | |
355 bcf PORTC,3 | |
356 decfsz i2c_temp,F | |
357 bra I2CReset_1 ; check for nine clock cycles | |
358 I2CReset_2: | |
359 bsf TRISC,3 ; SCL Input | |
360 clrf SSPCON1 ; set I²C Mode | |
361 WAITMS d'10' ; Reset-Timeout for I2C devices | |
362 movlw b'00000000' | |
363 movwf SSPSTAT | |
364 movlw b'00101000' | |
365 movwf SSPCON1 | |
366 movlw b'00000000' | |
367 movwf SSPCON2 | |
368 movlw d'8' ; 400kHz I2C clock @ 16MHz Fcy | |
369 movwf SSPADD | |
21 | 370 bcf LED_red |
0 | 371 ostc_debug 'O' ; Sends debug-information to screen if debugmode active |
372 return | |
53 | 373 |
374 ;I2C_TX: | |
375 ; movwf i2c_temp2 ; Data byte | |
376 ; bsf SSPCON2,SEN ; Start condition | |
377 ; rcall WaitMSSP | |
378 ; movlw b'10010000' ; Bit0=0: WRITE, Bit0=1: READ | |
379 ; movwf SSPBUF ; control byte | |
380 ; rcall WaitMSSP | |
381 ; rcall I2C_WaitforACK | |
382 ; movff i2c_temp2, SSPBUF ; Data Byte | |
383 ; rcall WaitMSSP | |
384 ; rcall I2C_WaitforACK | |
385 ; bsf SSPCON2,PEN ; Stop condition | |
386 ; rcall WaitMSSP | |
387 ; return | |
388 ;I2C_RX: | |
389 ; bcf PIR1,SSPIF | |
390 ; bsf SSPCON2,SEN ; Start condition | |
391 ; rcall WaitMSSP | |
392 ; movlw b'10010001' ; Bit0=0: WRITE, Bit0=1: READ | |
393 ; movwf SSPBUF ; control byte | |
394 ; rcall WaitMSSP | |
395 ; rcall I2C_WaitforACK | |
396 ; bsf SSPCON2, RCEN ; Enable recieve mode | |
397 ; rcall WaitMSSP | |
398 ; movff SSPBUF,i2c_temp2 ; Data Byte | |
399 ; bsf SSPCON2,ACKEN ; Master acknowlegde | |
400 ; rcall WaitMSSP | |
401 ; bsf SSPCON2,PEN ; Stop condition | |
402 ; rcall WaitMSSP | |
403 ; return |