?? tempsen.bas
字號:
device 16f84a
Declare xtal 4
include "TFloat.inc"
Dim Command as Byte
Dim BitCounter as Byte
Dim Temp as Word
Dim Deg as Word
Dim DS_TSensor as Bit
Dim Neg_Pos_Temp as Byte
dim f_temp as word
dim i as word
Symbol DQ PortA.0
Goto Start
DS_Init:
Low DQ
Delayus 500
Input DQ
Delayus 100
DS_TSensor=DQ
Delayus 400
Return
DS_Read:
cls
For BitCounter=1 to 16
Temp=Temp >> 1
Low DQ
Delayus 1
Input DQ
Temp.15=DQ
Delayus 59
Next
f_temp=0
Neg_Pos_Temp="+"
if temp.15=1 and temp.14=1 and temp.13=1 and temp.12=1 and temp.11=1 then
Neg_Pos_Temp="-"
endif
f_ndpart1=0
f_dpart1=0
f_ndpart2=0
f_dpart2=0
if temp.10=1 then
f_temp=f_temp+64
endif
if temp.9=1 then
f_temp=f_temp+32
endif
if temp.8=1 then
f_temp=f_temp+16
endif
if temp.7=1 then
f_temp=f_temp+8
endif
if temp.6=1 then
f_temp=f_temp+4
endif
if temp.5=1 then
f_temp=f_temp+2
endif
if temp.4=1 then
f_temp=f_temp+1
endif
f_ndpart1=f_temp
f_dpart2=0
if temp.3=1 then
f_temp=f_temp+0.5
f_ndpart2=0
f_dpart2=5000
gosub addDecimalVal
endif
if temp.2=1 then
f_temp=f_temp+0.25
f_ndpart2=0
f_dpart2=2500
gosub addDecimalVal
endif
if temp.1=1 then
f_temp=f_temp+0.125
f_ndpart2=0
f_dpart2=1250
gosub addDecimalVal
endif
if temp.0=1 then
f_temp=f_temp+0.0625
f_ndpart2=0
f_dpart2=0625
gosub addDecimalVal
endif
Return
DS_Write:
For BitCounter=0 to 7
Low DQ
If Command.0=0 then
Delayus 60
Input DQ
Else
Delayus 5
Input DQ
Delayus 55
Endif
Command=Command >> 1
Next
Return
Start:
Cls
Main: Gosub DS_Init
Command=204:Gosub DS_Write
Command=68:Gosub DS_write
delayms 720
Gosub DS_Init
Command=204:Gosub DS_Write
Command=190:Gosub DS_Write
Gosub DS_Read
If DS_TSensor=1 then
Print at 1,1," * No Device * "
Delayms 500
Cls
Else
print at 1,5 ,Neg_Pos_Temp
print at 1,6,dec f_ndpart1,"."
while f_zeros>0
print dec 0
f_zeros=f_zeros-1
wend
print dec f_dpart1
Endif
Goto Main
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -