0
|
1
|
|
2 ; OSTC - diving computer code
|
|
3 ; Copyright (C) 2008 HeinrichsWeikamp GbR
|
|
4
|
|
5 ; This program is free software: you can redistribute it and/or modify
|
|
6 ; it under the terms of the GNU General Public License as published by
|
|
7 ; the Free Software Foundation, either version 3 of the License, or
|
|
8 ; (at your option) any later version.
|
|
9
|
|
10 ; This program is distributed in the hope that it will be useful,
|
|
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 ; GNU General Public License for more details.
|
|
14
|
|
15 ; You should have received a copy of the GNU General Public License
|
|
16 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
|
18
|
|
19 ; routine for extra temperature compensation
|
|
20 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com
|
|
21 ; written: 01/12/08
|
|
22 ; last updated: 08/08/31
|
|
23 ; known bugs:
|
|
24 ; ToDo:
|
|
25
|
|
26 ; routine echoes the "f" command as ready signal
|
|
27 ; PC has to send 2 bytes containing the actual temperature in 0.1C
|
|
28 ; Byte1: low
|
|
29 ; Byte2: high
|
|
30
|
|
31
|
|
32 compensate_temperature:
|
|
33 bcf uart_compensate_temp ; clear flag
|
|
34 bcf PIE1,RCIE ; no interrupt for UART
|
|
35 call set_LEDusb ; LEDusb ON
|
|
36 bcf PIR1,RCIF ; clear flag
|
|
37
|
|
38 movlw "f" ; send echo
|
|
39 movwf TXREG
|
|
40 call rs232_wait_tx ; wait for UART
|
|
41
|
|
42 call rs232_get_byte ; low byte
|
|
43 movff RCREG, lo
|
|
44
|
|
45 call rs232_get_byte ; high byte
|
|
46 movff RCREG, hi
|
|
47
|
|
48 clrf temperature_correction ; wait for uncompensated temperature value!
|
|
49 WAITMS d'250' ; wait for new temperature
|
|
50 WAITMS d'250'
|
|
51 WAITMS d'250'
|
|
52 WAITMS d'250'
|
|
53
|
|
54 movff lo,sub_a+0 ; calculate difference
|
|
55 movff hi,sub_a+1
|
|
56 movff temperature+0, sub_b+0
|
|
57 movff temperature+1, sub_b+1
|
|
58 call sub16 ; sub_c = sub_a - sub_b
|
|
59
|
|
60 movf sub_c+0,W
|
|
61 btfsc neg_flag ; compensate negative?
|
|
62 movlw d'0' ; use zero compensation!
|
|
63 movwf sub_c+0
|
|
64
|
|
65 movff sub_c+0,TXREG ; Send answer
|
|
66
|
|
67 movff sub_c+0,EEDATA ; store low byte only!
|
|
68 movff sub_c+0,temperature_correction ; no reboot required then...
|
|
69 movlw 0x01
|
|
70 movwf EEADRH
|
|
71 movlw 0x00
|
|
72 movwf EEADR
|
|
73 call write_eeprom ; stores in internal eeprom
|
|
74
|
|
75 movlw 0x00
|
|
76 movwf EEADRH ; reset high address byte
|
|
77
|
|
78 call clear_LEDusb ; LEDusb OFF
|
|
79 bcf PIR1,RCIF ; clear flag
|
|
80 bsf PIE1,RCIE ; enable interrupt for UART
|
|
81 goto surfloop_loop ; return to surface loop
|