comparison src/eeprom_rs232.asm @ 113:f3062a611eef

Merge
author heinrichsweikamp
date Mon, 23 Jun 2014 16:14:33 +0200
parents 11d4fc797f74
children 939f1e83c4c2
comparison
equal deleted inserted replaced
112:a24581f0b372 113:f3062a611eef
13 #include "start.inc" 13 #include "start.inc"
14 #include "tft.inc" 14 #include "tft.inc"
15 #include "wait.inc" 15 #include "wait.inc"
16 #include "strings.inc" 16 #include "strings.inc"
17 #include "convert.inc" 17 #include "convert.inc"
18 #include "adc_lightsensor.inc"
19 #include "math.inc"
18 20
19 ;============================================================================= 21 ;=============================================================================
20 eeprom code 0xF00000+0x10 22 eeprom code 0xF00000+0x10
21 ; Skip SERIAL number. Should not be overwritten. 23 ; Skip SERIAL number. Should not be overwritten.
22 global eeprom_serial_save, eeprom_opt_backup 24 global eeprom_serial_save, eeprom_opt_backup
78 banksel TXSTA2 80 banksel TXSTA2
79 clrf TXSTA2 81 clrf TXSTA2
80 clrf RCSTA2 82 clrf RCSTA2
81 banksel common 83 banksel common
82 bcf ir_power ; IR off 84 bcf ir_power ; IR off
85 bcf mcp_power ; Power-down intrumentation amp
86 bsf s8_npower ; Power-down S8 HUD
83 return 87 return
84 88
85 global enable_ir 89 global enable_ir
86 enable_ir: 90 enable_ir:
87 ;init serial port2 (TRISG2) 91 ;init serial port2 (TRISG2)
92 btfsc c3_hardware
93 bra enable_s8 ; Start S8
94
95 banksel BAUDCON2
96 movlw b'00100000' ; BRG16=0 ; inverted for IR
97 movwf BAUDCON2
88 banksel TXSTA2 98 banksel TXSTA2
89 movlw b'00100000' ; BRGH=0, SYNC=0 99 movlw b'00100000' ; BRGH=0, SYNC=0
90 movwf TXSTA2 100 movwf TXSTA2
91 movlw .102 ; SPBRGH:SPBRG = .102 : 2403 BAUD @ 16MHz 101 movlw .102 ; SPBRGH:SPBRG = .102 : 2403 BAUD @ 16MHz
92 movwf SPBRG2 102 movwf SPBRG2
93 clrf SPBRGH2 103 clrf SPBRGH2
94 movlw b'10010000' 104 movlw b'10010000'
95 movwf RCSTA2 105 movwf RCSTA2
96 banksel common 106 banksel common
97 bsf ir_power ; Power-up IR 107 bsf ir_power ; Power-up IR
98 btfss ir_power 108 btfss ir_power
99 bra $-6 109 bra $-6
110 return
111
112 enable_s8:
113 ; Check for Digital/Analog
114 bsf s8_npower ; Power-down S8 HUD
115 WAITMS d'1' ; Very short delay
116 bsf mcp_power ; Power-up intrumentation amp
117 btfss mcp_power
118 bra $-6
119 banksel TXSTA2
120 clrf TXSTA2
121 clrf RCSTA2
122 banksel common
123
124 ; It may be digital, check for voltage when isolator is powered
125 bcf s8_npower ; Power S8 HUD
126 WAITMS d'1' ; Very short delay
127
128 btfsc PORTG,2 ; RX2=1?
129 bra enable_s8_2 ; Yes, digital
130 WAITMS d'30'
131 btfsc PORTG,2 ; RX2=1?
132 bra enable_s8_2 ; Yes, digital
133
134 ; Not found, set to analog (fail-safe)
135
136 enable_s8_analog:
137 ; S8 Analog
138 bsf s8_npower ; Power-down S8 HUD
139 bcf s8_digital ; Clear flag
140 return
141
142 enable_s8_2: ; S8 Digital
143 banksel BAUDCON2
144 movlw b'00000000' ; BRG16=0 ; normal for S8
145 movwf BAUDCON2
146 banksel TXSTA2
147 movlw b'00100000' ; BRGH=0, SYNC=0
148 movwf TXSTA2
149 movlw .25 ; SPBRGH:SPBRG = .25 : 9615 BAUD @ 16MHz
150 movwf SPBRG2
151 clrf SPBRGH2
152 movlw b'10010000'
153 movwf RCSTA2
154 banksel common
155 bcf s8_npower ; Power S8 HUD
156 bsf s8_digital ; Set flag
100 return 157 return
101 158
102 ;============================================================================= 159 ;=============================================================================
103 global enable_rs232 160 global enable_rs232
104 enable_rs232: 161 enable_rs232:
131 bsf TRISC,7 ; Input 188 bsf TRISC,7 ; Input
132 return 189 return
133 190
134 global rs232_wait_tx 191 global rs232_wait_tx
135 rs232_wait_tx: 192 rs232_wait_tx:
136 ; btfss RCSTA1,SPEN ; Transmitter active?
137 ; return ; No, return!
138
139 btfsc TXSTA1,TRMT ; Transmit Shift Register empty? 193 btfsc TXSTA1,TRMT ; Transmit Shift Register empty?
140 return ; Yes, return! 194 return ; Yes, return!
141 195
142 btfss TXSTA,TRMT ; RS232 Busy? 196 btfss TXSTA1,TRMT ; RS232 Busy?
143 bra rs232_wait_tx ; yes, wait... 197 bra rs232_wait_tx ; yes, wait...
198 return ; Done.
199
200 global rs232_wait_tx2
201 rs232_wait_tx2:
202 banksel TXSTA2
203 btfsc TXSTA2,TRMT ; Transmit Shift Register empty?
204 bra rs232_wait_tx2_2 ; Yes, return!
205
206 btfss TXSTA2,TRMT ; RS232 Busy?
207 bra rs232_wait_tx2 ; yes, wait...
208 rs232_wait_tx2_2:
209 banksel common
144 return ; Done. 210 return ; Done.
145 211
146 global rs232_get_byte 212 global rs232_get_byte
147 rs232_get_byte: 213 rs232_get_byte:
148 bcf PIR1,RCIF ; clear flag 214 bcf PIR1,RCIF ; clear flag