0
|
1 ;=============================================================================
|
|
2 ;
|
|
3 ; File eeprom_rs232.asm
|
|
4 ;
|
|
5 ; Internal EEPROM, RS232
|
|
6 ;
|
|
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
|
|
8 ;=============================================================================
|
|
9 ; HISTORY
|
|
10 ; 2011-08-06 : [mH] moving from OSTC code
|
|
11
|
275
|
12 #include "hwos.inc"
|
0
|
13 #include "wait.inc"
|
|
14
|
|
15 ;=============================================================================
|
|
16 eeprom code 0xF00000+0x10
|
|
17 ; Skip SERIAL number. Should not be overwritten.
|
|
18 global eeprom_serial_save, eeprom_opt_backup
|
|
19 eeprom_serial_save res 2
|
|
20 eeprom_opt_backup res 0x3E
|
|
21
|
|
22 ;=============================================================================
|
|
23 basic CODE
|
|
24
|
|
25 global write_int_eeprom_1
|
|
26 write_int_eeprom_1:
|
|
27 movwf EEADR
|
|
28 bra write_eeprom ; writes and "returns" after write
|
|
29
|
|
30 global read_int_eeprom_1
|
|
31 read_int_eeprom_1:
|
|
32 movwf EEADR
|
|
33 bra read_eeprom ; reads and "returns" after write
|
|
34
|
|
35 ;=============================================================================
|
|
36 ; reads from internal eeprom
|
|
37 ; Input: EEADRH:EEADR = EEPROM address.
|
|
38 ; Output: EEDATA.
|
|
39 ; Trashed: NONE.
|
|
40 global read_eeprom
|
|
41 read_eeprom:
|
|
42 bcf EECON1,EEPGD
|
|
43 bcf EECON1,CFGS
|
|
44 bsf EECON1,RD
|
|
45 return
|
|
46
|
|
47 ;=============================================================================
|
|
48 ; writes into internal eeprom
|
|
49 ; Input: EEADRH:EEADR = EEPROM address.
|
|
50 ; EEDATA = byte to write.
|
|
51 ; Trashed: WREG.
|
|
52 global write_eeprom
|
|
53 write_eeprom:
|
|
54 bcf EECON1,EEPGD
|
|
55 bcf EECON1,CFGS
|
|
56 bsf EECON1,WREN
|
|
57
|
133
|
58 bcf INTCON,GIE ; Disable interrups for the next 5 instructions
|
0
|
59 movlw 0x55
|
|
60 movwf EECON2
|
|
61 movlw 0xAA
|
|
62 movwf EECON2
|
|
63 bsf EECON1,WR
|
|
64 bsf INTCON,GIE ; ...but the flag for the ISR routines were still set, so they will interrupt now!
|
|
65
|
|
66 write_eep2:
|
|
67 btfsc EECON1,WR
|
|
68 bra write_eep2 ; wait about 4ms...
|
|
69 bcf EECON1,WREN
|
|
70 return
|
|
71
|
224
|
72 global disable_ir_s8
|
|
73 disable_ir_s8:
|
0
|
74 banksel TXSTA2
|
|
75 clrf TXSTA2
|
|
76 clrf RCSTA2
|
|
77 banksel common
|
|
78 bcf ir_power ; IR off
|
113
|
79 bcf mcp_power ; Power-down intrumentation amp
|
|
80 bsf s8_npower ; Power-down S8 HUD
|
0
|
81 return
|
|
82
|
187
|
83 global enable_ir_s8
|
|
84 enable_ir_s8:
|
0
|
85 ;init serial port2 (TRISG2)
|
236
|
86 btfsc analog_o2_input
|
113
|
87 bra enable_s8 ; Start S8
|
|
88
|
|
89 banksel BAUDCON2
|
|
90 movlw b'00100000' ; BRG16=0 ; inverted for IR
|
|
91 movwf BAUDCON2
|
0
|
92 movlw b'00100000' ; BRGH=0, SYNC=0
|
|
93 movwf TXSTA2
|
|
94 movlw .102 ; SPBRGH:SPBRG = .102 : 2403 BAUD @ 16MHz
|
|
95 movwf SPBRG2
|
|
96 movlw b'10010000'
|
|
97 movwf RCSTA2
|
|
98 banksel common
|
113
|
99 bsf ir_power ; Power-up IR
|
0
|
100 btfss ir_power
|
|
101 bra $-6
|
|
102 return
|
|
103
|
113
|
104 enable_s8:
|
|
105 ; Check for Digital/Analog
|
|
106 bsf s8_npower ; Power-down S8 HUD
|
|
107 WAITMS d'1' ; Very short delay
|
|
108 bsf mcp_power ; Power-up intrumentation amp
|
|
109 btfss mcp_power
|
|
110 bra $-6
|
|
111 banksel TXSTA2
|
|
112 clrf TXSTA2
|
|
113 clrf RCSTA2
|
|
114 banksel common
|
|
115
|
|
116 ; It may be digital, check for voltage when isolator is powered
|
|
117 bcf s8_npower ; Power S8 HUD
|
|
118 WAITMS d'1' ; Very short delay
|
|
119
|
|
120 btfsc PORTG,2 ; RX2=1?
|
|
121 bra enable_s8_2 ; Yes, digital
|
|
122 WAITMS d'30'
|
|
123 btfsc PORTG,2 ; RX2=1?
|
|
124 bra enable_s8_2 ; Yes, digital
|
|
125
|
|
126 ; Not found, set to analog (fail-safe)
|
|
127
|
|
128 enable_s8_analog:
|
|
129 ; S8 Analog
|
|
130 bsf s8_npower ; Power-down S8 HUD
|
|
131 bcf s8_digital ; Clear flag
|
|
132 return
|
|
133
|
|
134 enable_s8_2: ; S8 Digital
|
|
135 banksel BAUDCON2
|
|
136 movlw b'00000000' ; BRG16=0 ; normal for S8
|
|
137 movwf BAUDCON2
|
|
138 movlw b'00100000' ; BRGH=0, SYNC=0
|
|
139 movwf TXSTA2
|
|
140 movlw .25 ; SPBRGH:SPBRG = .25 : 9615 BAUD @ 16MHz
|
|
141 movwf SPBRG2
|
|
142 movlw b'10010000'
|
|
143 movwf RCSTA2
|
|
144 banksel common
|
|
145 bsf s8_digital ; Set flag
|
|
146 return
|
|
147
|
0
|
148 ;=============================================================================
|
|
149 global enable_rs232
|
|
150 enable_rs232:
|
|
151 call speed_normal ; 16MHz
|
|
152 enable_rs232_2:
|
|
153 movlw T2CON_NORMAL
|
|
154 cpfseq T2CON
|
|
155 bra enable_rs232_2 ; Wait until speed is normal
|
218
|
156 bcf PORTE,0 ; Start comms
|
0
|
157 ;init serial port1 (TRISC6/7)
|
|
158 movlw b'00100100' ; BRGH=1, SYNC=0
|
|
159 movwf TXSTA1
|
|
160 movlw b'10010000'
|
|
161 movwf RCSTA1
|
|
162 return
|
|
163
|
|
164 global disable_rs232
|
|
165 disable_rs232:
|
|
166 clrf RCSTA1
|
|
167 clrf TXSTA1 ; UART disable
|
198
|
168 bcf PORTC,6 ; TX hard to GND
|
218
|
169 bsf PORTE,0 ; Stop comms
|
0
|
170 return
|
|
171
|
344
|
172
|
0
|
173 global rs232_wait_tx
|
|
174 rs232_wait_tx:
|
113
|
175 btfss TXSTA1,TRMT ; RS232 Busy?
|
0
|
176 bra rs232_wait_tx ; yes, wait...
|
344
|
177
|
|
178 btfss ble_available ; ble available?
|
|
179 return ; No, done.
|
350
|
180
|
344
|
181 btfsc NRTS ; Wait for Bluetooth module
|
350
|
182 bra rs232_wait_tx ; yes, wait...
|
0
|
183 return ; Done.
|
|
184
|
113
|
185 global rs232_wait_tx2
|
|
186 rs232_wait_tx2:
|
|
187 banksel TXSTA2
|
209
|
188 rs232_wait_tx2_1:
|
113
|
189 btfss TXSTA2,TRMT ; RS232 Busy?
|
209
|
190 bra rs232_wait_tx2_1 ; yes, wait...
|
113
|
191 banksel common
|
|
192 return ; Done.
|
|
193
|
0
|
194 global rs232_get_byte
|
|
195 rs232_get_byte:
|
|
196 bcf rs232_recieve_overflow ; clear flag
|
378
|
197 movlw .10
|
|
198 movwf uart1_temp
|
0
|
199 clrf uart2_temp
|
378
|
200 clrf uart3_temp
|
0
|
201 rs232_get_byte2:
|
|
202 btfsc PIR1,RCIF ; data arrived?
|
386
|
203 return ; Yes
|
378
|
204 decfsz uart3_temp,F
|
|
205 bra rs232_get_byte2
|
0
|
206 decfsz uart2_temp,F
|
378
|
207 bra rs232_get_byte2
|
0
|
208 decfsz uart1_temp,F
|
|
209 bra rs232_get_byte2
|
386
|
210 ; timeout occoured (about 400ms)
|
0
|
211 bsf rs232_recieve_overflow ; set flag
|
378
|
212 rs232_get_byte3:
|
0
|
213 bcf RCSTA1,CREN ; Clear receiver status
|
|
214 bsf RCSTA1,CREN
|
|
215 return ; and return anyway
|
|
216
|
|
217 END |