Mercurial > public > hwos_code
annotate src/eeprom_rs232.asm @ 205:618191753d2b
Preparations for 1.7
author | heinrichsweikamp |
---|---|
date | Wed, 26 Nov 2014 14:30:25 +0100 |
parents | 93085f540746 |
children | 56276a2418f9 |
rev | line source |
---|---|
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 | |
12 #include "ostc3.inc" | |
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
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 | 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 | |
72 global disable_ir | |
73 disable_ir: | |
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
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
151
diff
changeset
|
83 global enable_ir_s8 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
151
diff
changeset
|
84 enable_ir_s8: |
0 | 85 ;init serial port2 (TRISG2) |
200 | 86 btfsc cr_hardware |
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 banksel TXSTA2 |
93 movlw b'00100000' ; BRGH=0, SYNC=0 | |
94 movwf TXSTA2 | |
95 movlw .102 ; SPBRGH:SPBRG = .102 : 2403 BAUD @ 16MHz | |
96 movwf SPBRG2 | |
97 clrf SPBRGH2 | |
98 movlw b'10010000' | |
99 movwf RCSTA2 | |
100 banksel common | |
113 | 101 bsf ir_power ; Power-up IR |
0 | 102 btfss ir_power |
103 bra $-6 | |
104 return | |
105 | |
113 | 106 enable_s8: |
107 ; Check for Digital/Analog | |
108 bsf s8_npower ; Power-down S8 HUD | |
109 WAITMS d'1' ; Very short delay | |
110 bsf mcp_power ; Power-up intrumentation amp | |
111 btfss mcp_power | |
112 bra $-6 | |
113 banksel TXSTA2 | |
114 clrf TXSTA2 | |
115 clrf RCSTA2 | |
116 banksel common | |
117 | |
118 ; It may be digital, check for voltage when isolator is powered | |
119 bcf s8_npower ; Power S8 HUD | |
120 WAITMS d'1' ; Very short delay | |
121 | |
122 btfsc PORTG,2 ; RX2=1? | |
123 bra enable_s8_2 ; Yes, digital | |
124 WAITMS d'30' | |
125 btfsc PORTG,2 ; RX2=1? | |
126 bra enable_s8_2 ; Yes, digital | |
127 | |
128 ; Not found, set to analog (fail-safe) | |
129 | |
130 enable_s8_analog: | |
131 ; S8 Analog | |
132 bsf s8_npower ; Power-down S8 HUD | |
133 bcf s8_digital ; Clear flag | |
134 return | |
135 | |
136 enable_s8_2: ; S8 Digital | |
137 banksel BAUDCON2 | |
138 movlw b'00000000' ; BRG16=0 ; normal for S8 | |
139 movwf BAUDCON2 | |
140 banksel TXSTA2 | |
141 movlw b'00100000' ; BRGH=0, SYNC=0 | |
142 movwf TXSTA2 | |
143 movlw .25 ; SPBRGH:SPBRG = .25 : 9615 BAUD @ 16MHz | |
144 movwf SPBRG2 | |
145 clrf SPBRGH2 | |
146 movlw b'10010000' | |
147 movwf RCSTA2 | |
148 banksel common | |
149 bsf s8_digital ; Set flag | |
150 return | |
151 | |
0 | 152 ;============================================================================= |
153 global enable_rs232 | |
154 enable_rs232: | |
155 bcf TRISC,6 ; Output | |
156 call speed_normal ; 16MHz | |
157 enable_rs232_2: | |
158 movlw T2CON_NORMAL | |
159 cpfseq T2CON | |
160 bra enable_rs232_2 ; Wait until speed is normal | |
161 ;init serial port1 (TRISC6/7) | |
162 clrf RCSTA1 | |
163 clrf TXSTA1 | |
164 movlw b'00001000' ; BRG16=1 | |
165 movwf BAUDCON1 | |
166 movlw b'00100100' ; BRGH=1, SYNC=0 | |
167 movwf TXSTA1 | |
168 movlw .34 ; SPBRGH:SPBRG = .34 : 114285 BAUD @ 16MHz (+0,79% Error to 115200 BAUD) | |
169 movwf SPBRG1 | |
170 clrf SPBRGH1 | |
171 movlw b'10010000' | |
172 movwf RCSTA1 | |
173 return | |
174 | |
175 global disable_rs232 | |
176 disable_rs232: | |
177 clrf RCSTA1 | |
178 clrf TXSTA1 ; UART disable | |
198
c511dc403d7e
(Slightly) reduce current consumption in Eco and sleep mode
heinrichsweikamp
parents:
187
diff
changeset
|
179 bcf PORTC,6 ; TX hard to GND |
0 | 180 return |
181 | |
182 global rs232_wait_tx | |
183 rs232_wait_tx: | |
184 btfsc TXSTA1,TRMT ; Transmit Shift Register empty? | |
185 return ; Yes, return! | |
186 | |
113 | 187 btfss TXSTA1,TRMT ; RS232 Busy? |
0 | 188 bra rs232_wait_tx ; yes, wait... |
189 return ; Done. | |
190 | |
113 | 191 global rs232_wait_tx2 |
192 rs232_wait_tx2: | |
193 banksel TXSTA2 | |
194 btfsc TXSTA2,TRMT ; Transmit Shift Register empty? | |
195 bra rs232_wait_tx2_2 ; Yes, return! | |
196 | |
197 btfss TXSTA2,TRMT ; RS232 Busy? | |
198 bra rs232_wait_tx2 ; yes, wait... | |
199 rs232_wait_tx2_2: | |
200 banksel common | |
201 return ; Done. | |
202 | |
0 | 203 global rs232_get_byte |
204 rs232_get_byte: | |
205 bcf rs232_recieve_overflow ; clear flag | |
206 clrf uart1_temp | |
207 clrf uart2_temp | |
208 rs232_get_byte2: | |
209 btfsc PIR1,RCIF ; data arrived? | |
210 return | |
211 decfsz uart2_temp,F | |
212 bra rs232_get_byte2 | |
213 decfsz uart1_temp,F | |
214 bra rs232_get_byte2 | |
215 ; timeout occoured (about 20ms) | |
216 bsf rs232_recieve_overflow ; set flag | |
217 bcf RCSTA1,CREN ; Clear receiver status | |
218 bsf RCSTA1,CREN | |
219 return ; and return anyway | |
220 | |
221 END |