Zegar w BASCOMIE z użyciem Timera

0

Witam, napisałem program minutnik w BASCOMIE na mikroukłady. Mam taki problem, że mogę ustawić minutnik ale jak już wszytko ustawię i uruchomię odliczanie to czas w ogóle nie jest zmniejszany. Problem z procedurą zmniejszającą (nie sądzę, bo używałem jej w minutniku bez timera) czy może jej wywołaniem, a może coś innego. Program testowany w symulatorze, nie sugeruje się wyświetlaczem tylko samym monitorem zmiennych. Z góry dziękuje z pomoc, pozdrawiam.

$regfile = "m128def.dat"
$crystal = 16000000
$sim

Dim M As Byte
Dim S As Byte
Dim Key As Byte

Declare Sub Set_time
Declare Sub Display_time

Config Timer1 = Timer , Prescale = 256
On Timer1 On_sec

Config Kbd = Portc

Ddrb = &B0011111
Portb = &B1101111

Key_start Alias Pinb.6
Key_set Alias Pinb.7
Gong Alias Portb.5

Enable Interrupts

Cls

Do
   Key = Getkbd()
   If Key = 3 Then Call Set_time
   If Key = 7 Then
   'If Key_set = 0 Then Call Set_time
   'If Key_start = 0 Then
      Load Timer1 , 62500
      Enable Timer1
   End If
Loop
End                                                         'end program

Sub Set_time
   Incr S
   If S >= 59 Then
      M = 1
      S = 0
      If M >= 30 Then M = 0
      Call Display_time
      Waitms 400
   End If
End Sub

Sub Display_time
   Locate 1 , 1
   If M < 10 Then : Lcd "0" : End If : Lcd M ; ":"
   If S < 10 Then : Lcd "0" : End If : Lcd S ;
End Sub

On_sec:
Do
   Disable Timer1
   If S = 0 Then
      If M = 0 Then
         Exit Do
      Else
         S = 59
         Decr M
      End If
   End If
   Decr S
   Enable Timer1
Loop
Return
 
0

Och, ciężkie życie, znowu sam doszedłem do problemu. Poza małymi niedociągnięciami w samym działaniu programu to problemem było to, że przy załadowaniu Timera musiałem przejść do jego procedury "goto on_sec", w tutorialach tego nie było ale bez tego wgl ta procedura nie była uruchamiana. Podaje kod, może się przydać.

$regfile = "m128def.dat"
$crystal = 16000000
$sim

Dim M As Byte
Dim S As Byte
Dim Key As Byte

Declare Sub Set_time
Declare Sub Display_time

Config Timer1 = Timer , Prescale = 256
On Timer1 On_sec

Config Kbd = Portc

Ddrb = &B0011111
Portb = &B1101111

Key_start Alias Pinb.6
Key_set Alias Pinb.7
Gong Alias Portb.5

Enable Interrupts

Cls

Locate 2 , 1
Lcd "Minutnik - Timer"

Do
   Key = Getkbd()
   If Key = 3 Then Call Set_time
   If Key = 7 Then
   'If Key_set = 0 Then Call Set_time
   'If Key_start = 0 Then
      Gosub On_sec
      Load Timer1 , 62500
      Enable Timer1
   End If
Loop
End                                                         'end program

Sub Set_time
   Incr S
   If S >= 59 Then
      Incr M
      S = 0
      If M >= 30 Then M = 0
      Waitms 400
   End If
   Call Display_time
End Sub

Sub Display_time
   Locate 1 , 1
   If M < 10 Then : Lcd "0" : End If : Lcd M ; ":"
   If S < 10 Then : Lcd "0" : End If : Lcd S ;
End Sub

On_sec:
Do
   Disable Timer1
   If S = 0 Then
      If M = 0 Then
         Exit Do
         Gong = 1
      Else
         S = 59
         Decr M
      End If
   End If
   Decr S
   Call Display_time
   Enable Timer1
Loop
Return

POPRAWIONY 20-10-2012

1 użytkowników online, w tym zalogowanych: 0, gości: 1