DS1820 i MicroCode studio

Rasprava o PIC mikrokontrolerima, PIC projekti i drugo vezano za PIC-eve...

Moderators: pedja089, stojke369, [eDo], trax

Post Reply
User avatar
dejanmaksa
Napredujem
Napredujem
Posts: 159
Joined: 28-10-2008, 22:15
Location: Velika Plana

DS1820 i MicroCode studio

Post by dejanmaksa »

Zanima me kako se citaju vrednosti iz DS1820 a pri tome se program pise u MicroBasic studiu.
Pratio sam kurs ali nisam naleteo kako se definise sve to oko DS1820 u ovom programu. Ima samo jedan post.
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: DS1820 i MicroCode studio

Post by pedja089 »

DaTi wrote:Evo kod z rad sa ds18b20 (proveren)

Code: Select all

                   
        symbol  DQ = PORTb.2             ' Dq linija je povez. na pin RE2
       
        temperatura  Var Word            ' Promen.za cuvanje izmer. temp.
            count_remain Var Byte            ' Ostatak
            count_per_c  Var Byte            ' Ostatak po stepenu C
            ADCON1 = 7                           ' PORTA i PORTE su digitalni
        Pause 100                        ' Pauza za start LCD-a
Pocetak:
            OWOut DQ, 1, [$CC, $44]      ' Start merenja temperature
Cekaj:  OWIn DQ, 4, [count_remain]       ' Provera da li jos traje
            If count_remain = 0 Then Cekaj
            OWOut DQ, 1, [$CC, $BE]      ' Procitaj izmerenu temperaturu
            OWIn DQ, 0, [temperatura.LOWBYTE, temperatura.HIGHBYTE, Skip 4, count_remain, count_per_c]
       
           ' Prikazi temperaturu u DEC obliku
       
           temperatura = (((temperatura >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
           Lcdout $fe, 1, "   TEMPERATURA"
           Lcdout $fe, $C0, "      ", DEC (temperatura / 100), ".", DEC2        temperatura, " C"
       Pause 5000                            ' Zadrzi pet sekundi
       
           GoTo Pocetak                      ' Ponovi sve
           End                           ' Kraj programa
ceo program, sve provereno bilo je u ovoj temi http://www.elektronika.ba/forum/viewtop ... f=3&t=4919" onclick="window.open(this.href);return false;
u kodu su ti svi redovi iskomentarisali, pogledaj malo i datasheet pa mislim da ce ti sve biti jasno
User avatar
dejanmaksa
Napredujem
Napredujem
Posts: 159
Joined: 28-10-2008, 22:15
Location: Velika Plana

Re: DS1820 i MicroCode studio

Post by dejanmaksa »

Thanks
User avatar
dejanmaksa
Napredujem
Napredujem
Posts: 159
Joined: 28-10-2008, 22:15
Location: Velika Plana

Re: DS1820 i MicroCode studio

Post by dejanmaksa »

A sta je sa temperaturom kad ode u minus
User avatar
Smjesko
Stariji član
Stariji član
Posts: 4012
Joined: 26-12-2005, 17:12

Re: DS1820 i MicroCode studio

Post by Smjesko »

Ovo je pravo pitanje. To i mene zanima, buduci da u datashitu pise da je mjerno podrucje od -55 do +125 WCelzijusa.
User avatar
DaTi
Odlično uznapredovao
Odlično uznapredovao
Posts: 730
Joined: 10-06-2007, 13:24
Location: Novi Sad - Srbija
Contact:

Re: DS1820 i MicroCode studio

Post by DaTi »

NIje jos softverski podrzano :D
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: DS1820 i MicroCode studio

Post by pedja089 »

evo ovde ima primer koji ima minus
flash005 wrote:Pozdrav svima...

Ovaj kod je copy-paste i helpa..od micro basica....program za mjerenje temperature preko ds1820

program onewire

dim i, j1, j2 as byte
text as string[15]
tmp_sign as byte

main:

text = "Temp:- flash005"
adcon1 = 255 ' configure RA5 pin as digital I/O
PORTA = 255 ' initialize porte to 255
PORTD = 0 ' initialize portb to 255
TRISA = 255 ' designate porte as input
TRISD = 0 ' designate portb as output
Lcd_Init(PORTD)
lcd_cmd(LCD_CURSOR_OFF)
lcd_out(1, 1, text)
lcd_chr(2, 12, 223) ' 'degree' character
lcd_chr(2, 13, "C")

while TRUE
ow_reset(PORTA, 5) ' onewire reset signal
ow_write(PORTA, 5, $CC) ' issue command to DS1820
ow_write(PORTA, 5, $44) ' issue command to DS1820
delay_us(120)
i = ow_reset(PORTA, 5)
ow_write(PORTA, 5, $CC) ' issue command to DS1820
ow_write(PORTA, 5, $BE) ' issue command to DS1820

j1 = ow_read(PORTA, 5) ' get result
j2 = ow_read(PORTA, 5) ' get result (assuming the temperature is positive)

if j2 = $FF then
tmp_sign = "-" ' temperature sign
j1= j1 or $FF ' complement of two
j1= j1 + $01
else
tmp_sign = "+"
end if
j2 = (j1 and $01) * 5 ' Get decimal value
j1 = j1 >> 1 ' Get temp value

ByteToStr(j1, text) ' whole number
lcd_chr(2, 7, tmp_sign)
lcd_chr(2, 8, text[1])
lcd_chr(2, 9, text[2])
lcd_chr(2, 10, 46) ''.'

ByteToStr(j2, text) ' decimal
lcd_chr(2, 11, text[2])

Delay_ms(500)
wend 'endless loop
end.

-------------------------------------------------------------------------------
Međutim ovaj podebljani dio..mi nikako nece u glavu.....

j1= j1 or $FF ' complement of two

nakon ove naredbe .... j1 u bilo kojem slučaju ide na vrijednost FFh što nema nikakvog smisla..:D
malo pogledajte odakle je uizvuceno ovo j2
pogledajte ovaj deo koda.
ow_write(PORTA, 5, $CC) ' issue command to DS1820
ow_write(PORTA, 5, $BE) ' issue command to DS1820

j1 = ow_read(PORTA, 5) ' get result
j2 = ow_read(PORTA, 5) ' get result (assuming the temperature is positive)
' get result (assuming the temperature is positive)
koliko ja kapiram on posle rezultata salje 255 ako je u pitanju negativni rezultat
micromatic
Penjem se :)
Penjem se :)
Posts: 58
Joined: 23-02-2005, 14:13
Location: Hrvatska - Cakovec
Contact:

Re: DS1820 i MicroCode studio

Post by micromatic »

Pretpostavljam da je greška u kodu. Računanje drugog komplementa broja (negativnog) ide na način:
j1= j1 xor $FF ' invertiranje j1
j1= j1 + $01 '+1
__________________
http://www.micromatic.hr
__________________
User avatar
Smjesko
Stariji član
Stariji član
Posts: 4012
Joined: 26-12-2005, 17:12

Re: DS1820 i MicroCode studio

Post by Smjesko »

Decki, sve je to u redu o cemu vi raspravljate, ali za nas PICBasic-nepismene bi koristio jedan .hex napisan za neku od shema termometara objavjenih ovdje na stranici, s podrskom za negativnu temperaturu.
User avatar
DaTi
Odlično uznapredovao
Odlično uznapredovao
Posts: 730
Joined: 10-06-2007, 13:24
Location: Novi Sad - Srbija
Contact:

Re: DS1820 i MicroCode studio

Post by DaTi »

evo ja cu probati ubaciti mogucnost da moze da meri ispod 0 u moj termometar.
Post Reply