2 Pe
2 Pe
General: info@parallax.com
Rocklin, California 95765, USA
Technical: support@parallax.com
Office: (916) 624-8333
Web Site: www.parallax.com
Fax: (916) 624-8003
Educational: www.parallax.com/sic
General Information
Vss Vdd
1 2 3 4 5 6 7 8 9 11 12 13 14
10 kΩ
P13
Vss
DS1822
4.7 kΩ
Vdd
DQ P15
GND
Vss
' Temp_lcd_data_demo.bs2
' Purpose... Reads and displays information from a Dallas DS1822,and stores data across memory
blocks.
' {$STAMP BS2pe}
' {$PBASIC 2.5}
' -----[ Declarations ]----------------------------------------------------
OWpin CON 15
LCDpin CON 0
NoCmd CON $00 ' No command in LCDOUT
ClrLCD CON $01 ' clear the LCD
CrsrHm CON $02 ' move cursor to home position
CrsLf CON $10 ' move cursor left
CrsRt CON $14 ' move cursor right
DispLf CON $18 ' shift displayed chars left
DispRt CON $1C ' shift displayed chars right
DDRam CON $80 ' Display Data RAM control
CGRam CON $40 ' Custom character RAM
Line1 CON $80 ' DDRAM address of line 1
Line2 CON $C0 ' DDRAM address of line 2
UNit_off CON $08
Unit_on CON $0d
No_Device_Found:
LCDOUT LCDpin,Line1,[" No DS1822"] : PAUSE 5
LCDOUT LCDpin,Line2,[" Present"]
PAUSE 1500
LCDCMD LCDpin,ClrLCD : PAUSE 0
LCDOUT LCDpin,Line1,["Insert Ds1822"] : PAUSE 5
LCDOUT LCDpin,Line2,["and reset stamp"]
PAUSE 1500
LCDCMD LCDpin,ClrLCD : PAUSE 0
goto main
Get_ROM:
OWOUT OWpin,OW_FERst,[ReadROM] ' send Read ROM command
OWIN OWpin,OW_BERst,[STR romData\8] ' read serial number & CRC
IF (romData(0) = DS1822) THEN Show_Data
LCDCMD LCDpin,ClrLCD : PAUSE 0
LCDOUT LCDpin,Line1,["Installed device"]
PAUSE 5
LCDOUT LCDpin,Line2,["is not DS1822"] : PAUSE 5
LCDOUT LCDpin,NoCmd,["Code = ",HEX2 romData(0)]
PAUSE 1500
goto main
Show_Data:
Display_Temperatures:
run_bit = 1
GOSUB Get_Temp
skip_over:
readings = tempF
IF in13 = 0 THEN full
GOSUB record
GOTO Main
NEXT
NoNegC:
tempF = tempC */ $01CD ' multiply by 1.8
IF tSign = 0 THEN NoNegF ' if neg, extend sign bits
tempF = tempF | $FF00
NoNegF:
tempF = tempF + 32 ' finish C -> F conversion
RETURN
Full:
FOR bank = 1 TO 15
FOR address = 0 TO 2048 step 2
STORE bank
READ address ,readings.lowbyte
READ address + 1,readings.highbyte
LCDCMD LCDpin,ClrLCD : PAUSE 0
LCDOUT LCDpin,Line1,["Reading: ",dec address/2] : PAUSE 0
LCDOUT LCDpin,Line2,["Bank:",dec bank,"Temp ","F:", SDEC tempF] : PAUSE 0
PAUSE 1000 ' lessen this pause to increase rate of display
NEXT
NEXT
Sleeping:
SLEEP 3
LCDCMD LCDpin,unit_off : PAUSE 0
IF IN12 = 1 THEN sleeping
LCDCMD LCDpin,unit_on : PAUSE 0
GOTO sleeping
Record:
PAUSE 1000 ‘Adjust to vary the rate of storage
If address < 2040 THEN no_up
bank = bank +1
address = 0
No_up:
'DEBUG 0,cr,"record: ",? bank,? address,? readings," Low ",dec readings.lowbyte," High
",dec readings.highbyte
STORE bank
WRITE address ,readings.lowbyte
WRITE address + 1,readings.highbyte
address = address + 2
IF bank = 15 AND address = 2040 THEN filled
return
filled:
LCDCMD LCDpin,ClrLCD : PAUSE 0
LCDOUT LCDpin,Line1,["Full"] : PAUSE 5
STOP