Mercurial > public > mk2
annotate code_part1/OSTC_code_asm_part1/eeprom_rs232.asm @ 555:43296991c283
BUGFIX: CF55 (gas switch delay) should not add fake stops when null.
author | JeanDo |
---|---|
date | Mon, 13 Feb 2012 00:18:13 +0100 |
parents | 3091628b2742 |
children | fbd5e2b75a63 |
rev | line source |
---|---|
0 | 1 ; OSTC - diving computer code |
2 ; Copyright (C) 2008 HeinrichsWeikamp GbR | |
3 | |
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 | |
9 ; This program is distributed in the hope that it will be useful, | |
10 ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 ; GNU General Public License for more details. | |
13 | |
14 ; You should have received a copy of the GNU General Public License | |
15 ; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | |
17 | |
18 ; internal EEPROM and RS232 UART interface | |
19 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com | |
20 ; written: 02/01/06 | |
21 ; last updated: 090109 | |
22 ; known bugs: | |
23 ; ToDo: | |
24 | |
25 write_int_eeprom macro eeprom_address | |
26 movlw eeprom_address | |
27 call write_int_eeprom_1 | |
28 endm | |
29 | |
30 write_int_eeprom_1: | |
31 movwf EEADR | |
32 bra write_eeprom ; writes and "returns" after write | |
33 | |
34 read_int_eeprom macro eeprom_address | |
35 movlw eeprom_address | |
36 call read_int_eeprom_1 | |
37 endm | |
38 | |
39 read_int_eeprom_1: | |
40 movwf EEADR | |
41 bra read_eeprom ; reads and "returns" after write | |
42 | |
43 internal_eeprom_access_b1: ; accesses internal EEPROM BANK 1 via the UART | |
44 bcf internal_eeprom_write2 ; clear flag! | |
45 movlw d'1' | |
46 movwf EEADRH ;BANK1 | |
47 movlw "i" | |
48 bra internal_eeprom_access1 ; Continue with bank1 and bank0 common routines | |
49 | |
50 internal_eeprom_access_b0: ; accesses internal EEPROM BANK 0 via the UART | |
51 bcf internal_eeprom_write ; clear flag! | |
52 clrf EEADRH ; Bank0 | |
53 movlw "d" | |
54 ; bra internal_eeprom_access1 ; Continue with bank1 and bank0 common routines | |
55 | |
56 internal_eeprom_access1: | |
57 movwf TXREG ; Send command echo ("i" or "d") | |
58 bsf no_sensor_int ; No Sensor Interrupt | |
59 movlw d'4' | |
60 movwf EEADR | |
61 bcf PIE1,RCIE ; no interrupt for UART | |
62 bcf PIR1,RCIF ; clear flag | |
21 | 63 bsf LED_blue ; LEDusb ON |
0 | 64 |
65 internal_eeprom_access2: | |
66 rcall rs232_get_byte ; Get byte to write... | |
67 movff RCREG,EEDATA ; copy to write register | |
21 | 68 bsf LED_red ; show activity |
0 | 69 |
70 btfsc rs232_recieve_overflow ; overflow recieved? | |
71 bra internal_eeprom_access3 ; Yes, abort! | |
72 | |
73 rcall write_eeprom ; No, write one byte | |
21 | 74 bcf LED_red |
0 | 75 movff EEDATA,TXREG ; Send echo! |
76 rcall rs232_wait_tx ; Wait for UART | |
77 incfsz EEADR,F ; Do until EEADR rolls to zero | |
78 bra internal_eeprom_access2 | |
79 internal_eeprom_access2a: | |
21 | 80 bcf LED_blue ; LEDusb OFF |
0 | 81 bcf PIR1,RCIF ; clear flag |
82 bsf PIE1,RCIE ; re-enable interrupt for UART | |
83 clrf EEADRH ; Point to Bank0 again | |
84 bcf rs232_recieve_overflow ; Clear Flag | |
85 bcf no_sensor_int ; Renable Sensor Interrupt | |
86 goto restart | |
87 | |
88 internal_eeprom_access3: ; Overflow! Abort writing | |
89 movlw 0xFF | |
90 movwf TXREG ; Error Byte | |
91 bra internal_eeprom_access2a ; Quit | |
92 | |
93 read_eeprom: ; reads from internal eeprom | |
94 bcf EECON1,EEPGD | |
95 bcf EECON1,CFGS | |
96 bsf EECON1,RD | |
97 return | |
98 | |
99 write_eeprom: ; writes into internal eeprom | |
100 bcf EECON1,EEPGD | |
101 bcf EECON1,CFGS | |
102 bsf EECON1,WREN | |
103 | |
104 bcf INTCON,GIE ; even the RTC will be delayed for the next 5 instructions... | |
105 movlw 0x55 | |
106 movwf EECON2 | |
107 movlw 0xAA | |
108 movwf EECON2 | |
109 bsf EECON1,WR | |
110 bsf INTCON,GIE ; ...but the flag for the ISR routines were still set, so they will interrupt now! | |
111 | |
112 write_eep2: | |
113 btfsc EECON1,WR | |
114 bra write_eep2 ; wait about 4ms... | |
115 bcf EECON1,WREN | |
116 return | |
117 | |
118 enable_rs232: ;IO Ports must be input in order to activate the module | |
119 bsf TRISC,6 ; TX Pin | |
120 bsf TRISC,7 ; RX Pin | |
121 | |
122 movlw b'00100100' ; BRGH=1 | |
123 movwf TXSTA | |
124 movlw b'10010000' | |
125 movwf RCSTA | |
126 movlw b'00001000' | |
127 movwf BAUDCON | |
128 clrf SPBRGH | |
463 | 129 movlw SPBRG_VALUE ; Take care of the baud rate when changing Fosc! |
0 | 130 movwf SPBRG |
131 clrf RCREG | |
132 clrf PIR1 | |
133 bsf PIE1,RCIE ; enable interrupt for RS232 | |
134 return | |
135 | |
136 disable_rs232: | |
137 clrf TXSTA | |
138 clrf RCSTA | |
139 bcf PIE1,RCIE ; disable interrupt for RS232 | |
140 bcf TRISC,6 ; TX Pin | |
141 bcf TRISC,7 ; RX Pin | |
142 bcf PORTC,6 ; TX Pin | |
143 bcf PORTC,7 ; RX Pin | |
144 return | |
145 | |
146 rs232_wait_tx: | |
147 btfss RCSTA,SPEN ; Transmitter active? | |
148 return ; No, return! | |
149 nop | |
150 btfss TXSTA,TRMT ; RS232 Busy? | |
151 bra rs232_wait_tx ; yes, wait... | |
152 return ; Done. | |
153 | |
154 | |
155 rs232_get_byte: | |
156 bcf PIR1,RCIF ; clear flag | |
157 bcf rs232_recieve_overflow ; clear flag | |
158 clrf uart1_temp | |
159 rs232_get_byte2: | |
160 clrf uart2_temp | |
161 rs232_get_byte3: | |
162 btfsc PIR1,RCIF ; data arrived? | |
163 return ; data received | |
164 | |
165 nop ; Wait 1us * 255 * 255 = 65ms+x Timeout/Byte | |
166 nop | |
167 nop | |
168 nop | |
169 nop | |
170 nop | |
171 nop | |
172 nop | |
173 btfsc PIR1,RCIF ; data arrived? | |
174 return | |
529 | 175 nop |
176 nop | |
177 nop | |
178 nop | |
0 | 179 nop |
180 nop | |
181 nop | |
182 nop | |
183 btfsc PIR1,RCIF ; data arrived? | |
184 return | |
185 nop | |
186 nop | |
187 nop | |
188 nop | |
529 | 189 nop |
190 nop | |
191 nop | |
192 nop | |
193 btfsc PIR1,RCIF ; data arrived? | |
194 return | |
195 nop | |
196 nop | |
197 nop | |
198 nop | |
199 nop | |
200 nop | |
201 nop | |
202 nop | |
0 | 203 btfsc PIR1,RCIF ; data arrived? |
204 return | |
205 | |
206 decfsz uart2_temp,F | |
207 bra rs232_get_byte3 | |
208 decfsz uart1_temp,F | |
209 bra rs232_get_byte2 | |
210 ; timeout occoured (about 20ms) | |
211 bcf RCSTA,CREN ; Clear receiver status | |
212 bsf RCSTA,CREN | |
213 bsf rs232_recieve_overflow ; set flag | |
283
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
50
diff
changeset
|
214 return ; and return anyway |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
50
diff
changeset
|
215 |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
50
diff
changeset
|
216 uart_115k_bootloader: |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
50
diff
changeset
|
217 bcf PIE1,RCIE ; disable interrupt for RS232 |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
50
diff
changeset
|
218 call PLED_ClearScreen ; Clear screen |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
50
diff
changeset
|
219 movlw color_red |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
50
diff
changeset
|
220 call PLED_set_color ; Set to Red |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
50
diff
changeset
|
221 DISPLAYTEXTH d'302' ; Bootloader |
537 | 222 bcf RCSTA,CREN ; Clear receiver status |
223 bsf RCSTA,CREN | |
224 bcf PIR1,RCIF ; clear flag | |
225 movlw d'200' ; one second | |
284
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
226 movwf uart1_temp |
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
227 uart_115k_bootloader0: |
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
228 btfsc PIR1,RCIF ; New byte in UART? |
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
229 bra uart_115k_bootloader1 ; Yes, Check if 0xC1 |
537 | 230 WAITMS d'5' |
284
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
231 decfsz uart1_temp,F |
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
232 bra uart_115k_bootloader0 |
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
233 uart_115k_bootloader2: |
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
234 DISPLAYTEXTH d'304' ; Aborted! |
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
235 movlw d'8' ; Two seconds |
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
236 movwf uart1_temp |
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
237 uart_115k_bootloader3: |
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
238 WAITMS d'250' |
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
239 decfsz uart1_temp,F |
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
240 bra uart_115k_bootloader3 |
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
241 goto restart |
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
242 |
908d0013727e
115200 baud bootloader tested and debugged
heinrichsweikamp
parents:
283
diff
changeset
|
243 uart_115k_bootloader1: |
283
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
50
diff
changeset
|
244 movlw 0xC1 |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
50
diff
changeset
|
245 cpfseq RCREG ; 115200Baud Bootloader request? |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
50
diff
changeset
|
246 bra uart_115k_bootloader2 ; No, Abort |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
50
diff
changeset
|
247 DISPLAYTEXTH d'303' ; Yes, "Please wait!" |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
50
diff
changeset
|
248 clrf INTCON ; Interrupts disabled |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
50
diff
changeset
|
249 bcf PIR1,RCIF ; clear flag |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
50
diff
changeset
|
250 goto 0x17F56 ; Enter straight into bootloader. Good luck! |