Mercurial > public > hwos_code
annotate src/eeprom_rs232.asm @ 212:5fd93901b735
Merge
author | heinrichsweikamp |
---|---|
date | Wed, 10 Dec 2014 09:13:49 +0100 |
parents | 56276a2418f9 |
children | 8fbd8c5ac51f |
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 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 | |
156 ;init serial port1 (TRISC6/7) | |
157 movlw b'00100100' ; BRGH=1, SYNC=0 | |
158 movwf TXSTA1 | |
159 movlw b'10010000' | |
160 movwf RCSTA1 | |
161 return | |
162 | |
163 global disable_rs232 | |
164 disable_rs232: | |
165 clrf RCSTA1 | |
166 clrf TXSTA1 ; UART disable | |
198
c511dc403d7e
(Slightly) reduce current consumption in Eco and sleep mode
heinrichsweikamp
parents:
187
diff
changeset
|
167 bcf PORTC,6 ; TX hard to GND |
0 | 168 return |
169 | |
170 global rs232_wait_tx | |
171 rs232_wait_tx: | |
113 | 172 btfss TXSTA1,TRMT ; RS232 Busy? |
0 | 173 bra rs232_wait_tx ; yes, wait... |
174 return ; Done. | |
175 | |
113 | 176 global rs232_wait_tx2 |
177 rs232_wait_tx2: | |
178 banksel TXSTA2 | |
209 | 179 rs232_wait_tx2_1: |
113 | 180 btfss TXSTA2,TRMT ; RS232 Busy? |
209 | 181 bra rs232_wait_tx2_1 ; yes, wait... |
113 | 182 banksel common |
183 return ; Done. | |
184 | |
0 | 185 global rs232_get_byte |
186 rs232_get_byte: | |
187 bcf rs232_recieve_overflow ; clear flag | |
188 clrf uart1_temp | |
189 clrf uart2_temp | |
190 rs232_get_byte2: | |
191 btfsc PIR1,RCIF ; data arrived? | |
192 return | |
193 decfsz uart2_temp,F | |
194 bra rs232_get_byte2 | |
195 decfsz uart1_temp,F | |
196 bra rs232_get_byte2 | |
197 ; timeout occoured (about 20ms) | |
198 bsf rs232_recieve_overflow ; set flag | |
199 bcf RCSTA1,CREN ; Clear receiver status | |
200 bsf RCSTA1,CREN | |
201 return ; and return anyway | |
202 | |
203 END |