OpenCores
URL https://opencores.org/ocsvn/rtf65002/rtf65002/trunk

Subversion Repositories rtf65002

[/] [rtf65002/] [trunk/] [software/] [asm/] [ReadTemp.asm] - Blame information for rev 40

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 40 robfinch
 
2
; ============================================================================
3
;        __
4
;   \\__/ o\    (C) 2013, 2014  Robert Finch, Stratford
5
;    \  __ /    All rights reserved.
6
;     \/_//     robfinch@opencores.org
7
;       ||
8
;
9
;
10
; This source file is free software: you can redistribute it and/or modify
11
; it under the terms of the GNU Lesser General Public License as published
12
; by the Free Software Foundation, either version 3 of the License, or
13
; (at your option) any later version.
14
;
15
; This source file is distributed in the hope that it will be useful,
16
; but WITHOUT ANY WARRANTY; without even the implied warranty of
17
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
; GNU General Public License for more details.
19
;
20
; You should have received a copy of the GNU General Public License
21
; along with this program.  If not, see .
22
;
23
; ReadTemp.asm
24
; ============================================================================
25
;
26
;--------------------------------------------------------------------------
27
; ReadTemp
28
;    Read and display the temperature from a DS1626 temperature sensor
29
; device. RTF65002 source code.
30
;--------------------------------------------------------------------------
31
DS1626_CMD      =$FFDC0300
32
DS1626_DAT      =$FFDC0301
33
; Commands
34
START_CNV = $51;
35
STOP_CNV = $22;
36
READ_TEMP = $AA;
37
READ_CONFIG = $AC;
38
READ_TH = $A1;
39
READ_TL = $A2;
40
WRITE_TH = $01;
41
WRITE_TL = $02;
42
WRITE_CONFIG = $0C;
43
POR = $54;
44
 
45
public ReadTemp:
46
        lda             CONFIGREC       ; Do we even have a temperature sensor ?
47
        bit             #$10
48
        beq             rdtmp3          ; If not, output '0.000'
49
rdtmp1:
50
        ; On power up the DS1626 interface circuit sends a power on reset (POR)
51
        ; command to the DS1626. Waiting here makes sure this command has been
52
        ; completed.
53
        jsr             rdt_busy_wait
54
        lda             #$0F                    ; 12 bits resolution, cpu mode, one-shot mode
55
        sta             DS1626_DAT
56
        lda             #WRITE_CONFIG   ; write the desired config to the device
57
        sta             DS1626_CMD
58
        jsr             rdt_busy_wait
59
        lda             #10
60
        jsr             tSleep
61
        lda             #0
62
        sta             DS1626_DAT
63
        lda             #START_CNV              ; issue a start conversion command
64
        sta             DS1626_CMD
65
        jsr             rdt_busy_wait
66
        lda             #10
67
        jsr             tSleep
68
        ; Now poll the config register to determine when the conversion has completed.
69
rdtmp2:
70
        lda             #READ_CONFIG    ; issue the READ_CONFIG command
71
        sta             DS1626_CMD
72
        jsr             rdt_busy_wait
73
        pha
74
        lda             #10                             ; Wait a bit before checking again. The conversion
75
        jsr             tSleep                  ; can take up to 1s to complete.
76
        pla
77
        bit             #$80                    ; test done bit
78
        beq             rdtmp2                  ; loop back if not done conversion
79
        lda             #0
80
        sta             DS1626_DAT              ; issue a stop conversion command
81
        lda             #STOP_CNV
82
        sta             DS1626_CMD
83
        jsr             rdt_busy_wait
84
        lda             #10
85
        jsr             tSleep
86
        lda             #READ_TEMP              ; issue the READ_TEMP command
87
        sta             DS1626_CMD
88
        jsr             rdt_busy_wait
89
        pha
90
        lda             #10
91
        jsr             tSleep
92
        pla
93
rdtmp4:
94
        jsr             CRLF
95
        and             #$FFF
96
        bit             #$800           ; check for negative temperature
97
        beq             rdtmp7
98
        sub             r1,r0,r1        ; negate the number
99
        and             #$FFF
100
        pha
101
        lda             #'-'            ; output a minus sign
102
        jsr             DisplayChar
103
        pla
104
rdtmp7:
105
        pha                                     ; save off value
106
        lsr             r1,r1,#4        ; get rid of fractional portion
107
        and             #$7F            ; strip off sign bit
108
        ldx             #3                      ; output the whole number part
109
        jsr             PRTNUM
110
        lda             #'.'            ; followed by a decimal point
111
        jsr             DisplayChar
112
        pla                                     ; get back temp value
113
        and             #$0F
114
        mul             r1,r1,#625      ; 1/16th's per degree
115
        ldx             #1
116
        jsr             PRTNUM
117
;       pha                                     ; save off fraction bits
118
;       div             r1,r1,#1000     ; calculate the first digit
119
;       add             #'0'
120
;       jsr             DisplayChar     ; output digit
121
;       pla                                     ; get back fractions bits
122
;       pha                                     ; and save again
123
;       div             r1,r1,#100      ; shift over to second digit
124
;       mod             r1,r1,#10       ; ignore high order bits
125
;       add             #'0'
126
;       jsr             DisplayChar     ; display the digit
127
;       pla                                     ; get back fraction
128
;       div             r1,r1,#10
129
;       mod             r1,r1,#10       ; compute low order digit
130
;       add             #'0'
131
;       jsr             DisplayChar     ; display low order digit
132
        jsr             CRLF
133
        rts
134
rdtmp3:
135
        lda             #0
136
        bra             rdtmp4
137
 
138
; Returns:
139
;       acc = value from data register
140
;
141
rdt_busy_wait:
142
        jsr             KeybdGetChar
143
        cmp             #CTRLC
144
        beq             Monitor
145
        lda             DS1626_DAT
146
        bit             #$8000
147
        bne             rdt_busy_wait
148
        rts
149
 
150
tSleep:
151
        ldx             Milliseconds
152
        txa
153
tSleep1:
154
        ldx             Milliseconds
155
        sub             r2,r2,r1
156
        cpx             #100
157
        blo             tSleep1
158
        rts
159
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.