|
ME Labs, Inc. 719-520-5323 |
|
|
|
ME Labs, Inc. | 1-719-520-5323 | Example Program - TEMP_DS1822.pbpPICBASIC PRO program to read DS1822 or DS18B20 1-wire temperature sensor using OWIN and OWOUT commands and display temperature on LCD.' Name : TEMP_DS1822.pbp
' Compiler : PICBASIC PRO Compiler 2.60
' Assembler : PM or MPASM
' Target PIC : 40-pin 16F877, 877A or similar
' Hardware : LAB-X1 Experimenter Board
' Oscillator : 4MHz external crystal
' Keywords : DS1822, DS18B20, OWIN, OWOUT
' Description : PICBASIC PRO program to read DS1822 or DS18B20 1-wire
' temperature sensor using OWIN and OWOUT commands and display
' temperature on LCD.
'
temperature VAR WORD ' Temperature storage
count_remain VAR BYTE ' Count remaining
count_per_c VAR BYTE ' Count per degree C
DQ VAR PORTC.0 ' One-wire data pin
' Define LCD registers and bits
DEFINE LCD_DREG PORTD
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTE
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTE
DEFINE LCD_EBIT 1
ADCON1 = %00000111 ' Set PORTA and PORTE to digital
Low PORTE.2 ' LCD R/W line low (W)
mainloop:
OWOUT DQ, 1, [$CC, $44] ' Start temperature conversion
pause 2000
OWOUT DQ, 1, [$CC, $BE] ' Read the temperature
OWIN DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
' Calculate temperature in degrees C to 2 decimal places
' (not valid for negative temperature)
temperature = temperature */ 1600
LCDOUT $fe, 1, DEC (temperature / 100), ".", DEC2 temperature, " C"
' Calculate temperature in degrees F to 2 decimal places
' (not valid for negative temperature)
temperature = (temperature */ 461) + 3200
LCDOUT $fe, $c0, DEC (temperature / 100), ".", DEC2 temperature, " F"
GoTo mainloop ' Do it forever
Download the program file. |
|
Copyright 2022 ME Labs, Inc. PO Box 8250 Asheville NC 28814 (719) 520-5323 (719) 520-1867 fax email: support@melabs.com |
|