/ Published in: PicBasic
Displays temperature from DS18B20 in Celsius on hardware serial port
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
'**************************************************************** '* Name : DS18B20 Temperature sensor reading * '* Author : Daniel Bowen [email protected] * '* Notice : Copyright (c) 2007 UTARC www.utarc.org * '* : All Rights Reserved * '* Date : 2/20/2007 * '* Version : 1.0 * '* Notes : Displays temperature from DS18B20 in Celsius on hardware serial port '* : Microcontroller used: PicMicro 18F4620 '* : * '**************************************************************** INCLUDE "MODEDEFS.BAS" DEFINE OSC 20 DEFINE LOADER_USED 1 DEFINE HSER_BAUD 2400 DEFINE ADC_CLOCK 1 DEFINE ADC_BITS 10 DEFINE ADC_SAMPLEUS 50 SYMBOL LF=$0A CMCON=$07 ADCON1=%00001100 TRISA=%00110111 TRISB=%01111101 TRISC=%10010100 TRISD=%10010100 TRISE=%00000000 '*** Pin assignments TempIn VAR PORTA.4 '*** Temp Read Variables *** char VAR BYTE TTData VAR BYTE TSign VAR BIT TempData VAR WORD Sign VAR TEMPDATA.15 START: GOSUB TEMPINREAD LOOKUP TSIGN, ["+","-"], CHAR HSEROUT [char,DEC3 TEMPDATA, "C" CR,LF] ' and display it 0=positive, 1=negative GOTO START TEMPINREAD: OWOUT TEMPIN,1,[$CC,$44] HIGH TEMPIN PAUSE 10 OWOUT TEMPIN,1,[$CC,$BE] OWIN TEMPIN,0,[TEMPDATA.LowByte,TEMPDATA.HighByte,SKIP 7] tSign = SIGN ' save sign bin IF TSIGN=1 THEN TEMPDATA = $FFFF-TEMPDATA TEMPDATA = TEMPDATA + 1 ENDIF TEMPDATA = TEMPDATA/16 RETURN
URL: http://www.utarc.org/wiki/index.php?title=Source_Code