' Name : TEMP_DS1822.pbp
' Compiler : PICBASIC PRO Compiler 2.60
' Assembler : PM or MPASM
' Target PIC : 40-pin 16F887
' 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
ANSEL = 000000 ' Make PORTA and PORTE digital
ANSELH= 000000 ' Make PORTA and PORTE 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
29 Ekim 2013 Salı
Posted by Adsız on 03:49
with No comments so far
Categories: Elektronik Devreler
Kaydol:
Kayıt Yorumları (Atom)
0 yorum:
Yorum Gönder