Vous êtes sur la page 1sur 2

Define SIMULATION_WAITMS_VALUE = 1

TRISA = %00100000 'port a je izlaz


PORTA = 0
TRISB = %00000000 'port b je izlaz
PORTB = 0
Define LCD_LINES = 2
Define LCD_CHARS = 16
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 0
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 5
Define LCD_EREG = PORTB
Define LCD_EBIT = 4
Define LCD_COMMANDUS = 5000 'delay after LCDCMDOUT, default value is
5000
Define LCD_DATAUS = 100 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 500
Define 1WIRE_REG = PORTB
Define 1WIRE_BIT = 6
Dim temp As Byte
Dim sign As Byte
Dim decimala As Byte
Dim temperatura As Word
Lcdinit
Lcddefchar 5, %01110, %01010, %01110, %00000, %00000, %00000, %00000,
%00000 'degree symbol
Lcdout "DS 18B20"
WaitMs 2000
loop:
DS18S20Start
WaitMs 1000
DS18S20ReadT temp, sign
Lcdcmdout LcdClear
decimala = ShiftLeft(temp, 4)
decimala = ShiftRight(decimala, 4)
If decimala = 15 Then decimala = 93
If decimala = 14 Then decimala = 87
If decimala = 13 Then decimala = 81
If decimala = 12 Then decimala = 75
If decimala = 11 Then decimala = 68
If decimala = 10 Then decimala = 62
If decimala = 9 Then decimala = 56
If decimala = 8 Then decimala = 50
If decimala = 7 Then decimala = 43
If decimala = 6 Then decimala = 37
If decimala = 5 Then decimala = 31
If decimala = 4 Then decimala = 25
If decimala = 3 Then decimala = 18
If decimala = 2 Then decimala = 12
If decimala = 1 Then decimala = 0
If decimala = 0 Then decimala = 0
temperatura = sign
temperatura = ShiftLeft(temperatura, 8)
temperatura = temperatura Or temp
temperatura = ShiftRight(temperatura, 4)
Lcdout "DS 18B20"

Lcdcmdout LcdLine2Home
Lcdout "Temp: " #temperatura, ".", #decimala, " ", 5, "C"
WaitMs 2000
Goto loop
End

Vous aimerez peut-être aussi