URL
https://opencores.org/ocsvn/rtf65002/rtf65002/trunk
Subversion Repositories rtf65002
[/] [rtf65002/] [trunk/] [software/] [asm/] [ReadTemp.asm] - Rev 40
Compare with Previous | Blame | View Log
; ============================================================================; __; \\__/ o\ (C) 2013, 2014 Robert Finch, Stratford; \ __ / All rights reserved.; \/_// robfinch<remove>@opencores.org; ||;;; This source file is free software: you can redistribute it and/or modify; it under the terms of the GNU Lesser General Public License as published; by the Free Software Foundation, either version 3 of the License, or; (at your option) any later version.;; This source file is distributed in the hope that it will be useful,; but WITHOUT ANY WARRANTY; without even the implied warranty of; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the; GNU General Public License for more details.;; You should have received a copy of the GNU General Public License; along with this program. If not, see <http://www.gnu.org/licenses/>.;; ReadTemp.asm; ============================================================================;;--------------------------------------------------------------------------; ReadTemp; Read and display the temperature from a DS1626 temperature sensor; device. RTF65002 source code.;--------------------------------------------------------------------------DS1626_CMD =$FFDC0300DS1626_DAT =$FFDC0301; CommandsSTART_CNV = $51;STOP_CNV = $22;READ_TEMP = $AA;READ_CONFIG = $AC;READ_TH = $A1;READ_TL = $A2;WRITE_TH = $01;WRITE_TL = $02;WRITE_CONFIG = $0C;POR = $54;public ReadTemp:lda CONFIGREC ; Do we even have a temperature sensor ?bit #$10beq rdtmp3 ; If not, output '0.000'rdtmp1:; On power up the DS1626 interface circuit sends a power on reset (POR); command to the DS1626. Waiting here makes sure this command has been; completed.jsr rdt_busy_waitlda #$0F ; 12 bits resolution, cpu mode, one-shot modesta DS1626_DATlda #WRITE_CONFIG ; write the desired config to the devicesta DS1626_CMDjsr rdt_busy_waitlda #10jsr tSleeplda #0sta DS1626_DATlda #START_CNV ; issue a start conversion commandsta DS1626_CMDjsr rdt_busy_waitlda #10jsr tSleep; Now poll the config register to determine when the conversion has completed.rdtmp2:lda #READ_CONFIG ; issue the READ_CONFIG commandsta DS1626_CMDjsr rdt_busy_waitphalda #10 ; Wait a bit before checking again. The conversionjsr tSleep ; can take up to 1s to complete.plabit #$80 ; test done bitbeq rdtmp2 ; loop back if not done conversionlda #0sta DS1626_DAT ; issue a stop conversion commandlda #STOP_CNVsta DS1626_CMDjsr rdt_busy_waitlda #10jsr tSleeplda #READ_TEMP ; issue the READ_TEMP commandsta DS1626_CMDjsr rdt_busy_waitphalda #10jsr tSleepplardtmp4:jsr CRLFand #$FFFbit #$800 ; check for negative temperaturebeq rdtmp7sub r1,r0,r1 ; negate the numberand #$FFFphalda #'-' ; output a minus signjsr DisplayCharplardtmp7:pha ; save off valuelsr r1,r1,#4 ; get rid of fractional portionand #$7F ; strip off sign bitldx #3 ; output the whole number partjsr PRTNUMlda #'.' ; followed by a decimal pointjsr DisplayCharpla ; get back temp valueand #$0Fmul r1,r1,#625 ; 1/16th's per degreeldx #1jsr PRTNUM; pha ; save off fraction bits; div r1,r1,#1000 ; calculate the first digit; add #'0'; jsr DisplayChar ; output digit; pla ; get back fractions bits; pha ; and save again; div r1,r1,#100 ; shift over to second digit; mod r1,r1,#10 ; ignore high order bits; add #'0'; jsr DisplayChar ; display the digit; pla ; get back fraction; div r1,r1,#10; mod r1,r1,#10 ; compute low order digit; add #'0'; jsr DisplayChar ; display low order digitjsr CRLFrtsrdtmp3:lda #0bra rdtmp4; Returns:; acc = value from data register;rdt_busy_wait:jsr KeybdGetCharcmp #CTRLCbeq Monitorlda DS1626_DATbit #$8000bne rdt_busy_waitrtstSleep:ldx MillisecondstxatSleep1:ldx Millisecondssub r2,r2,r1cpx #100blo tSleep1rts
