Hello there, im kind new with pics but i have some knowledge about basic schematics and programming.
- I use pic6F88
- Oscilator 20Mhz
-And for testing reasons because i dont have an lcd screen i use TX/RX pseudo-RS232
I have started a project that i need to read 18b20's temp and do something else... but i stuck in busy bit 1 month now, and can't find any solution :'(.
Im kinda desperate because i dont know what else to check....
Here is my code :
include "modedefs.bas"
'---------------------------------------------------------------
' DEFINES
'---------------------------------------------------------------
TRISA=%00000010
TRISB=%00000100
CMCON=0
ANSEL=0
ADCON0=0
DEFINE OSC 20
'---------------------------------------------------------------
' Variables
'---------------------------------------------------------------
present var bit
count_remain var byte
count_per_c var byte
sign1 var byte
tempout var byte
temp var byte
t05 var byte
t05out var byte
tempb20 VAR WORD
DQ VAR PORTA.1
RX VAR PORTB.2
TX VAR PORTB.5
'--------------------------------------------------------------
' Initialisation
'--------------------------------------------------------------
CLEAR
serout tx,n9600,["TEST OK",13,10]
pause 1500
'-------------------------------------------------------------
' Main prog
'-------------------------------------------------------------
main:
while 1
gosub sensor_ch1
IF present=1 then
gosub mainloop1
tempout=temp
t05out=t05
else
tempout=99
t05out=9
endif
Serout2 tx,16468,["T=",dec2 tempout,",",t05out,"C",13,10]
pause 250
wend
'================================================= =
' Subroutines
'================================================= =
'------------------------------------------------------------------------------------------
' Presence
'------------------------------------------------------------------------------------------
sensor_ch1:
Low DQ 'Set the data pin low to initialize
PauseUs 500 'Wait for more than 480us
TRISA.1=1 'Release the data pin (set to input for high)
PauseUs 100 'Wait for more than 60us
IF DQ=1 Then 'Is there a DS1820 detected Present=1
present=0 'If not, then clear DS_VALID flag Presebt=0
Else
present=1
EndIF
Return 'And return with DS_Valid holding 0
'---------------------------------------------------------------------------------------------------
' Read 18B20 Sensor
'---------------------------------------------------------------------------------------------------
mainloop1:
TRISA.1=0 'read temp ch0 connect it to RA.1
OWOut DQ, 1, [$CC, $44] 'Start temperature conversion
waitloop1:
pauseus 200
OWOut DQ, 1, [$CC, $BE] 'Read the temperature
TRISA.1=1
OWIn DQ, 0, [tempb20.LOWBYTE, tempb20.HIGHBYTE, Skip 4, count_remain, count_per_c]
IF tempb20.15=1 Then
sign1=1
if tempb20.3=1 and tempb20.2=0 and tempb20.1=0 and tempb20.0=0 then
t05="5"
else
t05="0"
endif
tempb20=tempb20 >> 4
tempb20=tempb20.lowbyte ^ 255'Reverse the bits of the lowbyte of TEMP because negative
temp=tempb20.lowbyte
Else
sign1=0
if tempb20.3=1 then t05="5"
if tempb20.3=0 then t05="0"
tempb20=tempb20 >> 4
temp=tempb20.lowbyte
EndIF
Return
eND
Bookmarks