<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=12&amp;t=8264&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2014-09-05T18:51:28+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=12&amp;t=8264&amp;mode</id>
<entry>
<author><name><![CDATA[slawek3000]]></name></author>
<updated>2014-09-05T18:51:28+01:00</updated>
<published>2014-09-05T18:51:28+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=8264&amp;p=94385#p94385</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=8264&amp;p=94385#p94385"/>
<title type="html"><![CDATA[Re: Zamrożenie pomiaru temperatury]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=8264&amp;p=94385#p94385"><![CDATA[
Witam,<br />Teraz po podłączeniu kilku DS18B20 na przemiennie jest wyświetlana temperatura , ale jednocześnie mam ograniczoną możliwość sterowania encoderem, tzn.muszę się wstrzelić w okno pomiędzy przemiataniem -wyświetlaniem kolejnych czujników ... teoretycznie wiem jak to można by rozwiązać ... ale z kodem mam problem <br /> ... jak można by zrobić coś takiego jeżeli nie kręcę encoderem i nie używam pewnych przycisków to podprogram odczytuje z &quot;przemiataniem&quot; <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":-)" title="Szczęśliwy" /> temperaturę z czujników jeżeli encoder , przyciski są używane to przemiatanie jest wstrzymane <br /><br />lub bardziej , co mi odpowiada program czujników nie zależnie działa i nie przeszkadza w funkcjonalności encodera jakby działały nie zależnie od siebie <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":-)" title="Szczęśliwy" /> <br /><br />poniżej kod czujników<br /><br />[syntax=basic4gl]'*************************************************<br />'* Code to test DS18x20<br />'* The 1-wire bus pin is Port B.4<br />'* Tested 14th Dec 2008 with Bascom 1.11.9.1<br />'*<br />'* Brett England<br />'*************************************************<br /><br />' The DS18x20 1-wire chips can only be polled every 750ms therefore we need<br />' to wait.  If this code is to be used in other programs we would want this<br />' polling to be interrupt driven so other tasks can be executed during the<br />' wait period.<br /><br />' We will setup a timer that ticks every 750ms on each even tick we will<br />' ask all the 1-wire devices to read and place their values into the scratchpad<br />' on the odd ticks we will read these values.<br /><br />$regfile = &quot;m644pdef.dat&quot;                                   ' specify the used micro<br />$crystal = 16000000<br />$baud = 19200                                               ' use baud rate<br />$hwstack = 32                                               ' default use 32 for the hardware stack<br />$swstack = 10                                               ' default use 10 for the SW stack<br />$framesize = 40                                             ' default use 40 for the frame space<br /><br />$lib &quot;glcdKS108.lbx&quot;<br /><br /><br />'First we define that we use a graphic LCD<br />Config Graphlcd = 128 * 64sed , Dataport = Porta , Controlport = Portb , Ce = 0 , Ce2 = 1 , Cd = 4 , Rd = 3 , Reset = 2 , Enable = 5<br /><br /><br />Declare Sub Convallt                                        ' Convert T on ALL sensors<br />Declare Sub Meas_to_cel(offset As Byte)<br />Declare Sub To_decicel<br />Declare Sub Monitor<br />Declare Sub Disp_temp(cnt As Byte , Offset As Byte)<br /><br />' Up to 8 devices - each having an 8 byte ROMID<br />Const Max1wire = 8<br />Dim Dsid(64) As Byte                                        ' Dallas ID 64bit inc. CRC<br /><br />' Temperature measurement<br />Dim Cel As Integer                                          ' Celcuis<br />Dim Cel_frac_bit As Byte                                    '.1 of celcius<br />Dim Subzero As Bit                                          ' +ve / -ve indicator<br />Dim Decicel As Integer                                      ' 28.9C = 289 decicel<br /><br />Dim Sc(9) As Byte                                           ' scratch pad<br />Dim Cnt1wire As Byte                                        ' Number of 1-wire devices found<br /><br />'Temp variables<br />Dim B As Byte<br />Dim B1 As Byte<br />Dim B2 As Byte<br />Dim I As Byte<br />Dim W As Word<br /><br />' I want a timer that resolves to 750mS, so the first step is to divide down<br />' the input clock .  Input clock to divide by 256, so now each clock pulse is<br />' worth (8.192/256)=32uS.<br /><br />' The trick is to preload the counter with a value that will cause it to count<br />' for 750mS. Each time the counter expires, you can force the new number back<br />' into the timer register. We need .75/.000032 or 23437 counts. However, the<br />' counter expires at 65536, so the correct number to preload is 65536-23437 or<br />' 42098 This way, the timer will count up 42098 counts (750 ms) and<br />' expire.<br />Const 750ms = 42098                                         ' @ 8Mhz<br />Config Timer1 = Timer , Prescale = 256<br />On Timer1 Timer1_int<br />Config Timer2 = Timer , Prescale = 128<br />Dim Time1_count As Byte<br />Dim Time1_ok As Bit<br /><br />Const Ds18b20_conf_reg = 4<br /><br />' constant to convert the fraction bits to cel*(10^-4)<br />Const Ds18x20_fracconv = 625<br /><br />' DS18x20 ROM ID<br />Const Ds18s20_id = &amp;H10<br />Const Ds18b20_id = &amp;H28<br /><br />' COMMANDS<br />Const Ds18x20_convert_t = &amp;H44<br />Const Ds18x20_read = &amp;HBE<br />Const Ds18x20_write = &amp;H4E<br />Const Ds18x20_ee_write = &amp;H48<br />Const Ds18x20_ee_recall = &amp;HB8<br />Const Ds18x20_read_power_supply = &amp;HB4<br /><br />'LCD config<br /><br /><br />Config 1wire = Pb.7                                         '<br /><br /><br />Cls<br /><br />Setfont My6_8 : Lcdat 5 , 1 , &quot;1-wire DS18x20&quot;<br />Wait 1<br /><br /><br />' Gather ROM ID for all 1-wire devices<br />Cnt1wire = 1wirecount()<br />If Cnt1wire &gt; Max1wire Then<br />  Cnt1wire = Max1wire<br />End If<br /><br />B = 1<br />Dsid(b) = 1wsearchfirst()<br />For I = 1 To Cnt1wire<br />  B = B + 8<br />  Dsid(b) = 1wsearchnext()<br />Next<br /><br />' Show what we found on the bus<br />B1 = 1<br />B2 = 8<br />For I = 1 To Cnt1wire<br /><br />  If Dsid(b2) = Crc8(dsid(b1) , 7) Then<br />    Setfont My6_8 : Lcdat 5 , 1 , &quot;CRC OK sensor &quot; ; I<br />    Waitms 500<br /><br />   Setfont My6_8 : Lcdat 6 , 1 , &quot;ROM ID &quot;<br />    For B = B1 To B2<br />     Setfont My6_8 : Lcdat 7 , 1 , Hex(dsid(b))<br />    Next<br />  Else<br />    Setfont My6_8 : Lcdat 7 , 1 , &quot;CRC BAD sensor &quot; ; I<br />  End If<br />  Wait 1<br />  B1 = B1 + 8<br />  B2 = B2 + 8<br />Next<br /><br />' Monitor temperature sensors<br />Time1_count = 0 : Timer1 = 750ms : Time1_ok = 0<br />Enable Timer1<br />Enable Interrupts<br />Start Timer1<br />Do<br />  If Time1_ok = 1 Then                                      'An interrupt event ?<br />    Stop Timer1<br /><br />    If Time1_count = 0 Then                                 'Make measurement<br />       Convallt<br />    Elseif Time1_count = 1 Then<br />       Monitor                                              'Show results<br />    End If<br /><br />    Reset Time1_ok<br />    Start Timer1<br />  End If<br />  'Box(10 , 30) -(60 , 100) , 1<br />  'Boxfill(10 , 48) -(11 , 54) , 1 : Boxfill(13 , 48) -(14 , 54) , 1 : Boxfill(16 , 48) -(17 , 54) , 1<br />Loop<br /> 'Timer Interrupt<br />Timer1_int:<br />   Timer1 = 750ms<br />   Set Time1_ok<br />   Incr Time1_count<br />   If Time1_count &gt; 1 Then Time1_count = 0<br />   Return<br /><br />End<br /><br />Sub Monitor<br />  B = 1<br />  For I = 1 To Cnt1wire<br />    If Dsid(b) = Ds18s20_id Or Dsid(b) = Ds18b20_id Then    ' Only process TEMP sensors<br />      1wverify Dsid(b)                                      'Issues the &quot;Match ROM &quot;<br />      If Err = 1 Then<br />        Setfont My6_8 : Lcdat 2 , 1 , &quot;18x20 not on bus&quot;    'where did it go?<br />      Elseif Err = 0 Then<br />        1wwrite Ds18x20_read<br />        Sc(1) = 1wread(9)<br />        If Sc(9) = Crc8(sc(1) , 8) Then<br />          Call Disp_temp(i , B)<br />          If I &lt; Cnt1wire Then                              ' if more 1-wire devices.<br />             Wait 1<br />          End If<br />        End If<br />      End If<br />    End If<br /><br />    B = B + 8<br />  Next<br />End Sub<br /><br /><br />'Makes the Dallas &quot;Convert T&quot; command on the 1w-bus configured in &quot;Config 1wire = Portb. &quot;<br />'WAIT 200-750 ms after issued, internal conversion time for the sensor<br />'SKIPS ROM - so it makes the conversion on ALL sensors on the bus simultaniously<br />'When leaving this sub, NO sensor is selected, but ALL sensors has the actual<br />'temperature in their scratchpad ( within 750 ms )<br /><br />Sub Convallt<br /> 1wreset                                                    ' reset the bus<br /> 1wwrite &amp;HCC                                               ' skip rom<br /> 1wwrite Ds18x20_convert_t<br />End Sub<br /><br />' input:<br />'   - offset - in the dsid array which 1-wire are we addressing<br />' output:<br />'   - cel full celsius<br />'   - fractions of celsius in millicelsius*(10^-1)/625 (the 4 LS-Bits)<br />'   - subzero =0 positiv / 1 negativ<br />Sub Meas_to_cel(offset As Byte)<br /> Dim Meas As Word<br /><br /> Meas = 0<br /> Meas = Makeint(sc(1) , Sc(2))<br /><br /> ' 18S20 is only 9bit upscale to 12bit<br /> If Dsid(offset) = Ds18s20_id Then<br />   Meas = Meas And &amp;HFFFE<br />   Shift Meas , Left , 3<br />   B1 = 16 - Sc(6)                                          ' sc(6) count remain<br />   B1 = B1 - 4<br />   Meas = Meas + B1<br /> End If<br /><br /> W = Meas And &amp;H8000<br /> If W = &amp;H8000 Then<br />   Set Subzero<br />   ' convert to +ve, (two's complement)++<br />   Meas = Meas Xor &amp;HFFFF<br />   Incr Meas<br /> Else<br />   Reset Subzero<br /> End If<br /><br /> If Dsid(offset) = Ds18b20_id Then<br />   B1 = Sc(ds18b20_conf_reg)<br />   ' clear undefined bit for != 12bit<br />   If B1.5 = 1 And B1.6 = 1 Then                            ' 12 bit<br />    ' nothing<br />   Elseif B1.6 = 1 Then                                     ' 11 bit<br />     Meas = Meas And &amp;HFFFE<br />   Elseif B1.5 = 1 Then                                     '10 bit<br />     Meas = Meas And &amp;HFFFC<br />   Else                                                     ' 9 bit<br />     Meas = Meas And &amp;HFFF8<br />   End If<br /> End If<br /><br /> Cel = Meas<br /> Shift Cel , Right , 4<br /> Cel_frac_bit = Meas And &amp;HF<br />End Sub<br /><br />' input: cel, cel_frac_bit, subzero<br />' output: temp (as decicelsius)<br />' ie 289 = 28.9C<br />Sub To_decicel<br />  Decicel = Cel_frac_bit * Ds18x20_fracconv<br />  Decicel = Decicel / 1000<br />  Cel = Cel * 10<br />  Decicel = Decicel + Cel<br />  If Subzero = 1 Then<br />     Restore Rounding<br />     For B1 = 1 To 8<br />        Read B2<br />        If Cel_frac_bit = B2 Then<br />          Incr Decicel<br />          Exit For<br />        End If<br />     Next<br />  End If<br />End Sub<br /><br />' Display the temperature<br />' INPUT: temp<br />Sub Disp_temp(cnt As Byte , Offset As Byte)<br />  Call Meas_to_cel(offset)<br />  Call To_decicel<br /><br />  Cls<br />  Setfont My6_8 : Lcdat 1 , 1 , &quot;TEMP&quot; ; Cnt ; &quot; &quot;<br />  If Subzero = 1 Then<br />    Setfont My6_8 : Lcdat 1 , 30 , &quot;-&quot;<br />  Else<br />    Setfont My6_8 : Lcdat 1 , 30 , &quot;+&quot;<br />  End If<br /><br />  W = Decicel / 10<br />  B1 = Decicel Mod 10<br />  Setfont My6_8 : Lcdat 1 , 40 , W ; &quot;.&quot; ; B1<br />  Setfont My6_8 : Lcdat 1 , 66 , &quot;C&quot;<br />End Sub<br /><br />Rounding:<br />Data 1 , 3 , 4 , 6 , 9 , 11 , 12 , 14<br /><br /> $include &quot;my6_8.font&quot;<br /> $include &quot;my12_16.font&quot;<br /> $include &quot;font8x8.font&quot;[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=988">slawek3000</a> — 5 wrz 2014, o 18:51</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[slawek3000]]></name></author>
<updated>2014-08-26T21:01:31+01:00</updated>
<published>2014-08-26T21:01:31+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=8264&amp;p=93036#p93036</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=8264&amp;p=93036#p93036"/>
<title type="html"><![CDATA[Re: Zamrożenie pomiaru temperatury]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=8264&amp;p=93036#p93036"><![CDATA[
Poradziłem sobie , po prostu musiałem poustawiać części kodu w odpowiedniej kolejności a z czujnikami chce zrobić tak wyświetla na się ten, który wybierzemy w menu czujniki będą coś tam załączać , wyłączać jak osiągną daną temperaturę <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":-)" title="Szczęśliwy" /><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=988">slawek3000</a> — 26 sie 2014, o 21:01</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[slawek3000]]></name></author>
<updated>2014-08-26T19:07:58+01:00</updated>
<published>2014-08-26T19:07:58+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=8264&amp;p=93016#p93016</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=8264&amp;p=93016#p93016"/>
<title type="html"><![CDATA[Re: Zamrożenie pomiaru temperatury]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=8264&amp;p=93016#p93016"><![CDATA[
To jak to mam zrobić ,żeby działało ?<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=988">slawek3000</a> — 26 sie 2014, o 19:07</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[slawek3000]]></name></author>
<updated>2014-08-25T16:03:13+01:00</updated>
<published>2014-08-25T16:03:13+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=8264&amp;p=92824#p92824</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=8264&amp;p=92824#p92824"/>
<title type="html"><![CDATA[Re: Zamrożenie pomiaru temperatury]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=8264&amp;p=92824#p92824"><![CDATA[
Wiesz , ale to jest dziwne w tym kodzie działa bez zarzutu<br />[youtube]<br /><!-- m --><a class="postlink" href="https://www.youtube.com/watch?v=pz6tid_PzP4&amp;feature=youtu.be" >https://www.youtube.com/watch?v=pz6tid_ ... e=youtu.be</a><!-- m --><br />[/youtube]<br /><br /><br /> [syntax=basic4gl]'Filename   Encoder_100.bas<br />'Version    1.00<br />'Date       2012-03-19<br />'Purpose    Test of ALPS STEC11B13 encoder (reichelt.de)<br />'Author     Georg Latzel, DL6GL<br />'Copyright  (c) Georg Latzel, free for private use under GNU license<br />'Hardware   ATmega8<br />'           Crystal 16 MHz<br />'           2x16 Text LCD @ PortC<br />'           Encoder A @ PortB.0<br />'           Encoder B @ PortB.1<br />'Compiler   BASCOM-AVR 2.0.7.3<br />'           For readable &quot;camel case&quot; variables mark &quot;Don't change case&quot;<br />'           in BASCOM Options-Programmer-Environment-Editor<br />'           Flash used: 1420 bytes (17%)<br />'Edit history<br />'V1.00      2012-03-19, first release<br /><br />'==============================================================================<br /><br />'FUSE-Bits (Ponyprog-Settings, &#91; &#93;=no check, &#91;x&#93;=check)<br />'In ATmega data sheets: Bit = 1 -&gt; not set = &#91; &#93; Ponyprog<br />'                       Bit = 0 -&gt; set     = &#91;x&#93; Ponyprog<br />'- OCDEN    &#91; &#93;<br />'- JTAGEN:  &#91; &#93; (disabled!, otherwise LCD at PORT.C does not work)<br />'- EESAVE   &#91; &#93; Save EEProm on erase chip<br />'- BOOTSZ1  &#91;x&#93; Select Boot size<br />'- BOOTSZ0  &#91;x&#93; Select Boot size<br />'- BOOTRST  &#91; &#93; Select reset vector<br />'- Crystal oscillator<br />'  CKOPT:   &#91; &#93; (=1, low Oscillator amplitude or=1, &#91;x&#93;, high ampl.)<br />'  CKSEL3:  &#91; &#93; (=1, Select Clock Source)<br />'  CKSEL2:  &#91; &#93; (=1, as well)<br />'  CKSEL1:  &#91; &#93; (=1, as well)<br />'  CKSEL0:  &#91; &#93; (=1, crystal osc. fast start up 16k CK + 4ms)<br />'  SUT1:    &#91; &#93; (=1, as well)<br />'  SUT0:    &#91;x&#93; (=0, as well)<br /><br />$regfile = &quot;m644pdef.dat&quot;                                   ' specify the used micro<br />$crystal = 16000000<br />$baud = 19200                                               ' use baud rate<br />$hwstack = 32                                               ' default use 32 for the hardware stack<br />$swstack = 10                                               ' default use 10 for the SW stack<br />$framesize = 40                                             ' default use 40 for the frame space<br /><br />$lib &quot;glcdKS108.lbx&quot;<br /><br /><br />'First we define that we use a graphic LCD<br />Config Graphlcd = 128 * 64sed , Dataport = Porta , Controlport = Portb , Ce = 0 , Ce2 = 1 , Cd = 4 , Rd = 3 , Reset = 2 , Enable = 5<br /><br />'Configure Encoder on Port B --------------------------------------------------<br />Ddrd = &amp;B00000000                                           'Portd = input<br />Portd = &amp;B11111111                                          'Activate Pullup<br />'Config 1wire = Portb.7<br />'                                                 'PIND.0 = Encoder Pin A<br />'                                                 'PIND.1 = Encoder Pin B<br />'                                                 'PIND.2 = Encoder key<br />Enc_a Alias Pind.6                                          'Encoder A<br />Enc_b Alias Pind.7                                          'Encoder B<br />Enc_k Alias Pind.5                                          'Encoder key<br />Config Sda = Portc.1                                        'konfiguracja sprzętowa I2C<br />Config Scl = Portc.0<br />Config I2cdelay = 0<br />'Configure Timer0 interrupt for encoder  --------------------------------------<br />'Timer0 = 8 bit<br />'Overflow time: overflow counts * Prescale / crystal frequency<br />'= 256 * 256 / 16.000.000 Hz = 4,1 msec = ~ 244 Hz<br />'Here Prescale = 256<br />'The encoder is polled every 4,1 msec. To shorten time set PresetTimer 0 &gt; 0<br />'Possible Prescales: 8, 64, 256, 1024<br />Config Timer0 = Timer , Prescale = 256<br />Const Presettimer0 = 0                                      'Initialize Timer0<br />On Timer0 Timer0_isr                                        'Timer0 Interrupt service routine<br /><br />'Common Variables, multiply used ----------------------------------------------<br />Dim Lngfreq As Long<br />Dim Lngstep As Long<br />Dim Strfreq As String * 9<br />Dim 1s As Byte<br /><br />'Zmienne zegara----------------------------------------------------<br />Dim Mic As Byte<br />Dim Dzien As Byte<br />Dim Miesiac As Byte<br />Dim Rok As Byte                                             'rok z pcf (od 0 do 3)<br />Dim Rok_2 As Byte                                           'ostatnie dwie cyfry - rok z ramu minus rok z pcf<br />Dim Rok_w As Byte                                           'rok do bezpośredniego wyświetlania<br />Dim Dzien_tygodnia As Byte<br />Dim H As Byte , M As Byte , S As Byte<br />Dim Godz As String * 3 , Minut As String * 2 , Sek As String * 2<br /><br />'Variables Encoder  -----------------------------------------------------------<br />Dim Bytincr As Byte                                         '=2: Encoder incr., =1: decr., =0: ./.<br />Dim Bytenc_old As Byte<br />Dim Bytenc_new As Byte<br />Dim Bitkey_enc As Bit                                       'Encoder key, =1: pressed<br />Const Doublestep = 0                                        '=1: intermediate position detected<br /><br />Declare Sub Clearlcdline(byval Bytline As Byte)<br />'------------------------------------------------------------------------------<br /><br />Declare Sub Convallt                                        ' Convert T on ALL sensors<br />Declare Sub Meas_to_cel(offset As Byte)<br />Declare Sub To_decicel<br />Declare Sub Monitor<br />Declare Sub Disp_temp(cnt As Byte , Offset As Byte)<br /><br />' Up to 8 devices - each having an 8 byte ROMID<br />Const Max1wire = 8<br />Dim Dsid(64) As Byte                                        ' Dallas ID 64bit inc. CRC<br /><br />' Temperature measurement<br />Dim Cel As Integer                                          ' Celcuis<br />Dim Cel_frac_bit As Byte                                    '.1 of celcius<br />Dim Subzero As Bit                                          ' +ve / -ve indicator<br />Dim Decicel As Integer                                      ' 28.9C = 289 decicel<br /><br />Dim Sc(9) As Byte                                           ' scratch pad<br />Dim Cnt1wire As Byte                                        ' Number of 1-wire devices found<br /><br />'Temp variables<br />Dim B As Byte<br />Dim B1 As Byte<br />Dim B2 As Byte<br />Dim I As Byte<br />Dim W As Word<br /><br /><br />Const 750ms = 42098                                         ' @ 8Mhz<br />Config Timer1 = Timer , Prescale = 256<br />On Timer1 Timer1_int<br />'Config Timer2 = Timer , Prescale = 256 , Compare A = Disconnect , Compare B = Disconnect , Clear Timer = 1<br />'On Compare1a Odmierz_1s<br />Dim Time1_count As Byte<br />Dim Time1_ok As Bit<br />Const Ds18b20_conf_reg = 4<br /><br />' constant to convert the fraction bits to cel*(10^-4)<br />Const Ds18x20_fracconv = 625<br /><br />' DS18x20 ROM ID<br />Const Ds18s20_id = &amp;H10<br />Const Ds18b20_id = &amp;H28<br /><br />' COMMANDS<br />Const Ds18x20_convert_t = &amp;H44<br />Const Ds18x20_read = &amp;HBE<br />Const Ds18x20_write = &amp;H4E<br />Const Ds18x20_ee_write = &amp;H48<br />Const Ds18x20_ee_recall = &amp;HB8<br />Const Ds18x20_read_power_supply = &amp;HB4<br /><br />Config 1wire = Portb.7                                      ' DS1820 on Port B.4 (mega8 pin 18)<br />' Gather ROM ID for all 1-wire devices<br />Cnt1wire = 1wirecount()<br />If Cnt1wire &gt; Max1wire Then<br />  Cnt1wire = Max1wire<br />End If<br /><br />B = 1<br />Dsid(b) = 1wsearchfirst()<br />For I = 1 To Cnt1wire<br />  B = B + 8<br />  Dsid(b) = 1wsearchnext()<br />Next<br /><br />' Show what we found on the bus<br /><br /><br />' Monitor temperature sensors<br />Time1_count = 0 : Timer1 = 750ms : Time1_ok = 0<br />Enable Timer1<br />Enable Interrupts<br />Start Timer1<br />Start Timer2<br />'Main program  ****************************************************************<br />Cls<br />Gosub Wyswietlacz<br /><br />Lngfreq = 14000000<br />Lngstep = 10<br /><br />Strfreq = Str(lngfreq)<br />Strfreq = Format(strfreq , &quot; 0.000000&quot;)<br />Setfont My12_16 : Lcdat 3 , 20 , Strfreq<br /><br />Bytenc_old = 0                                              'Encoder data<br />Bytenc_new = 0                                              'Encoder data<br />Bytincr = 0<br /><br />Enable Timer0<br />                                               'Interrupt encoder<br />'Enable Interrupts                                           'enable all Interrupts<br /> Gosub Wyswietlacz<br />Do<br /><br />   Disable Timer0                                           'Stop Timer0 for display<br /><br />   Select Case Bytincr                                      'Set/show TRX freq.<br />      Case 2                                                'Encoder incremented<br />         Lngfreq = Lngfreq + Lngstep<br />      Case 1                                                'Encoder decremented<br />         Lngfreq = Lngfreq - Lngstep<br />   End Select<br />       Setfont My6_8 : Lcdat 1 , 5 , Bytincr<br />   If Bytincr &gt; 0 Then                                      'Freq. was changed<br />      Strfreq = Str(lngfreq)<br />      Strfreq = Format(strfreq , &quot; 0.000000&quot;)<br />      'Call Clearlcdline(2)<br />      Setfont My12_16 : Lcdat 3 , 20 , Strfreq<br />      Bytincr = 0                                           'Reset increment flag<br />   End If<br />       Gosub Zegar<br />   Enable Timer0<br />   Gosub Wyswietlacz                                        'Restart Timer0<br />     If Time1_ok = 1 Then                                   'An interrupt event ?<br />    Stop Timer1<br /><br />    If Time1_count = 0 Then                                 'Make measurement<br />       Convallt<br />    Elseif Time1_count = 1 Then<br />       Monitor                                              'Show results<br />    End If<br /><br />    Reset Time1_ok<br />    Start Timer1<br />  End If<br />Loop<br />End<br />Return<br /><br />Timer1_int:<br />   Timer1 = 750ms<br />   Set Time1_ok<br />   Incr Time1_count<br />   If Time1_count &gt; 1 Then Time1_count = 0<br />   Return<br /><br />End<br /><br />Sub Monitor<br />  B = 1<br />  For I = 1 To Cnt1wire<br />    If Dsid(b) = Ds18s20_id Or Dsid(b) = Ds18b20_id Then    ' Only process TEMP sensors<br />      1wverify Dsid(b)                                      'Issues the &quot;Match ROM &quot;<br />      If Err = 1 Then<br />         Setfont My6_8 : Lcdat 4 , 1 , &quot;18x20 not on bus&quot;   'where did it go?<br />      Elseif Err = 0 Then<br />        1wwrite Ds18x20_read<br />        Sc(1) = 1wread(9)<br />        If Sc(9) = Crc8(sc(1) , 8) Then<br />          Call Disp_temp(i , B)<br />          If I &lt; Cnt1wire Then                              ' if more 1-wire devices.<br />             Wait 1<br />          End If<br />        End If<br />      End If<br />    End If<br /><br />    B = B + 8<br />  Next<br />End Sub<br /><br /><br /><br /><br />Sub Convallt<br /> 1wreset                                                    ' reset the bus<br /> 1wwrite &amp;HCC                                               ' skip rom<br /> 1wwrite Ds18x20_convert_t<br />End Sub<br /><br /><br />Sub Meas_to_cel(offset As Byte)<br /> Dim Meas As Word<br /><br /> Meas = 0<br /> Meas = Makeint(sc(1) , Sc(2))<br /><br /> ' 18S20 is only 9bit upscale to 12bit<br /> If Dsid(offset) = Ds18s20_id Then<br />   Meas = Meas And &amp;HFFFE<br />   Shift Meas , Left , 3<br />   B1 = 16 - Sc(6)                                          ' sc(6) count remain<br />   B1 = B1 - 4<br />   Meas = Meas + B1<br /> End If<br /><br /> W = Meas And &amp;H8000<br /> If W = &amp;H8000 Then<br />   Set Subzero<br />   ' convert to +ve, (two's complement)++<br />   Meas = Meas Xor &amp;HFFFF<br />   Incr Meas<br /> Else<br />   Reset Subzero<br /> End If<br /><br /> If Dsid(offset) = Ds18b20_id Then<br />   B1 = Sc(ds18b20_conf_reg)<br />   ' clear undefined bit for != 12bit<br />   If B1.5 = 1 And B1.6 = 1 Then                            ' 12 bit<br />    ' nothing<br />   Elseif B1.6 = 1 Then                                     ' 11 bit<br />     Meas = Meas And &amp;HFFFE<br />   Elseif B1.5 = 1 Then                                     '10 bit<br />     Meas = Meas And &amp;HFFFC<br />   Else                                                     ' 9 bit<br />     Meas = Meas And &amp;HFFF8<br />   End If<br /> End If<br /><br /> Cel = Meas<br /> Shift Cel , Right , 4<br /> Cel_frac_bit = Meas And &amp;HF<br />End Sub<br /><br />' input: cel, cel_frac_bit, subzero<br />' output: temp (as decicelsius)<br />' ie 289 = 28.9C<br />Sub To_decicel<br />  Decicel = Cel_frac_bit * Ds18x20_fracconv<br />  Decicel = Decicel / 1000<br />  Cel = Cel * 10<br />  Decicel = Decicel + Cel<br />  If Subzero = 1 Then<br />     Restore Rounding<br />     For B1 = 1 To 8<br />        Read B2<br />        If Cel_frac_bit = B2 Then<br />          Incr Decicel<br />          Exit For<br />        End If<br />     Next<br />  End If<br />End Sub<br /><br />' Display the temperature<br />' INPUT: temp<br />Sub Disp_temp(cnt As Byte , Offset As Byte)<br />  Call Meas_to_cel(offset)<br />  Call To_decicel<br /><br /><br /><br /><br />  W = Decicel / 10<br />  B1 = Decicel Mod 10<br /> Setfont My6_8 : Lcdat 1 , 40 , W ; &quot;.&quot; ; B1<br /><br />End Sub<br /><br /> Wyswietlacz:<br />      Setfont My6_8 : Lcdat 2 , 40 , &quot;Icom Inc&quot;<br />      Setfont My6_8 : Lcdat 5 , 1 , &quot;^&quot; : Lcdat 5 , 10 , &quot;1&quot; , 1 : Lcdat 5 , 20 , &quot;ATT&quot; : Lcdat 5 , 40 , &quot;0dB&quot; , 1 :       'Line(57 , 32) -(57 , 39) , 1<br />     Setfont My6_8 : Lcdat 6 , 1 , &quot;S ~1~3~5~7~9+20+40 dB&quot; :<br />     Setfont My6_8 : Lcdat 8 , 1 , &quot;Po   10  30  50   100&quot; :<br />      'Boxfill(10 , 48) -(11 , 54) , 1 : Boxfill(13 , 48) -(14 , 54) , 1 : Boxfill(16 , 48) -(17 , 54) , 1<br /> Return<br /><br /> Odmierz_1s:<br />   Incr 1s<br />   Lcdat 2 , 1 , 1s<br /> Return<br /><br /><br /><br /> Zegar:<br />'Obsługa zegara na PCF 8583<br />I2cstart                                                    'inicjalizacja magistrali I2C<br />I2cwbyte 162                                                'podanie adresu PCF8583 dla zapisu<br />I2cwbyte 2                                                  'wybranie drugiego rejestru<br />I2cstart                                                    'powtórna inicjalizacja magistrali I2C<br />I2cwbyte 163                                                'podanie adresu PCF8583 dla odczytu danych<br />I2crbyte S , Ack                                            'odczyt sekund z potwierdzeniem transmisji<br />I2crbyte M , Ack                                            'odczyt minut z potwierdzeniem transmisji<br />I2crbyte H , Ack                                            'odczyt godzin bez potwierdzania transmisji<br />I2crbyte Dzien , Ack<br />I2crbyte Miesiac , Nack<br />I2cstop                                                     'koniec transmisji I2C<br /><br />S = Makedec(s)                                              'po odczycie zamieniamy kod bcd na zwykłe liczby<br />M = Makedec(m)<br />H = Makedec(h)<br /><br />'pobranie roku z pamięci ram<br />I2cstart<br />I2cwbyte 162<br />I2cwbyte &amp;H10<br />I2cstart<br />I2cwbyte 163<br />I2crbyte Rok_2 , Nack<br />I2cstop<br /><br />'przeliczenie danych z pcf na date dziesiętną<br />Rok = Dzien<br />Shift Rok , Right , 6<br />Rok = Makedec(rok)<br />Dzien.7 = 0 : Dzien.6 = 0<br />Dzien = Makedec(dzien)<br />Dzien_tygodnia = Miesiac<br />Shift Dzien_tygodnia , Right , 5<br />Dzien_tygodnia = Makedec(dzien_tygodnia)<br />Miesiac.7 = 0 : Miesiac.6 = 0 : Miesiac.5 = 0<br />Miesiac = Makedec(miesiac)<br /><br />Rok_w = Rok_2 + Rok<br /><br />      If H &lt; 10 Then Godz = &quot;0&quot; + Godz<br />         Godz = Str(h)<br />      If M &lt; 10 Then Minut = &quot;0&quot; + Minut<br />         Minut = Str(m)<br />      If S &lt; 10 Then Sek = &quot;0&quot; + Sek<br />         Sek = Str(s)<br /><br /> If H &lt; 10 Then<br />   Setfont My6_8 : Lcdat 1 , 95 , &quot;0&quot; ; H ; &quot;:&quot;<br />   Else<br /> Setfont My6_8 : Lcdat 1 , 95 , H ; &quot;:&quot;<br />   End If<br /><br /> If M &lt; 10 Then<br />   Setfont My6_8 : Lcdat 1 , 115 , &quot;0&quot; ; M ;<br />   Else<br /> Setfont My6_8 : Lcdat 1 , 115 , M ;<br />   End If<br /> 'Setfont My6_8 : Lcdat 1 , 99 , H ; &quot;:&quot; ; M,<br /><br /> Return<br /><br /><br /><br />'End of main program **********************************************************<br /><br />'------------------------------------------------------------------------------<br />Timer0_isr:<br />'Encoder interrupt on Timer0 overflow<br />'While data are displayed Timer0 should be stopped<br />'Output: bytIncr = 2: increment, =1: decrement if encoder was changed<br />'Having processed the bytIncr data in the main program reset bytIncr = 0<br />'Switching pattern of ALPS STEC11 encoder:<br />'Turning clockwise              ... counter clockwise<br />'A    B                             A     B<br />'1    1  start detent position      1     1<br />'1    0  intermediate position 1    0     1<br />'0    0  intermediate position 2    0     0<br />'0    1  intermediate position 3    1     0<br />'1    1  next detent position       1     1<br /><br />   Timer0 = Presettimer0<br />   Bytenc_new.0 = Enc_a                                     'Set bit 0 of bytEnc_new<br />   Bytenc_new.1 = Enc_b                                     'Set bit 1 of bytEnc_new<br /><br />   'Check encoder pattern if encoder is changed<br />   'bytIncr = 1: decremented (turned counter clockwise)<br />   'bytIncr = 2: incremented (turned         clockwise)<br />   If Bytenc_new &lt;&gt; Bytenc_old Then                         'encoder is changed<br />      'from intermediate position 3 to quiescent position<br />      If Bytenc_new = &amp;B00000011 And Bytenc_old = &amp;B00000010 Then Bytincr = 2<br />      If Bytenc_new = &amp;B00000011 And Bytenc_old = &amp;B00000001 Then Bytincr = 1<br />      'from intermediate position 1 to intermediate position 2<br />      'DoubleStep = 1:  intermediate position 2 gives an additional tick<br />      '                 2 ticks between 2 detent positions on slow rotation<br />      '           = 0:  1 tick  between 2 detent positions<br />      #if Doublestep = 1<br />         If Bytenc_new = &amp;B00000000 And Bytenc_old = &amp;B00000001 Then Bytincr = 2<br />         If Bytenc_new = &amp;B00000000 And Bytenc_old = &amp;B00000010 Then Bytincr = 1<br />      #endif<br />      Bytenc_old = Bytenc_new                               'old &lt;- new for the next time<br />   End If<br />Return<br /><br />'------------------------------------------------------------------------------<br />Sub Clearlcdline(byval Bytline As Byte)<br /><br />End Sub<br />'------------------------------------------------------------------------------<br />Rounding:<br />Data 1 , 3 , 4 , 6 , 9 , 11 , 12 , 14<br />$include &quot;my12_16.font&quot;<br />$include &quot;my6_8.font&quot;[/syntax]<br /><br />pierwotny kod tam gdzie ma te podprogramy jest dość duży, idą Twoim przykładem rozbiłem go na mniejsze pliki<br /><br /><strong><span style="color: #808000">------------------------ [ Dodano po: 19 minutach ]</span></strong><br /><br />ile czujników max chyba 8 tyle ile można , wiesz taki podstawowy do czujnika mam ale on opóźnia mi pracę encodera<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=988">slawek3000</a> — 25 sie 2014, o 16:03</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[slawek3000]]></name></author>
<updated>2014-08-25T05:17:34+01:00</updated>
<published>2014-08-25T05:17:34+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=8264&amp;p=92769#p92769</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=8264&amp;p=92769#p92769"/>
<title type="html"><![CDATA[Zamrożenie pomiaru temperatury]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=8264&amp;p=92769#p92769"><![CDATA[
Witam,<br /><br />Wyskoczył mi problem z wyświetlaniem ,może z pomiarem temperatury za pomocą DS18B20 mam jeszcze na płytce zegar zrobiony za pomocą PCF8583 a mianowicie gdy włączę płytkę termometr działa gdy na zegarze zmieni minutę automatycznie termometr zostaje zamrożony nie co jest przyczyną tego tu jest kod zegara<br />[syntax=basic4gl]Zegar:<br />'Obsługa zegara na PCF 8583<br />I2cstart                                                    'inicjalizacja magistrali I2C<br />I2cwbyte 162                                                'podanie adresu PCF8583 dla zapisu<br />I2cwbyte 2                                                  'wybranie drugiego rejestru<br />I2cstart                                                    'powtórna inicjalizacja magistrali I2C<br />I2cwbyte 163                                                'podanie adresu PCF8583 dla odczytu danych<br />I2crbyte S , Ack                                            'odczyt sekund z potwierdzeniem transmisji<br />I2crbyte M , Ack                                            'odczyt minut z potwierdzeniem transmisji<br />I2crbyte H , Ack                                            'odczyt godzin bez potwierdzania transmisji<br />I2crbyte Dzien , Ack<br />I2crbyte Miesiac , Nack<br />I2cstop                                                     'koniec transmisji I2C<br /><br />S = Makedec(s)                                              'po odczycie zamieniamy kod bcd na zwykłe liczby<br />M = Makedec(m)<br />H = Makedec(h)<br /><br />'pobranie roku z pamięci ram<br />I2cstart<br />I2cwbyte 162<br />I2cwbyte &amp;H10<br />I2cstart<br />I2cwbyte 163<br />I2crbyte Rok_2 , Nack<br />I2cstop<br /><br />'przeliczenie danych z pcf na date dziesiętną<br />Rok = Dzien<br />Shift Rok , Right , 6<br />Rok = Makedec(rok)<br />Dzien.7 = 0 : Dzien.6 = 0<br />Dzien = Makedec(dzien)<br />Dzien_tygodnia = Miesiac<br />Shift Dzien_tygodnia , Right , 5<br />Dzien_tygodnia = Makedec(dzien_tygodnia)<br />Miesiac.7 = 0 : Miesiac.6 = 0 : Miesiac.5 = 0<br />Miesiac = Makedec(miesiac)<br /><br />Rok_w = Rok_2 + Rok<br /><br />      If H &lt; 10 Then Godz = &quot;0&quot; + Godz<br />         Godz = Str(h)<br />      If M &lt; 10 Then Minut = &quot;0&quot; + Minut<br />         Minut = Str(m)<br />      If S &lt; 10 Then Sek = &quot;0&quot; + Sek<br />         Sek = Str(s)<br /><br /> If H &lt; 10 Then<br />   Setfont My6_8 : Lcdat 1 , 95 , &quot;0&quot; ; H ; &quot;:&quot;<br />   Else<br /> Setfont My6_8 : Lcdat 1 , 95 , H ; &quot;:&quot;<br />   End If<br /><br /> If M &lt; 10 Then<br />   Setfont My6_8 : Lcdat 1 , 115 , &quot;0&quot; ; M ;<br />   Else<br /> Setfont My6_8 : Lcdat 1 , 115 , M ;<br />   End If<br /> 'Setfont My6_8 : Lcdat 1 , 99 , H ; &quot;:&quot; ; M,<br />Return[/syntax]<br /><br />a tutaj pomiaru temperatury , ten drugi jest wersji oryginalnej na alfanumerycznym LCD, ja w swoim pozmieniałem tylko LCD na lcdat <br /><br />[syntax=basic4gl]*************************************************<br />'* Code to test DS18x20<br />'* The 1-wire bus pin is Port B.4<br />'* Tested 14th Dec 2008 with Bascom 1.11.9.1<br />'*<br />'* Brett England<br />'*************************************************<br /> <br />' The DS18x20 1-wire chips can only be polled every 750ms therefore we need<br />' to wait.  If this code is to be used in other programs we would want this<br />' polling to be interrupt driven so other tasks can be executed during the<br />' wait period.<br /> <br />' We will setup a timer that ticks every 750ms on each even tick we will<br />' ask all the 1-wire devices to read and place their values into the scratchpad<br />' on the odd ticks we will read these values.<br /> <br />$regfile = &quot;m8def.dat&quot;<br />$crystal = 8000000                                          ' we are using this frequency<br /> <br />Declare Sub Convallt                                        ' Convert T on ALL sensors<br />Declare Sub Meas_to_cel(offset As Byte)<br />Declare Sub To_decicel<br />Declare Sub Monitor<br />Declare Sub Disp_temp(cnt As Byte , Offset As Byte)<br /> <br />' Up to 8 devices - each having an 8 byte ROMID<br />Const Max1wire = 8<br />Dim Dsid(64) As Byte                                        ' Dallas ID 64bit inc. CRC<br /> <br />' Temperature measurement<br />Dim Cel As Integer                                          ' Celcuis<br />Dim Cel_frac_bit As Byte                                    '.1 of celcius<br />Dim Subzero As Bit                                          ' +ve / -ve indicator<br />Dim Decicel As Integer                                      ' 28.9C = 289 decicel<br /> <br />Dim Sc(9) As Byte                                           ' scratch pad<br />Dim Cnt1wire As Byte                                        ' Number of 1-wire devices found<br /> <br />'Temp variables<br />Dim B As Byte<br />Dim B1 As Byte<br />Dim B2 As Byte<br />Dim I As Byte<br />Dim W As Word<br /> <br />' I want a timer that resolves to 750mS, so the first step is to divide down<br />' the input clock .  Input clock to divide by 256, so now each clock pulse is<br />' worth (8.192/256)=32uS.<br /> <br />' The trick is to preload the counter with a value that will cause it to count<br />' for 750mS. Each time the counter expires, you can force the new number back<br />' into the timer register. We need .75/.000032 or 23437 counts. However, the<br />' counter expires at 65536, so the correct number to preload is 65536-23437 or<br />' 42098 This way, the timer will count up 42098 counts (750 ms) and<br />' expire.<br />Const 750ms = 42098                                         ' @ 8Mhz<br />Config Timer1 = Timer , Prescale = 256<br />On Timer1 Timer1_int<br /> <br />Dim Time1_count As Byte<br />Dim Time1_ok As Bit<br /> <br />Const Ds18b20_conf_reg = 4<br /> <br />' constant to convert the fraction bits to cel*(10^-4)<br />Const Ds18x20_fracconv = 625<br /> <br />' DS18x20 ROM ID<br />Const Ds18s20_id = &amp;H10<br />Const Ds18b20_id = &amp;H28<br /> <br />' COMMANDS<br />Const Ds18x20_convert_t = &amp;H44<br />Const Ds18x20_read = &amp;HBE<br />Const Ds18x20_write = &amp;H4E<br />Const Ds18x20_ee_write = &amp;H48<br />Const Ds18x20_ee_recall = &amp;HB8<br />Const Ds18x20_read_power_supply = &amp;HB4<br /> <br />'LCD config<br />Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0<br />Config Lcd = 16 * 1a<br /> <br />Config 1wire = Pb.4                                         ' DS1820 on Port B.4 (mega8 pin 18)<br /> <br />Cursor Off<br />Cls<br /> <br />Lcd &quot;1-wire DS18x20&quot;<br />Wait 1<br />Cls<br /> <br />' Gather ROM ID for all 1-wire devices<br />Cnt1wire = 1wirecount()<br />If Cnt1wire &gt; Max1wire Then<br />  Cnt1wire = Max1wire<br />End If<br /> <br />B = 1<br />Dsid(b) = 1wsearchfirst()<br />For I = 1 To Cnt1wire<br />  B = B + 8<br />  Dsid(b) = 1wsearchnext()<br />Next<br /> <br />' Show what we found on the bus<br />B1 = 1<br />B2 = 8<br />For I = 1 To Cnt1wire<br />  Cls<br />  If Dsid(b2) = Crc8(dsid(b1) , 7) Then<br />    Lcd &quot;CRC OK sensor &quot; ; I<br />    Waitms 500<br />    Cls<br />    Lcd &quot;ROM ID &quot;<br />    For B = B1 To B2<br />      Lcd Hex(dsid(b))<br />    Next<br />  Else<br />    Lcd &quot;CRC BAD sensor &quot; ; I<br />  End If<br />  Wait 1<br />  B1 = B1 + 8<br />  B2 = B2 + 8<br />Next<br /> <br />' Monitor temperature sensors<br />Time1_count = 0 : Timer1 = 750ms : Time1_ok = 0<br />Enable Timer1<br />Enable Interrupts<br />Start Timer1<br />Do<br />  If Time1_ok = 1 Then                                      'An interrupt event ?<br />    Stop Timer1<br /> <br />    If Time1_count = 0 Then                                 'Make measurement<br />       Convallt<br />    Elseif Time1_count = 1 Then<br />       Monitor                                              'Show results<br />    End If<br /> <br />    Reset Time1_ok<br />    Start Timer1<br />  End If<br />Loop<br /> <br />' Timer interrupt<br />Timer1_int:<br />   Timer1 = 750ms<br />   Set Time1_ok<br />   Incr Time1_count<br />   If Time1_count &gt; 1 Then Time1_count = 0<br />   Return<br /> <br />End<br /> <br />Sub Monitor<br />  B = 1<br />  For I = 1 To Cnt1wire<br />    If Dsid(b) = Ds18s20_id Or Dsid(b) = Ds18b20_id Then    ' Only process TEMP sensors<br />      1wverify Dsid(b)                                      'Issues the &quot;Match ROM &quot;<br />      If Err = 1 Then<br />        Lcd &quot;18x20 not on bus&quot;                              'where did it go?<br />      Elseif Err = 0 Then<br />        1wwrite Ds18x20_read<br />        Sc(1) = 1wread(9)<br />        If Sc(9) = Crc8(sc(1) , 8) Then<br />          Call Disp_temp(i , B)<br />          If I &lt; Cnt1wire Then                              ' if more 1-wire devices.<br />             Wait 1<br />          End If<br />        End If<br />      End If<br />    End If<br /> <br />    B = B + 8<br />  Next<br />End Sub<br /> <br /> <br />'Makes the Dallas &quot;Convert T&quot; command on the 1w-bus configured in &quot;Config 1wire = Portb. &quot;<br />'WAIT 200-750 ms after issued, internal conversion time for the sensor<br />'SKIPS ROM - so it makes the conversion on ALL sensors on the bus simultaniously<br />'When leaving this sub, NO sensor is selected, but ALL sensors has the actual<br />'temperature in their scratchpad ( within 750 ms )<br /> <br />Sub Convallt<br /> 1wreset                                                    ' reset the bus<br /> 1wwrite &amp;HCC                                               ' skip rom<br /> 1wwrite Ds18x20_convert_t<br />End Sub<br /> <br />' input:<br />'   - offset - in the dsid array which 1-wire are we addressing<br />' output:<br />'   - cel full celsius<br />'   - fractions of celsius in millicelsius*(10^-1)/625 (the 4 LS-Bits)<br />'   - subzero =0 positiv / 1 negativ<br />Sub Meas_to_cel(offset As Byte)<br /> Dim Meas As Word<br /> <br /> Meas = 0<br /> Meas = Makeint(sc(1) , Sc(2))<br /> <br /> ' 18S20 is only 9bit upscale to 12bit<br /> If Dsid(offset) = Ds18s20_id Then<br />   Meas = Meas And &amp;HFFFE<br />   Shift Meas , Left , 3<br />   B1 = 16 - Sc(6)                                          ' sc(6) count remain<br />   B1 = B1 - 4<br />   Meas = Meas + B1<br /> End If<br /> <br /> W = Meas And &amp;H8000<br /> If W = &amp;H8000 Then<br />   Set Subzero<br />   ' convert to +ve, (two's complement)++<br />   Meas = Meas Xor &amp;HFFFF<br />   Incr Meas<br /> Else<br />   Reset Subzero<br /> End If<br /> <br /> If Dsid(offset) = Ds18b20_id Then<br />   B1 = Sc(ds18b20_conf_reg)<br />   ' clear undefined bit for != 12bit<br />   If B1.5 = 1 And B1.6 = 1 Then                            ' 12 bit<br />    ' nothing<br />   Elseif B1.6 = 1 Then                                     ' 11 bit<br />     Meas = Meas And &amp;HFFFE<br />   Elseif B1.5 = 1 Then                                     '10 bit<br />     Meas = Meas And &amp;HFFFC<br />   Else                                                     ' 9 bit<br />     Meas = Meas And &amp;HFFF8<br />   End If<br /> End If<br /> <br /> Cel = Meas<br /> Shift Cel , Right , 4<br /> Cel_frac_bit = Meas And &amp;HF<br />End Sub<br /> <br />' input: cel, cel_frac_bit, subzero<br />' output: temp (as decicelsius)<br />' ie 289 = 28.9C<br />Sub To_decicel<br />  Decicel = Cel_frac_bit * Ds18x20_fracconv<br />  Decicel = Decicel / 1000<br />  Cel = Cel * 10<br />  Decicel = Decicel + Cel<br />  If Subzero = 1 Then<br />     Restore Rounding<br />     For B1 = 1 To 8<br />        Read B2<br />        If Cel_frac_bit = B2 Then<br />          Incr Decicel<br />          Exit For<br />        End If<br />     Next<br />  End If<br />End Sub<br /> <br />' Display the temperature<br />' INPUT: temp<br />Sub Disp_temp(cnt As Byte , Offset As Byte)<br />  Call Meas_to_cel(offset)<br />  Call To_decicel<br /> <br />  Cls<br />  Lcd &quot;TEMP &quot; ; Cnt ; &quot; &quot;<br />  If Subzero = 1 Then<br />    Lcd &quot;-&quot;<br />  Else<br />    Lcd &quot;+&quot;<br />  End If<br /> <br />  W = Decicel / 10<br />  B1 = Decicel Mod 10<br />  Lcd W ; &quot;.&quot; ; B1<br />  Lcd &quot; C&quot;<br />End Sub<br /> <br />Rounding:<br />Data 1 , 3 , 4 , 6 , 9 , 11 , 12 , 14[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=988">slawek3000</a> — 25 sie 2014, o 05:17</p><hr />
]]></content>
</entry>
</feed>