PDA

View Full Version : Anyone can explain this code please? (Read temperature with DS1620 +pic 16F628)



crynof
- 10th November 2014, 16:41
I have this code (DS1620 with PIC 16F628), and was trying to understand how works, but i dont know whats means the variables.

Anyone can explain me this code??




include "Modedefs.bas
DEFINE OSC = 4
VRCON = 0
TRISA= %00000000
TRISB = % 00000000
CFGW CON $0C
CPUCN CON $02
START CON $EE
GETT CON $AA
STH CON $01
STL CON $02

DST var PortB.0
CLK Var PortB.1
RST var PortB.2
SER var PortB.3
Temp var byte
GCel var byte

gosub Init
GoSUB SetHL
gosub LetGo

e_go:
gosub Lee_T
GCel = Temp /2
serout ser,N2400,[GCel]
pause 250
goto e_go
end

Init:
High RST
shiftout DST,CLK,LSBFIRST,[CFGW,CPUCN]
low RST
pause 10
return

LetGo
high RST
shiftout DST,CLK,LSBFIRST,[START]
low RST
pause 10
return

Lee_T:
high RST
shiftout DST,CLK,LSBFIRST,[GetT]
shiftin DST,CLK,LSBPRE,[Temp]
low RST
return

SetHL:
high RST
shiftout DST,CLK,LSBFIRST,[SHL,48\9]
low RST
pause 10
high RST
shiftout DST,CLK,LSBFIRST,[STL,34\9]
low RST
pause 10
return




Thanks!!

Acetronics2
- 10th November 2014, 17:49
You'll find everything you're looking for in the DS 1620 datasheet ...

see here for commented code snippets ...
http://cornerstonerobotics.org/curriculum/lessons_year2/erii_ds1620_thermometer.pdf
http://cornerstonerobotics.org/picbasic_system_control.php
http://melabs.com/samples/LABX1-16F887/temp3x.htm

Alain

Archangel
- 10th November 2014, 17:51
A variable is a space in memory which you have given a name to and declared it's size, or it is a register, port etc . . . which you have given an alias to.
When you post "found code" it is usually helpful to post a link to where you found it too.


DST var PortB.0 'most likely DQ pin 1 of ds1620
CLK Var PortB.1 'pin 2 of ds1620
RST var PortB.2 'pin 3 " " " "
SER var PortB.3 'pin user is sending information to serial display
Temp var byte 'store rew received data
GCel var byte 'var to store temp/2






http://datasheets.maximintegrated.com/en/ds/DS1620.pdf

Acetronics2
- 10th November 2014, 18:20
CFGW CON $0C
CPUCN CON $02
START CON $EE
GETT CON $AA
STH CON $01
STL CON $02




Those variables ( which are constants !!! ) are custom names for the DS1620 command codes and internal DS1620 registers ...

sooo simple !!! ( with the datasheet - once more - )