annotate code_part1/OSTC_code_asm_part1/tempcomp.asm @ 1:210410f7c1b4

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