Stopky v Bascom, kam vložit reset stopek

Zdarvím, jsem začítečník, kam do programu vložit podpogram pro vynulování stopek tačítkem a jak zabezpečit aby bylo tlačítko aktivní pouze při doběhnutí stopek? Děkuji za vaše návrhy.

[code]
$regfile = M8def.dat
$crystal = 4096000

Dim _ssec As Byte
Dim _sec As Byte
Dim S_ssec As String * 2
Dim S_sec As String * 3
Dim _start_stop As Bit
Dim S As String * 5

Config Lcdpin = Pin , Db4 = Portd.7 , Db5 = Portb.0 , Db6 = Portd.5 , Db7 = Portd.6 , E = Portd.2 , Rs = Portd.0 'Konfigurace pinu* LCD
Config Pinc.3 = Input
Config Pinc.3 = Input
Config Pinc.4 = Input
Enable Interrupts

Config Timer1 = Timer , Prescale = 256
On Ovf1 Tim1_isr
Enable Timer1
Tcnt1h = 255
Tcnt1l = 96
Start Timer1

_start_stop = 0
Cls
Locate 1 , 5
Lcd “CASOMIRA”
Lowerline
Cursor Off
Wait 2
Cls

Do
Locate 1 , 6
Lcd Str(_sec)
Locate 1 , 9
Lcd “.”
Locate 1 , 10
Lcd Str(_ssec)
Locate 2 , 1
Lcd “”
Locate 2 , 1
Lcd “START STOP RESET”

Loop

Tim1_isr:
Tcnt1h = 255
Tcnt1l = 96

If Pinc.3 = 0 Then 'kdyz Je Zmacknuto Startovaci Tlacitko , Zapis 1 Na Start_stop
_start_stop = 1
End If

If Pinc.4 = 0 Then 'Jsou Spadnute Terce , Zapis 0 Na Start_stop
_start_stop = 0
End If

If _start_stop = 1 Then 'Kdyz Je _start_stop 1 Pricti 1setinu Sekundy
_ssec = _ssec + 1
End If

If _ssec >= 100 Then 'Kdyz Je 100 Setin Sekundy , Vynuluj _s_sec A Pricti 1 _sec
_ssec = 0
_sec = _sec + 1
End If

Return

End[/code]

Tak sem si pomohl nakonec sám, vím vypadá to hrozně ale funguje to… Kdyby jste měl nědo nápad jak to řešit elegantněji sem s ním :slight_smile:

[code]$regfile = M8def.dat
$crystal = 4096000

Dim _ssec As Byte
Dim _sec As Byte
Dim _start_stop As Bit

Config Lcdpin = Pin , Db4 = Portd.7 , Db5 = Portb.0 , Db6 = Portd.5 , Db7 = Portd.6 , E = Portd.2 , Rs = Portd.0 'Konfigurace pinu* LCD
Config Pinc.3 = Input
Config Pinc.4 = Input
Config Pinc.5 = Input

_start:
If Pinc.5 = 0 Then
Goto _start
End If

Enable Interrupts
Config Timer1 = Timer , Prescale = 256
On Ovf1 Tim1_isr
Enable Timer1
Tcnt1h = 255
Tcnt1l = 96
Start Timer1
_start_stop = 0

Cls
Locate 1 , 4
Lcd “Fire Sport”
Lowerline
Cursor Off
Wait 2
Cls

Do
Locate 1 , 6
Lcd Str(_sec)
Locate 1 , 9
Lcd “.”
Locate 1 , 10
Lcd Str(_ssec)
Locate 2 , 1
Lcd “”
Locate 2 , 1
Lcd “START STOP RESET”

Loop
Tim1_isr:
Tcnt1h = 255
Tcnt1l = 96

If Pinc.3 = 0 Then 'kdyz Je Zmacknuto Startovaci Tlacitko , Zapis 1 Na Start_stop
_start_stop = 1
End If

If Pinc.4 = 0 Then 'Jsou Spadnute Terce , Zapis 0 Na Start_stop
_start_stop = 0
End If

If _start_stop = 0 Then 'kdyz jspu stopky zastveny
If Pinc.5 = 0 Then 'tlacitko reset sepnuto
If _ssec > 0 Then
If _sec > 0 Then 'setiny seknd nejsou vynulovany
_ssec = 0 'vynuluj setiny sekund
_sec = 0 'sekundy
Goto _start 'a jdi na start
End If
End If
End If
End If

If _start_stop = 1 Then 'Kdyz Je _start_stop 1 Pricti 1setinu Sekundy
_ssec = _ssec + 1
End If

If _ssec >= 100 Then 'Kdyz Je 100 Setin Sekundy , Vynuluj _s_sec A Pricti 1 _sec
_ssec = 0
_sec = _sec + 1
End If
Return

End[/code]

V programování AVR jsem taky začátečník, ale v basicu jako takovém nějaké zkušenosti mám. Já osobně bych to udělal takto:

Někam do hlavní smyčky bych vložil:

if _start_stop = 0 and Pinc.5 = 0 Then gosub Reset

Pokud jsou stopky zastaveny a současně je stisknuto tlačítko reset, jdi do podprogramu “Reset”

A do podprogramu nulování bych dal vlastní fyzický reset

Sub reset _sec = 0 _ssec = 0 Return