Elektroda.pl
Elektroda.pl
X
Please add exception to AdBlock for elektroda.pl.
If you watch the ads, you support portal and users.

bascom at89c4051 i resetujący się program

omen_s 27 Aug 2006 20:13 1478 7
  • #1
    omen_s
    Level 19  
    Witam

    mam coś takiego :
    Config 1wire = P1.0
    
    Ledzolta Alias P3.0
    Ledmieszanie Alias P3.1
    Ledgrzanie Alias P3.2
    Ledgrzalki Alias P3.4
    Ledalarm Alias P3.5
    Mieszanie Alias P1.6
    Grzanie Alias P1.7
    Wyj1 Alias P1.4
    Wyj2 Alias P1.3
    Wyj3 Alias P1.2
    
    Reset P1
    Set P1.7
    Set P1.6
    Set P3
    
    Dim A1 As Bit
    Dim C As Bit
    Dim D As Bit
    Dim E As Integer
    Dim F As Integer
    Dim Temp As Integer
    Dim C3 As Integer
    Dim Zmienna_temp(8) As Byte
    
    Reset A1
    Reset C
    Reset D
    Reset E
    Reset F
    
    Reset Ledzolta
    Reset Ledmieszanie
    Reset Ledgrzanie
    Reset Ledgrzalki
    Reset Ledalarm
    Wait 1
    Set Ledzolta
    Set Ledmieszanie
    Set Ledgrzanie
    Set Ledgrzalki
    Set Ledalarm
    
    Wait 1
    
    Do
    
    Reset Ledzolta
    
    Waitms 100
    
    Loop
    
    End


    i to działa ale gdy do pętli do...loop wpisze coś takiego:
    Do
    
    Reset Ledzolta
    
    If Mieszanie = 0 And A1 = 0 Then
       Set A1
       Reset Ledmieszanie
       Pk1:
       If Mieszanie = 0 Then Goto Pk1
    End If
    
    Waitms 100
    
    Loop
    
    End


    to program nawet nie wchodzi do pętli (wtedy zapaliła by śię tylko zółta led) tylko miga wszystkimi czyli dochodzi do fragmentu :
    Reset Ledzolta
    Reset Ledmieszanie
    Reset Ledgrzanie
    Reset Ledgrzalki
    Reset Ledalarm
    Wait 1
    Set Ledzolta
    Set Ledmieszanie
    Set Ledgrzanie
    Set Ledgrzalki
    Set Ledalarm
    
    Wait 1


    i po wait 1 program zaczyna od początku :roll:

    i już sam nie wiem co mam robić :(
    ktoś ma jakieś pomysły ?

    ps. mikrokontroler jest na kwarcu 12MHz (ustawione w programie tak samo jak biblioteka do at89c4051)

    pozdrawiam


    ...nawet takie coś nie działa :
    Ledzolta Alias P3.0
    Ledmieszanie Alias P3.1
    Ledgrzanie Alias P3.2
    Ledgrzalki Alias P3.4
    Ledalarm Alias P3.5
    Mieszanie Alias P1.6
    Grzanie Alias P1.7
    Wyj1 Alias P1.4
    Wyj2 Alias P1.3
    Wyj3 Alias P1.2
    
    Reset P1
    Set P1.7
    Set P1.6
    Set P3
    
    Dim A1 As Bit
    
    Reset A1
    
    Reset Ledzolta
    Wait 1
    Set Ledzolta
    Wait 1
    
    Do
    
    Reset Ledzolta
    
    If Mieszanie = 0 And A1 = 0 Then
       Set A1
       Reset Ledmieszanie
       Pk1:
       If Mieszanie = 0 Then Goto Pk1
    End If
    
    Loop
    
    End


    Czy to może być wina bascoma ? bo dla mnie o troche dziwne że nie działa if.......end if
  • #2
    zumek
    Level 39  
    To zamiast Goto(brrrrrr...) , spróbuj :
    
    While Mieszanie = 0 : Wend 
    'lub
    Bitwait Mieszanie , Reset
    

    A o instrukcji Goto - zapomnij :(

    Piotrek
  • #3
    omen_s
    Level 19  
    Więc tak z tamtym to już działa winny był bascom, zainstalowałem inny i teraz to już działa tj nie zatrzymuje się przed pętlą.
    ALe teraz mam inny problem:

    Config 1wire = P1.0
    
    Reset P1
    Set P1.7
    Set P1.6
    Set P3
    
    Ledzolta Alias P3.0
    Ledmieszanie Alias P3.1
    Ledgrzanie Alias P3.2
    Ledgrzalki Alias P3.4
    Ledalarm Alias P3.5
    Mieszanie Alias P1.6
    Grzanie Alias P1.7
    Wyj1 Alias P1.4
    Wyj2 Alias P1.3
    Wyj3 Alias P1.2
    
    Reset Wyj1
    Reset Wyj2
    Reset Wyj3
    
    Dim A1 As Bit
    Dim C As Bit
    Dim D As Bit
    Dim E As Integer
    Dim F As Integer
    Dim Temp As Integer
    Dim C3 As Integer
    Dim Zmienna_temp(8) As Byte
    
    Reset A1
    Reset C
    Reset D
    Reset E
    Reset F
    
    Reset Ledzolta
    Reset Ledmieszanie
    Reset Ledgrzanie
    Reset Ledgrzalki
    Reset Ledalarm
    Wait 1
    Set Ledzolta
    Set Ledmieszanie
    Set Ledgrzanie
    Set Ledgrzalki
    Set Ledalarm
    
    Wait 1
    
    Do
    
    Reset Ledzolta
    
    If F = 80 Then
       Reset F
       Odczyt:
       1wreset
       1wwrite &HCC
       1wwrite &H44
    
       Wait 1
    
       1wreset
       1wwrite &HCC
       1wwrite &HBE
    
       Zmienna_temp(1) = 1wread(8)
       C3 = Zmienna_temp(1) And 1
    
       If C3 = 1 Then Decr Zmienna_temp(1)
    
       Temp = Makeint(zmienna_temp(1) , Zmienna_temp(2))
       Temp = Temp * 50 : Temp = Temp - 25
       C3 = Zmienna_temp(8) - Zmienna_temp(7) : C3 = C3 * 100
       C3 = C3 / Zmienna_temp(8) : Temp = Temp + C3
       Temp = Temp / 10
    End If
    
    If Mieszanie = 0 And A1 = 0 Then
       Set A1
       Reset Ledmieszanie
       Pk1:
       If Mieszanie = 0 Then Goto Pk1
    End If
    
    If Mieszanie = 0 And A1 = 1 Then
       Reset A1
       Set Ledmieszanie
       Pk2:
       If Mieszanie = 0 Then Goto Pk2
    End If
    
    If Grzanie = 0 And C = 0 Then
       Set C
       Reset Ledgrzanie
       Pk3:
       If Grzanie = 0 Then Goto Pk3
    End If
    
    If Grzanie = 0 And C = 1 Then
       Reset C
       Set Ledgrzanie
       Pk4:
       If Grzanie = 0 Then Goto Pk4
    End If
    
    If C = 1 And Temp <= 470 And D = 0 Then
       Set D
       Reset Ledgrzalki
       Set Wyj3
    End If
    
    If C = 1 And Temp = 500 And D = 1then
       Reset D
       Set Ledgrzalki
       Reset Wyj3
    End If
    
    If C = 0 Then
       Reset D
       Set Ledgrzalki
       Reset Wyj3
    End If
    
    If A1 = 1 Then
       If E = 1 Then Set Wyj1
       If E < 81 Then Incr E
       If E > 81 And E < 162 Then Incr E
    
       While E = 81
          Reset Wyj1
          Wait 2
          Incr E
          Set Wyj2
       Wend
    
       While E = 162
          Reset Wyj2
          Wait 2
          E = 1
          Set Wyj1         'po wyłączeniu wyj2 wyj1 nie włącza się tylko dlaczego ?
       Wend
    
       Else
       Reset Wyj1
       Reset Wyj2
       E = 0
    End If
    
    If Temp > 540 Then Reset Ledalarm
    
    If Temp < 540 Then Set Ledalarm
    
    Incr F
    
    Waitms 100
    
    Loop
    
    End


    a i coś z temperaturą też świruje bo ledalarm się zapala przy temp pokojowej (rezystor 4,7k do plusa jest)

    Pozdrawiam
  • #4
    M. S.
    Level 34  
    Jeszcze raz powtórzę apel zumka "ZAPOMNIJ i GOTO". Zastosować możesz jeszcze GOSUB. Chodzi o to, żeby program po wykonaniu skoku wrócił w to samo miejsce (Return) i opróżnił stos.
    Co do termometru to napisz osobno program odczytujący DS'a. Jak go dopracujesz to wstaw go do programu docelowego najlepiej jako podprogram. Zobacz jeszcze obsługę DS'a w przykładach dołączonych do Bascoma.
  • #5
    Elektrooonik
    Level 29  
    Ja również odradzam stosowanie GOTO, nie wiem czy w bascomie jest jakiś bug ale kiedys nawet proste programy z tymi instrukcjami nie chciały mi działać prawidłowo.
  • #6
    omen_s
    Level 19  
    Ale w tym ostatnim kodzie który zamieściłem nie ma już żadnego goto
  • #7
    Elektrooonik
    Level 29  
    Na pewno? ja widze:
    
    
    If Mieszanie = 0 And A1 = 1 Then
       Reset A1
       Set Ledmieszanie
       Pk2:
       If Mieszanie = 0 Then Goto Pk2
    End If
    
    If Grzanie = 0 And C = 0 Then
       Set C
       Reset Ledgrzanie
       Pk3:
       If Grzanie = 0 Then Goto Pk3
    End If
    
    If Grzanie = 0 And C = 1 Then
       Reset C
       Set Ledgrzanie
       Pk4:
       If Grzanie = 0 Then Goto Pk4
    End If 
    

    zrezygnuj ze skoków na rzecz procedur
  • #8
    omen_s
    Level 19  
    hehe no racja nie widziałem tego ;)
    aktualna wersja :
    Config 1wire = P1.0
    
    Reset P1
    Set P1.7
    Set P1.6
    Set P3
    
    Ledzolta Alias P3.0
    Ledmieszanie Alias P3.1
    Ledgrzanie Alias P3.2
    Ledgrzalki Alias P3.4
    Ledalarm Alias P3.5
    Mieszanie Alias P1.6
    Grzanie Alias P1.7
    Wyj1 Alias P1.4
    Wyj2 Alias P1.3
    Wyj3 Alias P1.2
    
    Reset Wyj1
    Reset Wyj2
    Reset Wyj3
    
    Dim A1 As Bit
    Dim C As Bit
    Dim D As Bit
    Dim E As Integer
    Dim F As Integer
    Dim Temp As Integer
    Dim C3 As Integer
    Dim Zmienna_temp(8) As Byte
    
    Reset A1
    Reset C
    Reset D
    Reset E
    Reset F
    
    Reset Ledzolta
    Reset Ledmieszanie
    Reset Ledgrzanie
    Reset Ledgrzalki
    Reset Ledalarm
    Wait 1
    Set Ledzolta
    Set Ledmieszanie
    Set Ledgrzanie
    Set Ledgrzalki
    Set Ledalarm
    
    Wait 1
    
    Do
    
    Reset Ledzolta
    
    While F = 100
       Reset F
    
    '   1wreset
    '   1wwrite &HCC
    '   1wwrite &H44
    '
    '   Wait 1
    '
    '   1wreset
    '   1wwrite &HCC
    '   1wwrite &HBE
    '
    '   Zmienna_temp(1) = 1wread(8)
    '   C3 = Zmienna_temp(1) And 1
    '
    '   If C3 = 1 Then Decr Zmienna_temp(1)
    '
    '   Temp = Makeint(zmienna_temp(1) , Zmienna_temp(2))
    '   Temp = Temp * 50 : Temp = Temp - 25
    '   C3 = Zmienna_temp(8) - Zmienna_temp(7) : C3 = C3 * 100
    '   C3 = C3 / Zmienna_temp(8) : Temp = Temp + C3
    '   Temp = Temp / 10
    
    Exit While
    Wend
    
    While Mieszanie = 0 And A1 = 0
       Set A1
       Reset Ledmieszanie
       Bitwait Mieszanie , Set
    Wend
    
    While Mieszanie = 0 And A1 = 1
       Reset A1
       Set Ledmieszanie
       Bitwait Mieszanie , Set
    Wend
    
    While Grzanie = 0 And C = 0
       Set C
       Reset Ledgrzanie
       Bitwait Grzanie , Set
    Wend
    
    While Grzanie = 0 And C = 1
       Reset C
       Set Ledgrzanie
       Bitwait Grzanie , Set
    Wend
    
    While C = 1 And Temp <= 470 And D = 0
       Set D
       Reset Ledgrzalki
       Set Wyj3
    Wend
    
    While C = 1 And Temp = 500 And D = 1
       Reset D
       Set Ledgrzalki
       Reset Wyj3
    Wend
    
    While C = 0
       Reset D
       Set Ledgrzalki
       Reset Wyj3
       Exit While
    Wend
    
    If A1 = 1 Then
    
       If E >= 1 And E < 81 Then Set Wyj1
       If E > 81 And E < 162 Then Set Wyj2
       If E < 81 Then Incr E
       If E > 81 And E < 162 Then Incr E
    
       Else
       Reset Wyj1
       Reset Wyj2
    
    End If
    
    While E = 81
       Reset Wyj1
       Wait 2
       Incr E
       Set Wyj2
    Wend
    
    While E = 162
       Reset Wyj2
       Wait 2
       E = 1
       Set Wyj1
    Wend
    
    While Temp > 540 And Ledalarm = 1
       Reset Ledalarm
    Wend
    
    While Temp < 520 And Ledalarm = 0
       Set Ledalarm
    Wend
    
    Incr F
    
    Waitms 100
    
    Loop
    
    End


    teraz jak mam włączone grzanie to przy mieszaniu nie działa wyj1 :( (procedura odczytu ds'a jest na razie wyłączona)