annotate src/eeprom_rs232.asm @ 124:40ff64d60054

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