annotate src/eeprom_rs232.asm @ 171:2f1f3da0ae98

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