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

Zegarek z programem na timerze wyłącza się po 4 minutach - co poprawić?

rekinisko 29 Wrz 2007 19:53 1491 3
REKLAMA
  • #1 4332599
    rekinisko
    Poziom 22  
    Posty: 852
    Pomógł: 42
    Ocena: 142
    Napisałem sobie taki prosty programik, dodam, że to jeden z moich pierwszych z użyciem timera i niby wszystko ok to jednak zegarek przestaje wyświetlać po ok 4 minutach poprawnej pracy.

    $regfile = "m8def.dat"
    $crystal = 8000000
    Config Lcd = 20 * 2
    Config Lcdpin = Pin , Db4 = Portb.1 , Db5 = Portb.2 , Db6 = Portd.5 , Db7 = Portd.6 , E = Portd.7 , Rs = Portb.0
    Cursor Off
    Cls
    
    Config Timer0 = Timer , Prescale = 256
    Timer0 = 6
    
    Enable Interrupts
    Enable Timer0
    Start Timer0
    
    On Timer0 Przepelnil
    
    Dim Zlicz_przep As Word
    Dim Sekunda As Byte
    Dim Minuta As Byte
    Dim Godz As Byte
    
    Godz = 19
    Minuta = 22
    
    
    Do
    
    If Minuta = 60 Then
    Minuta = 0
    Incr Godz
    End If
    
    If Godz = 24 Then
    Godz = 0
    End If
    
    Locate 1 , 1
    Lcd " " ; Godz ; ":" ; Minuta ; ":" ; Sekunda
    Loop
    
    End
    
    Przepelnil:
    Incr Zlicz_przep
    Timer0 = 6
    
    If Zlicz_przep = 125 Then
    Zlicz_przep = 0
    Incr Sekunda
    End If
    
    If Sekunda = 60 Then
    Cls
    Sekunda = 0
    Incr Minuta
    End If
    
    Return
  • REKLAMA
  • #2 4332667
    M. S.
    Poziom 34  
    Posty: 2107
    Pomógł: 259
    Ocena: 680
    $regfile = "m8def.dat"
    $crystal = 8000000
    Config Lcd = 20 * 2
    Config Lcdpin = Pin , Db4 = Portb.1 , Db5 = Portb.2 , Db6 = Portd.5 , Db7 = Portd.6 , E = Portd.7 , Rs = Portb.0
    Cursor Off
    Cls
    
    Config Timer0 = Timer , Prescale = 256
    Timer0 = 6
    
    Enable Interrupts
    Enable Timer0
    Start Timer0
    
    On Timer0 Przepelnil
    
    Dim Zlicz_przep As Word
    Dim Sekunda As Byte
    Dim Minuta As Byte
    Dim Godz As Byte
    
    Godz = 19
    Minuta = 22
    
    
    Do
    
    If Zlicz_przep = 125 Then
    Zlicz_przep = 0
    Incr Sekunda
    End If
    
    If Sekunda = 60 Then
    Cls
    Sekunda = 0
    Incr Minuta
    End If
    
    If Minuta = 60 Then
    Minuta = 0
    Incr Godz
    End If
    
    If Godz = 24 Then
    Godz = 0
    End If
    
    Locate 1 , 1
    Lcd " " ; Godz ; ":" ; Minuta ; ":" ; Sekunda
    Loop
    
    End
    
    Przepelnil:
    Incr Zlicz_przep
    Timer0 = 6
    Return


    W przerwaniu rób tylko tyle ile jest konieczne.
    Użyj 16 bitowego Timera1. Wtedy przerwania nie wystąpią tak często i uC będzie miał czas zająć się pętlą główną.
  • REKLAMA
  • #3 4332783
    rekinisko
    Poziom 22  
    Posty: 852
    Pomógł: 42
    Ocena: 142
    No ja tez tak robiłem wcześniej i nawet sekundnik nie chce ruszyć, w momencie kiedy przerzucam ten kawałek do pętli główne a przeciez powinno działać, wrzucam to w do ... loop i kicha:
    If Zlicz_przep = 125 Then 
    Zlicz_przep = 0 
    Incr Sekunda 
    End If 

    A jak myślisz, dobrze policzyłem 1s na tym timerze?

    PS. Wiem, że tak nie powinno być to napisane jak niżej bo to marnuje czas ale przestawiłem i nie wiesza:

    $regfile = "m8def.dat"
    $crystal = 8000000
    Config Lcd = 20 * 2
    Config Lcdpin = Pin , Db4 = Portb.1 , Db5 = Portb.2 , Db6 = Portd.5 , Db7 = Portd.6 , E = 
    
    Portd.7 , Rs = Portb.0
    Cursor Off
    Cls
    
    Config Timer0 = Timer , Prescale = 256
    Timer0 = 6
    
    Enable Interrupts
    Enable Timer0
    Start Timer0
    
    On Timer0 Przepelnil
    
    Config Pinc.3 = Input
    Dim Zlicz_przep As Word
    Dim Sekunda As Byte
    Dim Minuta As Byte
    Dim Godz As Byte
    
    Godz = 20
    Minuta = 17
    
    Do
    
    'If Pinc.3 = 1 Then
    'Incr Minuta
    'End If
    
    If Sekunda = 60 Then
    Cls
    Sekunda = 0
    Incr Minuta
    End If
    
    If Minuta = 60 Then
    Cls
    Minuta = 0
    Incr Godz
    End If
    
    If Godz = 24 Then
    Cls
    Godz = 0
    End If
    
    Locate 1 , 1
    Lcd " " ; Godz ; ":" ; Minuta ; ":" ; Sekunda
    Loop
    
    End
    
    Przepelnil:
    Incr Zlicz_przep
    Timer0 = 6
    
    If Zlicz_przep = 125 Then
    Zlicz_przep = 0
    Incr Sekunda
    End If
    
    Return


    Co zrobić aby było tak jak zaproponowałeś wcześniej? Nie rozumiem dlaczego nie działa, powinno.
  • Pomocny post
    #4 4333089
    M. S.
    Poziom 34  
    Posty: 2107
    Pomógł: 259
    Ocena: 680
    Zostaw tak jak jest. Być może, że timerek zgłosi kolejne przerwanie zanim uC sprawdzi warunek
    If Zlicz_przep = 125 Then
    Zlicz_przep = 0
    Incr Sekunda
    End If 

    w pętli głównej

    Jak się upierasz to spróbuj tak:
    If Zlicz_przep >= 125 Then
    Zlicz_przep = Zlicz_przep - 125
    Incr Sekunda
    End If 
REKLAMA