logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

[Mega32][Bascom] Multipleksowanie +1wire +LCD

Gibol 23 Sie 2009 20:01 2051 3
REKLAMA
  • #1 6926402
    Gibol
    Poziom 17  
    Długi czas już siedzę nad tym programem, analizując inne programy i próbując różnych sposobów ale nie mogę zmusić tego do działania...
    Byłby ktoś skłonny wytknąć mi błędy ?

    Dodam, że jak pominąć całą sprawę z timerem to na lcd poprawnie liczy mi wartości (tzn prawie poprawnie bo 28 / 10 wychodzi 2.7999995 ale temu już zaradziłem)

    
    $regfile = "m32def.dat"
    
    $crystal = 16000000
    
    
    
    
    Config Lcd = 16 * 2                                         'konfiguracja typu wyświetlacza LCD
    Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , E = Porta.1 , Rs = Porta.0
    
    Config Timer1 = Timer , Prescale = 256
    
    Config Portd = Output
    
    
    Config Portb = Output
    
    Config 1wire = Portc.0
    
    Dim A As Byte , B As Byte , C As Byte , A1 As Integer , B1 As Byte , B2 As Single , B3 As Single , C1 As Single
    Dim Opozniacz As Integer
    Dim I As Byte
    Dim T(2) As Byte
    Dim Temp As Single
    
    
    
    Enable Interrupts
    Enable Timer1
    Counter1 = 65200
    
    On Timer1 Wyswietlanie
    Start Timer1
    
    
    
    
    Do
    
    
    
    Disable Timer1
     Cursor Off
     Cls
    Lcd A1
    Lcd "x"
    Lcd B1
    Lcd "x"
    Lcd B2
    Lcd "x"
    Lcd B3
    Lowerline
    
    Lcd C1
    Lcd "x"
    Lcd Temp
    Lcd "x"
    Lcd A
    Lcd "x"
    Lcd B
    Lcd "x"
    Lcd C
    
    Enable Timer1
    Waitms 200
    Disable Timer1
    
    
    
    1wreset
    1wwrite &HCC
    1wwrite &H44
    
    Enable Timer1
    
    Waitms 750
    
    Disable Timer1
    
    1wreset
    1wwrite &HCC
    1wwrite &HBE
    T(1) = 1wread()
    T(2) = 1wread()
    1wreset
    Enable Timer1
    
      If T(2) = 0 Then
      Temp = T(1) / 2
      Else
      I = 256 - T(1)
      End If
    
      If Temp < 0 Then
      Set Portb.7
      Temp = -temp
      End If
    
     C1 = Frac(temp)
    C = C1 * 10
    B1 = Temp - C1
    B2 = B1 / 10
    B2 = B2 + 0.000001
    B3 = Frac(b2)
    B = B3 * 10
    A1 = B1 - B
    A = A1 \ 10
    
    
    
    
    Loop
    
    
    
    
    Wyswietlanie:
    
    Counter1 = 65200
    Disable Interrupts
    
    Portd = Lookup(a , Kody7seg)
    Portb.0 = 0
    Portb.1 = 1
    Portb.2 = 1
    
    Waitms 3
    Portd = Lookup(b , Kody7seg)
    Portb.0 = 1
    Portb.1 = 0
    Portb.2 = 1
    
    Waitms 3
    Portd = Lookup(c , Kody7seg)
    Portb.0 = 1
    Portb.1 = 1
    Portb.2 = 0
    
    Waitms 3
    Enable Interrupts
    
    Return
    
    
    Kody7seg:
    Data 64 , 121 , 36 , 48 , 25 , 18 , 2 , 120 , 0 , 16 , 127 , 28 , 255
    


    Poprawiłem tytuł - regulamin p.11
    [zumek]
  • REKLAMA
  • #2 6926991
    hose2
    Poziom 17  
    Witam,

    To:
      If T(2) = 0 Then
      Temp = T(1) / 2
      Else
      I = 256 - T(1)
      End If
    
      If Temp < 0 Then
      Set Portb.7
      Temp = -temp
      End If
    

    nie będzie Ci działać tak jak się tego spodziewasz, bo w Bascomie typ BYTE
    jest bez znaku (0-255), ale zamień "< 0" na "> 127" i masz już prawie wszystko
    na talerzu.

    Tu też jest błąd:
      If T(2) = 0 Then
      Temp = T(1) / 2
      Else
      I = 256 - T(1)
      End If
    
    bo DS1820 ma 9-bitową (a DS18B20 12-bitową domyślnie) rozdzielczość zawsze, a nie tylko przy temperaturze dodatniej.
  • REKLAMA
  • #3 6927334
    Gibol
    Poziom 17  
    ale temperaturę pokazuje ok (dodatnią) jeżeli wyrzucić linijki związane z timerem... poprawie to ale to i tak nie rozwiązuje mojego problemu. W tej postaci na obu wyświetlaczach mam krzaki...
  • #4 6929387
    Gibol
    Poziom 17  
    Udało mi się to uruchomić,
    lcd miałem tylko do testów czy wartości są ok, a to już jest ok więc wywaliłem procedury dla lcdka, i zostaly same ledy.
    Poprawiłem też te konwersje temp. Jak włożyłem do lodu pokazywało -12*C więc chyba jest teraz ok, jakby ktoś jeszcze potwierdził spałbym spokojnie.
    
    $regfile = "m32def.dat"
    
    $crystal = 16000000
    
    
    
    
    'Config Lcd = 16 * 2                                         'konfiguracja typu wyświetlacza LCD
    'Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , E = Porta.1 , Rs = Porta.0
    
    Config Timer1 = Timer , Prescale = 256
    
    Config Porta = Output
    
    
    Config Portb = Output
    
    Config 1wire = Portc.0
    
    Portb = &B11111111
    Porta = &B11111110
    
    Dim A As Byte , B As Byte , C As Byte , A1 As Integer , B1 As Byte , B2 As Single , B3 As Single , C1 As Single
    Dim Opozniacz As Integer
    Dim I As Byte
    Dim T(2) As Byte
    Dim Temp As Single
    
    On Timer1 Wyswietlanie
    
    Enable Interrupts
    Enable Timer1
    
    Load Timer1 , 700
    
    
    
    
    
    
    
    Do
    
    
    
    Disable Interrupts
     '(
     Cursor Off
     Cls
    Lcd A1
    Lcd "x"
    Lcd B1
    Lcd "x"
    Lcd B2
    Lcd "x"
    Lcd B3
    Lowerline
    
    Lcd C1
    Lcd "x"
    Lcd Temp
    Lcd "x"
    Lcd A
    Lcd "x"
    Lcd B
    Lcd "x"
    Lcd C
    ')
    
    1wreset
    1wwrite &HCC
    1wwrite &H44
    
    Enable Interrupts
    
    Waitms 750
    
    Disable Interrupts
    
    1wreset
    1wwrite &HCC
    1wwrite &HBE
    T(1) = 1wread()
    T(2) = 1wread()
    1wreset
    
    
      If T(2) = 0 Then
      Temp = T(1) / 2
      Reset Portb.7
      Else
      I = 256 - T(1)
      Temp = I / 2
      Set Portb.7
      End If
    
    
    
     C1 = Frac(temp)
    C = C1 * 10
    B1 = Temp - C1
    B2 = B1 / 10
    B2 = B2 + 0.000001
    B3 = Frac(b2)
    B = B3 * 10
    A1 = B1 - B
    A = A1 \ 10
     Enable Interrupts
    
    Waitms 1000
    
    Loop
    End
    
    
    
    Wyswietlanie:
    
    Load Timer1 , 700
    
    Porta = Lookup(a , Kody7seg)
    Portb.0 = 0
    Portb.1 = 1
    Portb.2 = 1
    
    Waitms 3
    Porta = Lookup(b , Kody7seg)
    Portb.0 = 1
    Portb.1 = 0
    Portb.2 = 1
    
    Waitms 3
    Porta = Lookup(c , Kody7seg)
    Portb.0 = 1
    Portb.1 = 1
    Portb.2 = 0
    
    Waitms 3
    
    
    Return
    
    
    Kody7seg:
    Data 64 , 121 , 36 , 48 , 25 , 18 , 2 , 120 , 0 , 16 , 127 , 28 , 255
    



    I teraz pytanie jeszcze jedno, teraz timer 1 robi całą robotę, ale poźniej bedzie sie zajmował pwm, więc jak użyć do tego Timer0 ? Jaka wartość prescale i load ?
REKLAMA