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

Atmega16 zawiesza się, uC, kod programu, co jest źle?

xŁolesxxx 23 Maj 2008 22:35 2064 3
REKLAMA
  • #1 5173820
    xŁolesxxx
    Poziom 14  
    Witam mam pewien problem z atmegą, otóż program składa się z zwykłej pętli w której wykonywane są pewne operacje a druga to przerwanie co sekundę od timer'a1, Instrukcje w pętli co jakiś czas się zawiesza i w ogóle nie są wykonywane podczas gdy instrukcje przerwania od timera są wykonywane bez problemu, uC zaczyna pracować poprawnie dopiero po restarcie. W przerwaniu co sekundę zawarta jest obsługa wyświetlacza lcd alfanumeryczego i zliczanie czasu dlatego wiem że ta część pracuje podczas gdy che nacisnąć guzik którego obsługa zawarta jest w pętli to niestety nie reaguje, dałem również wathdoga do programu a w pętli dałem instrukcje resetowania licznika wathdog, i co pewien czas uC się resetuje.
  • REKLAMA
  • #2 5173841
    don diego
    Poziom 32  
    Może byś program pokazał. Nie będzie trzeba wróżki wołać:)
  • REKLAMA
  • #3 5174001
    xŁolesxxx
    Poziom 14  
    Oto i on

    
        Config Portc = &B00000000
                Portc = &B11111111
    
           Config Portd = &B11111111
               Portd = &B1001100
    
          Config Watchdog = 2048
     Config Adc = Single , Prescaler = Auto , Reference = Internal
     Config Timer1 = Timer , Prescale = 64 
    
    Dim Formatowany1 As String *
    Dim Wart_ac As Word
    Dim V As Single
    Dim Pomp As Bit
    Dim Grz As Bit
    Dim Pomp1 As Bit
    Dim Grz1 As Bit
    Dim Stan As Bit
    Dim T As Byte
    Dim Sek As Byte
    Dim Minut As Byte
    Dim Ts As Bit
    Dim Z As Bit
    Dim Gl As Byte
    Dim Zab As Byte
    Dim Pgl As Byte
    
        Pgl = 10
        Gl = 76
        Ts = 0
        Minut = 0
        Sek = 0
        T = 10
        Pomp = 0
        Grz = 0
        Pomp1 = 0
        Grz1 = 0
        Stan = 1
        Z = 0
    
    Enable Interrupts
    Enable Timer1
    
    On Timer1 Co1s
    Timer1 = 3036
    
    
    Start Adc
       Cls
       Lcd "WYTRAWIARKA"
    
    
    
    Deflcdchar 1 , 32 , 32 , 30 , 31 , 30 , 18 , 18 , 32
    Deflcdchar 2 , 32 , 32 , 32 , 14 , 10 , 27 , 32 , 32
    Deflcdchar 3 , 3 , 3 , 32 , 12 , 18 , 16 , 18 , 12
    Deflcdchar 4 , 32 , 32 , 1 , 2 , 20 , 8 , 32 , 32
    Deflcdchar 5 , 32 , 32 , 17 , 10 , 4 , 10 , 17 , 32
     
    Start Watchdog
    Do
    
    Reset Watchdog
    
              If Portd.0 = 1 Then
                Portd.4 = 1
              Else
                Portd.4 = 0
              End If
    
    
              If Portd.1 = 1 Then
                Portd.5 = 1
              Else
                Portd.5 = 0
              End If
    
    
              If Gl < 76 Then
                Gl = Gl + 1
                Toggle Portd.3
               End If
    
               If Gl = 76 Then
                 Gl = Gl + 1
                  Portd.3 = 1
              End If
    
              If Pomp1 = Pomp And Grz1 = Grz Then
                Stan = 1
              End If
    
    
              If Pomp1 <> Pomp Or Grz1 <> Grz Then
                Stan = 0
              End If
    
    
    
          If Z = 1 Then
                 Z = 0
                 Gl = 60
                 Formatowany1 = Fusing(v , "#.#")
                 Cls
                 Lcd Chr(3)
                 Lcd Formatowany1
                 Lcd " T "
                 Lcd Minut
                 Lcd ":"
                 Lcd Sek
    
               Lowerline
    
               If Stan = 1 Then
                 Lcd Chr(4)
               Else
                 Lcd Chr(5)
               End If
                 Lcd " "
                 Lcd Chr(1)
                 Lcd Pomp
                 Lcd " "
                 Lcd Chr(2)
                 Lcd Grz
    
                 Lcd " czas:"
                 Lcd T
          End If
    
    
     Wart_ac = Getadc(0)
     V = Wart_ac * 0.252
    
            Debounce Pinc.4 , 0 , Dul , Sub
            Debounce Pinc.3 , 0 , Gura , Sub
            Debounce Pinc.2 , 0 , Enter , Sub
            Debounce Pinc.1 , 0 , Pomp , Sub
            Debounce Pinc.0 , 0 , Grz , Sub
    
    Loop
     End
    
    Co1s:
           Timer1 = 3036
          
            Zab = V
    
           If Zab > 38 Then
                 Grz = 0
                 Grz1 = 0
                 Portd.1 = 0
           End If
    
    
            If Pgl < 10 Then
               Gl = 0
               Pgl = Pgl + 1
           End If
    
    
           If Ts = 1 Then
              Sek = Sek + 1
    
              If Sek = 60then
                 Sek = 0
                 Minut = Minut + 1
    
              End If
    
            End If
    
    
                If Zab > 40 Then
                  Gl = 0
                End If
    
    
                  Formatowany1 = Fusing(v , "#.#")
                  Cls
    
        Lcd Chr(3)
        Lcd Formatowany1
    
        Lcd " T "
        Lcd Minut
        Lcd ":"
        Lcd Sek
    
    
       Lowerline
        If Stan = 1 Then
           Lcd Chr(4)
        End If
        If Stan = 0 Then
            Lcd Chr(5)
        End If
    
    
          Lcd " "
          Lcd Chr(1)
          Lcd Pomp
            Lcd " "
          Lcd Chr(2)
          Lcd Grz
    
          Lcd " czas:"
          Lcd T
    
    
             If Minut >= T Then
                 Pomp1 = 0
                 Grz1 = 0
                 Pomp = 0
                 Grz = 0
                 Ts = 0
                 Minut = 0
                 Sek = 0
                 Pgl = 0
    
                 Portd.0 = 0
                 Portd.1 = 0
            End If
    
    
     Return
    
    Enter:
            Pomp1 = Pomp
            Grz1 = Grz
    
    
              If Pomp1 = 0 Then
                Portd.0 = 0
              Else
                Portd.0 = 1
              End If
    
    
               If Grz1 = 0 Then
                 Portd.1 = 0
               Else
                 Portd.1 = 1
               End If
    
                    Ts = 1
                    Z = 1
    Return
    
    
    Pomp:
             If Pomp = 0 Then
                Pomp = 1
                Z = 1
       Return
              End If
    
    
             If Pomp = 1 Then
                Pomp = 0
                Z = 1
       Return
             End If
    
    Return
    
    
    
    Grz:
                   If Grz = 0 Then
                          Grz = 1
                          Z = 1
       Return
                   End If
    
    
                 If Grz = 1 Then
                   Grz = 0  
                   Z = 1
       Return
                 End If
    
    Return
    
    Dul:
              Ts = 0
              Minut = 0
              Sek = 0
    
             T = T - 1
    
           If T = 0 Then
             T = 1
           End If
    
            Z = 1
    
    
    Return
    
    
    Gura:
             Ts = 0
             Minut = 0
             Sek = 0
    
             T = T + 1
            
    
           If T > 30 Then
             T = 30
           End If
    
            Z = 1
    Return
    
  • #4 5175035
    Ch.M.
    Poziom 27  
    OMG człowieku popraw te ortografy w kodzie! Jak już stosujesz nazewnictwo ang. to się tego trzymaj a nie mieszasz. Przeedytuj kod usuwając puste linie.
    Warto by było trzyma się regulaminu tego subforum i w temacie tagi zastosowac.
REKLAMA