annotate code_part1/OSTC_code_asm_part1/i2c_eeprom.asm @ 737:6ec145626fbc

french text update
author heinrichsweikamp
date Thu, 27 Jun 2013 08:28:30 +0200
parents 16f4eafc197e
children c50296c3059e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
2 ; OSTC - diving computer code
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
3 ; Copyright (C) 2008 HeinrichsWeikamp GbR
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
4 ; This program is free software: you can redistribute it and/or modify
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
5 ; it under the terms of the GNU General Public License as published by
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
6 ; the Free Software Foundation, either version 3 of the License, or
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
7 ; (at your option) any later version.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
8 ; This program is distributed in the hope that it will be useful,
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
9 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
10 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
11 ; GNU General Public License for more details.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
12 ; You should have received a copy of the GNU General Public License
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
13 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
14 ; provides routines for external EEPROM via I2C
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
15 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com
573
77c8ff191cd7 Preparations for third bank of Custom Functions
heinrichsweikamp
parents: 539
diff changeset
16 ; written: 051030
77c8ff191cd7 Preparations for third bank of Custom Functions
heinrichsweikamp
parents: 539
diff changeset
17 ; last updated: 120421
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
18 ; known bugs:
573
77c8ff191cd7 Preparations for third bank of Custom Functions
heinrichsweikamp
parents: 539
diff changeset
19 ; ToDo:
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
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
055977afc2f9 Make loogbook search twice faster.
JeanDo
parents: 83
diff changeset
23 call incf_eeprom_address0
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
24 endm
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
25
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
26 incf_eeprom_address0:
148
055977afc2f9 Make loogbook search twice faster.
JeanDo
parents: 83
diff changeset
27 addwf eeprom_address+0,F ; increase address
055977afc2f9 Make loogbook search twice faster.
JeanDo
parents: 83
diff changeset
28 movlw d'0'
055977afc2f9 Make loogbook search twice faster.
JeanDo
parents: 83
diff changeset
29 addwfc eeprom_address+1,F
350
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
30 return
425
a76c5a3e9e96 Minor cleanups
JeanDo
parents: 350
diff changeset
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
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
34
148
055977afc2f9 Make loogbook search twice faster.
JeanDo
parents: 83
diff changeset
35
055977afc2f9 Make loogbook search twice faster.
JeanDo
parents: 83
diff changeset
36 decf_eeprom_address macro ext_ee_temp1
055977afc2f9 Make loogbook search twice faster.
JeanDo
parents: 83
diff changeset
37 movlw ext_ee_temp1
055977afc2f9 Make loogbook search twice faster.
JeanDo
parents: 83
diff changeset
38 call decf_eeprom_address0
055977afc2f9 Make loogbook search twice faster.
JeanDo
parents: 83
diff changeset
39 endm
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
40
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
41 decf_eeprom_address0:
148
055977afc2f9 Make loogbook search twice faster.
JeanDo
parents: 83
diff changeset
42 subwf eeprom_address+0,F ; decrease address: do a 16-8bits substract.
055977afc2f9 Make loogbook search twice faster.
JeanDo
parents: 83
diff changeset
43 movlw d'0'
055977afc2f9 Make loogbook search twice faster.
JeanDo
parents: 83
diff changeset
44 subwfb eeprom_address+1,F
350
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
45 return
148
055977afc2f9 Make loogbook search twice faster.
JeanDo
parents: 83
diff changeset
46
055977afc2f9 Make loogbook search twice faster.
JeanDo
parents: 83
diff changeset
47 ;=============================================================================
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
48
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
49 write_external_eeprom: ; data in WREG
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
50 ; increase address eeprom_address+0:eeprom_address+1 after write
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
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
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
57 rcall I2CWRITE ; writes WREG into EEPROM@eeprom_address
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
58 movlw d'1' ; increase address
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
59 addwf eeprom_address+0,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
60 movlw d'0'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
61 addwfc eeprom_address+1,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
62 return
573
77c8ff191cd7 Preparations for third bank of Custom Functions
heinrichsweikamp
parents: 539
diff changeset
63
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
64 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
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
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
70 btfsc eeprom_blockwrite ; Blockwrite continue?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
71 rcall I2CWRITE_BLOCK2
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
72 btfss eeprom_blockwrite ; Blockwrite start?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
73 rcall I2CWRITE_BLOCK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
74 bsf eeprom_blockwrite ; After the start, do blockwriting for the next 63Bytes!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
75
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
76 movlw d'0' ; increase address
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
77 incf eeprom_address+0,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
78 addwfc eeprom_address+1,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
79 return
350
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
80
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
81 I2CWRITE_BLOCK:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
82 movwf ext_ee_temp1 ; Data byte in WREG
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
83 bsf SSPCON2,SEN ; Start condition
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
84 rcall WaitMSSP
350
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
85 movlw b'10101110' ; Bit0=0: WRITE, Bit0=1: READ, BLOCK2
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
86 btfss eeprom_address+1,7 ; Access Block2?
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
87 movlw b'10100110' ; No, -> Bit0=0: WRITE, Bit0=1: READ, BLOCK1
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
88 movwf SSPBUF ; control byte
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
89 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
90 rcall I2C_WaitforACK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
91 movff eeprom_address+1,SSPBUF ; High Address byte
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
92 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
93 rcall I2C_WaitforACK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
94 movff eeprom_address+0,SSPBUF ; Low Address byte
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
95 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
96 rcall I2C_WaitforACK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
97 I2CWRITE_BLOCK2:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
98 movff ext_ee_temp1, SSPBUF ; Data Byte
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
99 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
100 rcall I2C_WaitforACK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
101 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
102
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
103
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
104 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
105
31fa973a70fd Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents: 53
diff changeset
106 #ifdef TESTING
31fa973a70fd Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents: 53
diff changeset
107 ; 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
108 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
109 movlw 0x1
31fa973a70fd Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents: 53
diff changeset
110 movwf eeprom_address+1
31fa973a70fd Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents: 53
diff changeset
111 return
31fa973a70fd Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents: 53
diff changeset
112 #endif
31fa973a70fd Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents: 53
diff changeset
113
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
114 clrf ext_ee_temp1 ; low address counter
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
115 clrf ext_ee_temp2 ; high address counter
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
116 bcf second_FD ; clear flags
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
117 bcf first_FD
455
c512a868937c last work for 2.0: Fixing 32kB boundary read for logbook
heinrichsweikamp
parents: 425
diff changeset
118 bcf eeprom_switched_b1
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
119 get_free_EEPROM_location3:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
120 bsf SSPCON2, PEN ; Stop condition
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
121 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
122 bsf SSPCON2,SEN ; Start condition
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
123 rcall WaitMSSP
350
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
124 movlw b'10101110' ; Bit0=0: WRITE, Bit0=1: READ, BLOCK2
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
125 btfss ext_ee_temp2,7 ; Access Block2?
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
126 movlw b'10100110' ; No, -> Bit0=0: WRITE, Bit0=1: READ, BLOCK1
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
127 movwf SSPBUF ; control byte
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
128 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
129 btfsc SSPCON2,ACKSTAT
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
130 bra get_free_EEPROM_location3 ; EEPROM NOT acknowledged, retry!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
131
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
132 movff ext_ee_temp2,SSPBUF ; High Address byte
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
133 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
134 rcall I2C_WaitforACK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
135 movff ext_ee_temp1,SSPBUF ; Low Address byte
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
136 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
137 rcall I2C_WaitforACK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
138
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
139 bsf SSPCON2,RSEN ; Start condition
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
140 rcall WaitMSSP
350
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
141 movlw b'10101111' ; Bit0=0: WRITE, Bit0=1: READ, BLOCK2
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
142 btfss ext_ee_temp2,7 ; Access Block2?
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
143 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
144 movwf SSPBUF ; control byte
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
145 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
146 rcall I2C_WaitforACK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
147
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
148 get_free_EEPROM_location2:
455
c512a868937c last work for 2.0: Fixing 32kB boundary read for logbook
heinrichsweikamp
parents: 425
diff changeset
149 btfsc eeprom_switched_b1 ; Switched to Block1 already?
c512a868937c last work for 2.0: Fixing 32kB boundary read for logbook
heinrichsweikamp
parents: 425
diff changeset
150 bra get_free_EEPROM_location2_x ; Yes, skip this check!
c512a868937c last work for 2.0: Fixing 32kB boundary read for logbook
heinrichsweikamp
parents: 425
diff changeset
151
c512a868937c last work for 2.0: Fixing 32kB boundary read for logbook
heinrichsweikamp
parents: 425
diff changeset
152 btfsc ext_ee_temp2,7 ; Access Block1?
c512a868937c last work for 2.0: Fixing 32kB boundary read for logbook
heinrichsweikamp
parents: 425
diff changeset
153 bsf eeprom_switched_b1 ; Yes, and set the flag so this check is skipped in the rest of this routine
c512a868937c last work for 2.0: Fixing 32kB boundary read for logbook
heinrichsweikamp
parents: 425
diff changeset
154 btfsc ext_ee_temp2,7 ; Access Block1?
c512a868937c last work for 2.0: Fixing 32kB boundary read for logbook
heinrichsweikamp
parents: 425
diff changeset
155 bra get_free_EEPROM_location3 ; Yes, initiate new read sequence in block1
c512a868937c last work for 2.0: Fixing 32kB boundary read for logbook
heinrichsweikamp
parents: 425
diff changeset
156
c512a868937c last work for 2.0: Fixing 32kB boundary read for logbook
heinrichsweikamp
parents: 425
diff changeset
157 get_free_EEPROM_location2_x:
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
158 bsf SSPCON2, RCEN ; Enable recieve mode
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
159 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
160 btfsc first_FD
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
161 bra test_2nd_FD
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
162 bsf first_FD ; found first 0xFD?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
163 movlw 0xFD
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
164 cpfseq SSPBUF
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
165 bcf first_FD ; No
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
166 bra get_free_EEPROM_location2c
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
167
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
168 test_2nd_FD:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
169 btfsc second_FD
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
170 bra test_FE
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
171 bsf second_FD ; found second 0xFD?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
172 movlw 0xFD
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
173 cpfseq SSPBUF
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
174 bra get_free_EEPROM_location2b ;No, clear both flags
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
175 bra get_free_EEPROM_location2c
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
176 test_FE:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
177 movlw 0xFE ; found the final 0xFE?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
178 cpfseq SSPBUF
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
179 bra get_free_EEPROM_location2b ;No, clear both flags
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
180 movff ext_ee_temp1,eeprom_address+0 ;Yes, copy ext_ee_temp1->eeprom_address+0 and
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
181 movff ext_ee_temp2,eeprom_address+1 ;ext_ee_temp2->eeprom_address+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
182 bra get_free_EEPROM_location4 ; Done.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
183
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
184 get_free_EEPROM_location2b:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
185 bcf second_FD ; clear both flags!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
186 bcf first_FD
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
187 get_free_EEPROM_location2c:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
188 movlw d'1' ; and increase search address
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
189 addwf ext_ee_temp1,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
190 movlw d'0'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
191 addwfc ext_ee_temp2,F
350
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
192
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
193 movlw 0xFF
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
194 cpfseq ext_ee_temp2 ; =0xFFFF
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
195 bra get_free_EEPROM_location2d ; No
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
196 cpfseq ext_ee_temp1 ; =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
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
199 bra get_free_EEPROM_location3b ; yes
350
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
200
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
201 get_free_EEPROM_location2d:
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
202 bsf SSPCON2, ACKEN ; no, send Ack
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
203 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
204 bra get_free_EEPROM_location2 ; and continue search
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
205 get_free_EEPROM_location3b:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
206 clrf eeprom_address+0 ; Not found in entire EEPROM, set to address 0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
207 clrf eeprom_address+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
208 get_free_EEPROM_location4:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
209 bsf SSPCON2, PEN ; Stop
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
210 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
211
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
212 bcf second_FD ; clear flags
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
213 bcf first_FD
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
214 return ; return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
215
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
216
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
217 I2CREAD:
245
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
218 rcall I2CREAD_COMMON
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
219 bsf SSPCON2, PEN ; Stop
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
220 rcall WaitMSSP
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
221 return
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
222
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
223 I2CREAD2: ; same as I2CREAD but with automatic address increase
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
224 rcall I2CREAD
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
225 I2CREAD2_2:
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
226 movlw d'1'
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
227 addwf eeprom_address+0,F
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
228 movlw d'0'
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
229 addwfc eeprom_address+1,F
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
230 return
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
231 I2CREAD3: ; block read start with automatic address increase
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
232 rcall I2CREAD_COMMON
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
233 ; no Stop condition here
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
234 bra I2CREAD2_2
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
235
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
236 I2CREAD4: ; block read with automatic address increase
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
237 bsf SSPCON2,ACKEN ; Master acknowlegde
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
238 rcall WaitMSSP
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
239 bsf SSPCON2, RCEN ; Enable recieve mode
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
240 rcall WaitMSSP
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
241 movf SSPBUF,W ; copy read byte into WREG
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
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
246 I2CREAD_COMMON:
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
247 bsf SSPCON2, PEN ; Stop
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
248 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
249 bsf SSPCON2,SEN ; Start condition
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
250 rcall WaitMSSP
350
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
251
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
252 movlw b'10101110' ; Bit0=0: WRITE, Bit0=1: READ, BLOCK2
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
253 btfss eeprom_address+1,7 ; Access Block2?
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
254 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
255 movwf SSPBUF ; control byte
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
256 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
257 btfsc SSPCON2,ACKSTAT
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
258 bra I2CREAD ; EEPROM NOT acknowledged, retry!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
259 movff eeprom_address+1,SSPBUF ; High Address byte
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
260 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
261 rcall I2C_WaitforACK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
262 movff eeprom_address+0,SSPBUF ; Low Address byte
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
263 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
264 rcall I2C_WaitforACK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
265
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
266 bsf SSPCON2,RSEN ; Start condition
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
267 rcall WaitMSSP
350
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
268
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
269 movlw b'10101111' ; Bit0=0: WRITE, Bit0=1: READ, BLOCK2
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
270 btfss eeprom_address+1,7 ; Access Block2?
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
271 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
272 movwf SSPBUF ; control byte
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
273 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
274 rcall I2C_WaitforACK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
275
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
276 bsf SSPCON2, RCEN ; Enable recieve mode
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
277 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
278 movf SSPBUF,W ; copy read byte into WREG
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
279 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
280
245
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
281
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
282 I2CWRITE:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
283 movwf ext_ee_temp1 ; Data byte
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
284 bsf SSPCON2,SEN ; Start condition
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
285 rcall WaitMSSP
350
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
286 movlw b'10101110' ; Bit0=0: WRITE, Bit0=1: READ, BLOCK2
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
287 btfss eeprom_address+1,7 ; Access Block2?
7250ca7c8d24 64kByte logbook (Still incompatible to existing PC software)
heinrichsweikamp
parents: 245
diff changeset
288 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
289 movwf SSPBUF ; control byte
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
290 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
291 rcall I2C_WaitforACK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
292 movff eeprom_address+1,SSPBUF ; High Address byte
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
293 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
294 rcall I2C_WaitforACK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
295 movff eeprom_address+0,SSPBUF ; Low Address byte
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
296 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
297 rcall I2C_WaitforACK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
298 movff ext_ee_temp1, SSPBUF ; Data Byte
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
299 rcall WaitMSSP
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
300 rcall I2C_WaitforACK
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
301 bsf SSPCON2,PEN ; Stop condition
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
302 rcall WaitMSSP
245
dee88c962653 Some clean up and minor I2C speed improvements
heinrichsweikamp
parents: 148
diff changeset
303 WAITMS d'5' ; Write delay
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
304 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
305
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
306 I2C_WaitforACK:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
307 btfsc SSPCON2,ACKSTAT ; checks for ACK bit from slave
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
308 rcall I2CFail
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
309 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
310
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
311 I2CFail:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
312 ostc_debug 'M' ; Sends debug-information to screen if debugmode active
21
73014f788032 1.60 stable rc1
heinrichsweikamp
parents: 0
diff changeset
313 bsf LED_red
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
314 rcall I2CReset ; I2C Reset
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
315 bcf PIR1,SSPIF
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
316 clrf i2c_temp
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
317 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
318
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
319 WaitMSSP:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
320 decfsz i2c_temp,F ; check for timeout during I2C action
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
321 bra WaitMSSP2
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
322 bra I2CFail ; timeout occured
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
323 WaitMSSP2:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
324 btfss PIR1,SSPIF
595
16f4eafc197e CNS for pSCR-GF fixed.
heinrichsweikamp
parents: 573
diff changeset
325 bra WaitMSSP
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
326 clrf i2c_temp
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
327 bcf PIR1,SSPIF
595
16f4eafc197e CNS for pSCR-GF fixed.
heinrichsweikamp
parents: 573
diff changeset
328 nop
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
329 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
330
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
331 I2CReset: ; Something went wrong (Slave holds SDA low?)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
332 clrf SSPCON1 ; wake-up slave and reset entire module
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
333 ostc_debug 'N' ; Sends debug-information to screen if debugmode active
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
334 clrf SSPCON2
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
335 clrf SSPSTAT
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
336 bcf TRISC,3 ; SCL OUTPUT
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
337 bsf TRISC,4 ; SDA Input
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
338 bcf PORTC,3
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
339 movlw d'9'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
340 movwf i2c_temp ; clock-out 9 clock cycles manually
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
341 I2CReset_1:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
342 bsf PORTC,3 ; SCL=1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
343 nop
539
a587f491693d clock in I2C "bus failed" routine
heinrichsweikamp
parents: 537
diff changeset
344 nop
a587f491693d clock in I2C "bus failed" routine
heinrichsweikamp
parents: 537
diff changeset
345 nop
a587f491693d clock in I2C "bus failed" routine
heinrichsweikamp
parents: 537
diff changeset
346 nop
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
347 btfsc PORTC,4 ; SDA=1?
539
a587f491693d clock in I2C "bus failed" routine
heinrichsweikamp
parents: 537
diff changeset
348 bra I2CReset_2 ; =1, SDA has been released from slave
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
349 bcf PORTC,3 ; SCL=0
539
a587f491693d clock in I2C "bus failed" routine
heinrichsweikamp
parents: 537
diff changeset
350 nop
a587f491693d clock in I2C "bus failed" routine
heinrichsweikamp
parents: 537
diff changeset
351 nop
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
352 bcf PORTC,3
539
a587f491693d clock in I2C "bus failed" routine
heinrichsweikamp
parents: 537
diff changeset
353 nop
a587f491693d clock in I2C "bus failed" routine
heinrichsweikamp
parents: 537
diff changeset
354 nop
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
355 decfsz i2c_temp,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
356 bra I2CReset_1 ; check for nine clock cycles
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
357 I2CReset_2:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
358 bsf TRISC,3 ; SCL Input
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
359 clrf SSPCON1 ; set I²C Mode
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
360 WAITMS d'10' ; Reset-Timeout for I2C devices
537
3091628b2742 BUGFIX: Spurious logbook read issue
heinrichsweikamp
parents: 455
diff changeset
361 movlw SSPSTAT_VALUE
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
362 movwf SSPSTAT
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
363 movlw b'00101000'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
364 movwf SSPCON1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
365 movlw b'00000000'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
366 movwf SSPCON2
537
3091628b2742 BUGFIX: Spurious logbook read issue
heinrichsweikamp
parents: 455
diff changeset
367 movlw SSPADD_VALUE
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
368 movwf SSPADD
21
73014f788032 1.60 stable rc1
heinrichsweikamp
parents: 0
diff changeset
369 bcf LED_red
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
370 ostc_debug 'O' ; Sends debug-information to screen if debugmode active
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
371 return
53
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
372
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
373 ;I2C_TX:
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
374 ; movwf i2c_temp2 ; Data byte
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
375 ; bsf SSPCON2,SEN ; Start condition
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
376 ; rcall WaitMSSP
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
377 ; movlw b'10010000' ; Bit0=0: WRITE, Bit0=1: READ
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
378 ; movwf SSPBUF ; control byte
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
379 ; rcall WaitMSSP
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
380 ; rcall I2C_WaitforACK
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
381 ; movff i2c_temp2, SSPBUF ; Data Byte
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
382 ; rcall WaitMSSP
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
383 ; rcall I2C_WaitforACK
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
384 ; bsf SSPCON2,PEN ; Stop condition
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
385 ; rcall WaitMSSP
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
386 ; return
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
387 ;I2C_RX:
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
388 ; bcf PIR1,SSPIF
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
389 ; bsf SSPCON2,SEN ; Start condition
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
390 ; rcall WaitMSSP
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
391 ; movlw b'10010001' ; Bit0=0: WRITE, Bit0=1: READ
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
392 ; movwf SSPBUF ; control byte
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
393 ; rcall WaitMSSP
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
394 ; rcall I2C_WaitforACK
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
395 ; bsf SSPCON2, RCEN ; Enable recieve mode
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
396 ; rcall WaitMSSP
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
397 ; movff SSPBUF,i2c_temp2 ; Data Byte
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
398 ; bsf SSPCON2,ACKEN ; Master acknowlegde
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
399 ; rcall WaitMSSP
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
400 ; bsf SSPCON2,PEN ; Stop condition
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
401 ; rcall WaitMSSP
263348f83485 1.70 cleaning the code
heinrichsweikamp
parents: 42
diff changeset
402 ; return