Mercurial > public > hwos_code
annotate src/eeprom_rs232.asm @ 344:1e342e433839
CHANGE: GF and aGF high range increased to 45-110%
Flow control test
| author | heinrichsweikamp |
|---|---|
| date | Mon, 20 Jul 2015 15:04:13 +0200 |
| parents | e4cb495aed3d |
| children | 2fd258596af0 |
| 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 | |
| 275 | 12 #include "hwos.inc" |
| 0 | 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 | |
|
224
5a4801918be9
temporally disable "Copy disable flags from digital input" routine
heinrichsweikamp
parents:
218
diff
changeset
|
72 global disable_ir_s8 |
|
5a4801918be9
temporally disable "Copy disable flags from digital input" routine
heinrichsweikamp
parents:
218
diff
changeset
|
73 disable_ir_s8: |
| 0 | 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) |
| 236 | 86 btfsc analog_o2_input |
| 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 | |
| 218 | 156 bcf PORTE,0 ; Start comms |
| 0 | 157 ;init serial port1 (TRISC6/7) |
| 158 movlw b'00100100' ; BRGH=1, SYNC=0 | |
| 159 movwf TXSTA1 | |
| 160 movlw b'10010000' | |
| 161 movwf RCSTA1 | |
| 162 return | |
| 163 | |
| 164 global disable_rs232 | |
| 165 disable_rs232: | |
| 166 clrf RCSTA1 | |
| 167 clrf TXSTA1 ; UART disable | |
|
198
c511dc403d7e
(Slightly) reduce current consumption in Eco and sleep mode
heinrichsweikamp
parents:
187
diff
changeset
|
168 bcf PORTC,6 ; TX hard to GND |
| 218 | 169 bsf PORTE,0 ; Stop comms |
| 0 | 170 return |
| 171 | |
|
344
1e342e433839
CHANGE: GF and aGF high range increased to 45-110%
heinrichsweikamp
parents:
276
diff
changeset
|
172 |
|
1e342e433839
CHANGE: GF and aGF high range increased to 45-110%
heinrichsweikamp
parents:
276
diff
changeset
|
173 rs232_wait_tx_led: |
|
1e342e433839
CHANGE: GF and aGF high range increased to 45-110%
heinrichsweikamp
parents:
276
diff
changeset
|
174 bsf LEDr ; Flow control test mH |
|
1e342e433839
CHANGE: GF and aGF high range increased to 45-110%
heinrichsweikamp
parents:
276
diff
changeset
|
175 |
| 0 | 176 global rs232_wait_tx |
| 177 rs232_wait_tx: | |
| 113 | 178 btfss TXSTA1,TRMT ; RS232 Busy? |
| 0 | 179 bra rs232_wait_tx ; yes, wait... |
|
344
1e342e433839
CHANGE: GF and aGF high range increased to 45-110%
heinrichsweikamp
parents:
276
diff
changeset
|
180 |
|
1e342e433839
CHANGE: GF and aGF high range increased to 45-110%
heinrichsweikamp
parents:
276
diff
changeset
|
181 btfss ble_available ; ble available? |
|
1e342e433839
CHANGE: GF and aGF high range increased to 45-110%
heinrichsweikamp
parents:
276
diff
changeset
|
182 return ; No, done. |
|
1e342e433839
CHANGE: GF and aGF high range increased to 45-110%
heinrichsweikamp
parents:
276
diff
changeset
|
183 |
|
1e342e433839
CHANGE: GF and aGF high range increased to 45-110%
heinrichsweikamp
parents:
276
diff
changeset
|
184 btfsc NRTS ; Wait for Bluetooth module |
|
1e342e433839
CHANGE: GF and aGF high range increased to 45-110%
heinrichsweikamp
parents:
276
diff
changeset
|
185 bra rs232_wait_tx_led ; yes, wait... |
|
1e342e433839
CHANGE: GF and aGF high range increased to 45-110%
heinrichsweikamp
parents:
276
diff
changeset
|
186 |
|
1e342e433839
CHANGE: GF and aGF high range increased to 45-110%
heinrichsweikamp
parents:
276
diff
changeset
|
187 bcf LEDr |
| 0 | 188 return ; Done. |
| 189 | |
| 113 | 190 global rs232_wait_tx2 |
| 191 rs232_wait_tx2: | |
| 192 banksel TXSTA2 | |
| 209 | 193 rs232_wait_tx2_1: |
| 113 | 194 btfss TXSTA2,TRMT ; RS232 Busy? |
| 209 | 195 bra rs232_wait_tx2_1 ; yes, wait... |
| 113 | 196 banksel common |
| 197 return ; Done. | |
| 198 | |
| 0 | 199 global rs232_get_byte |
| 200 rs232_get_byte: | |
| 201 bcf rs232_recieve_overflow ; clear flag | |
| 202 clrf uart1_temp | |
| 203 clrf uart2_temp | |
| 204 rs232_get_byte2: | |
| 205 btfsc PIR1,RCIF ; data arrived? | |
| 206 return | |
|
276
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
parents:
275
diff
changeset
|
207 btfsc PIR1,RCIF ; data arrived? |
|
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
parents:
275
diff
changeset
|
208 return |
|
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
parents:
275
diff
changeset
|
209 btfsc PIR1,RCIF ; data arrived? |
|
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
parents:
275
diff
changeset
|
210 return |
|
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
parents:
275
diff
changeset
|
211 btfsc PIR1,RCIF ; data arrived? |
|
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
parents:
275
diff
changeset
|
212 return |
| 0 | 213 decfsz uart2_temp,F |
| 214 bra rs232_get_byte2 | |
| 215 decfsz uart1_temp,F | |
| 216 bra rs232_get_byte2 | |
|
276
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
parents:
275
diff
changeset
|
217 ; timeout occoured (about 40ms) |
| 0 | 218 bsf rs232_recieve_overflow ; set flag |
| 219 bcf RCSTA1,CREN ; Clear receiver status | |
| 220 bsf RCSTA1,CREN | |
| 221 return ; and return anyway | |
| 222 | |
| 223 END |
