Stránka 2 z 3
Napsal: 06 pro 2014, 19:54
od procesor
Nie !!!
Vyššie som popísal ako tie nuly písať.
Na začiatku to môže byť tiež, ale by tam musela byť podmienka (test) iba pre pípad, že je stlačené niektoré tlačítko.
if Porc.0 AND Portc.1 AND.........AND Portc.3=0
porb.x=0
..
.
.
.
portc.x=0
endif
a tu tie pôvodné
if
.
.
.endif
if
.
.
.
endif
loop
end
Napsal: 06 pro 2014, 19:56
od mato1168
Ok upravim to a odskusam a keby nieco este sem napisem zatial dakujem
Napsal: 06 pro 2014, 20:16
od nekmil
Pokud na vstupním pinu nemáš připojen fyzický odpor nebo nemáš zapnutý vnitřní "pull up" , na tomto pinu bude furt 0 bez ohledu na to jestli je tlačítko stlačeno či nikoli.
Napsal: 06 pro 2014, 20:16
od Ruprecht
Nějak v tomprogramu nevidím, že by se aktivivaly pull-up odpory. Jakpak se tedy na vstup (od přizemněného tlačítka) dostane log.1/+5V?
Definice vstupů Config Portb.0 = Input je správně, interní pull-up (tedy 5V na vstupu s nezmáčknutým tlačítkem) se aktivuje Portb.0 = 1
Prostě ty řádky s definicí vstupů oprav na
Kód: Vybrat vše
Config Portb.0 = Input : Portb.0 = 1
Pak v klidu (žádné tlačítko není zmáčknuté=přizemněné) budou na vstupech log.1/5V, zmáčknuté tlačítko bude log.0, takže programově budeš testovat
if pinb.0 = 0 then...
Napsal: 06 pro 2014, 20:30
od mato1168
Testovat to budem asi az zajtra este som vonku a uz sa mi asi nebude chcet tak zajtra cez den upravim program a otestujem to zatial dakujem za rady
Napsal: 06 pro 2014, 21:48
od mato1168
upravil som ten program takto ale nejde skompilovat spravil som to tak ako som to pochopil z prispevku od procesor
Kód: Vybrat vše
$regfile = "m8def.dat"
$crystal = 4000000
$hwstack = 40
$swstack = 16
$framesize = 32
Config Portc.0 = Output 'hl.n biela
Config Portc.1 = Output 'hl.n cervena
Config Portc.2 = Output 'hl.n biela
Config Portc.3 = Output 'hl.n Z
Config Portd.0 = Output 'opakovacie biela
Config Portd.1 = Output 'opakovacie modra
Config Portd.2 = Output 'opakovacie biela
Config Portd.3 = Output 'opakovacie Z
Config Portb.0 = Input : Portb.0 = 1 'tlacit zakazane
Config Portb.1 = Input : Portb.1 = 1 'tlacit pomaly
Config Portb.2 = Input : Portb.2 = 1 'tlacit rychlejsie
Config Portb.3 = Input : Portb.3 = 1 'tlacit spat
Do
If Portb.0 And Portb.1 And Portb.2 And Portb.3 = 0 Then
Portc.0 = 0
Portc.1 = 0
Portc.2 = 0
Portc.3 = 0
Portd.0 = 0
Portd.1 = 0
Portd.2 = 0
Portd.3 = 0
End If
If Pinb.0 = 1 Then
Portc.1 = 1
Portd.1 = 1
End If
If Pinb.1 = 1 Then
Portc.0 = 1
Portc.2 = 1
Portd.0 = 1
Portd.2 = 1
End If
If Pinb.2 = 1 Then
Portc.0 = 1
Portd.0 = 1
End If
If Pinb.3 = 1 Then
Portc.1 = 1
Portc.3 = 1
Portd.1 = 1
Portd.3 = 1
End If
Loop
End
chyby to hlasi v prvom riadku za ,,do´´ nastavil som tam aj ten pullup ako pisal ruprecht
ked to dam bez tohto
Kód: Vybrat vše
If Portb.0 And Portb.1 And Portb.2 And Portb.3 = 0 Then
Portc.0 = 0
Portc.1 = 0
Portc.2 = 0
Portc.3 = 0
Portd.0 = 0
Portd.1 = 0
Portd.2 = 0
Portd.3 = 0
tak to skompiluje
Napsal: 06 pro 2014, 21:57
od procesor
Presne syntax neovládam.
Možno do zátvoriek treba ten logický súčin AND tlačítok.
Napsal: 06 pro 2014, 22:38
od mato1168
ako cele do zatvoriek myslis alebo ako?a keby to vypisem pod seba bez tych and to by mohlo ist takto
Kód: Vybrat vše
$regfile = "m8def.dat"
$crystal = 4000000
$hwstack = 40
$swstack = 16
$framesize = 32
Config Portc.0 = Output 'hl.n biela
Config Portc.1 = Output 'hl.n cervena
Config Portc.2 = Output 'hl.n biela
Config Portc.3 = Output 'hl.n Z
Config Portd.0 = Output 'opakovacie biela
Config Portd.1 = Output 'opakovacie modra
Config Portd.2 = Output 'opakovacie biela
Config Portd.3 = Output 'opakovacie Z
Config Portb.0 = Input : Portb.0 = 1 'tlacit zakazane
Config Portb.1 = Input : Portb.1 = 1 'tlacit pomaly
Config Portb.2 = Input : Portb.2 = 1 'tlacit rychlejsie
Config Portb.3 = Input : Portb.3 = 1 'tlacit spat
Do
If Pinb.0 = 0 Then
Portc.1 = 0
Portd.1 = 0
End If
If Pinb.1 = 0 Then
Portc.0 = 0
Portc.2 = 0
Portd.0 = 0
Portd.2 = 0
End If
If Pinb.2 = 0 Then
Portc.0 = 0
Portd.0 = 0
End If
If Pinb.3 = 0 Then
Portc.1 = 0
Portc.3 = 0
Portd.1 = 0
Portd.3 = 0
end if
If Pinb.0 = 1 Then
Portc.1 = 1
Portd.1 = 1
End If
If Pinb.1 = 1 Then
Portc.0 = 1
Portc.2 = 1
Portd.0 = 1
Portd.2 = 1
End If
If Pinb.2 = 1 Then
Portc.0 = 1
Portd.0 = 1
End If
If Pinb.3 = 1 Then
Portc.1 = 1
Portc.3 = 1
Portd.1 = 1
Portd.3 = 1
End If
Loop
End
Napsal: 06 pro 2014, 22:44
od Ruprecht
Ty ANDy mají vypadat takto
Kód: Vybrat vše
If Portb.0 = 0 And Portb.1 = 0 And Portb.2 = 0 And Portb.3 = 0 Then
ale úplně nechápu jejich smysl. To by nulovalo výstupy jen v případě zmáčknutí všech tlačítek najednou
Napsal: 06 pro 2014, 22:51
od procesor
Má to urobiť pri stlačení ktoréhokoľvek.
Ak ten zápis ANDu má byť ako píšeš potom ale má byť takto
Kód: Vybrat vše
If Portb.0 = 0 or Portb.1 = 0 or Portb.2 = 0 or Portb.3 = 0 Then
ešte by so skúsil či pozná syntax zátvorky ...potom by to bolo takto
Kód: Vybrat vše
If (Portb.0 And Portb.1 And Portb.2 And Portb.3) = 0 Then
Napsal: 06 pro 2014, 22:55
od Ruprecht
Nebo třeba takto?
Kód: Vybrat vše
$regfile = "m8def.dat"
$crystal = 4000000
$hwstack = 40
$swstack = 16
$framesize = 32
Config Portc.0 = Output 'hl.n biela
Config Portc.1 = Output 'hl.n cervena
Config Portc.2 = Output 'hl.n biela
Config Portc.3 = Output 'hl.n Z
Config Portd.0 = Output 'opakovacie biela
Config Portd.1 = Output 'opakovacie modra
Config Portd.2 = Output 'opakovacie biela
Config Portd.3 = Output 'opakovacie Z
Config Portb.0 = Input : Portb.0 = 1 'tlacit zakazane
Config Portb.1 = Input : Portb.1 = 1 'tlacit pomaly
Config Portb.2 = Input : Portb.2 = 1 'tlacit rychlejsie
Config Portb.3 = Input : Portb.3 = 1 'tlacit spat
Do
If Pinb.0 = 0 Then
Portc.1 = 1
Portd.1 = 1
Else
Gosub Zhasni
End If
'---------------------------------------------------------
If Pinb.1 = 0 Then
Portc.0 = 1
Portc.2 = 1
Portd.0 = 1
Portd.2 = 1
Else
Gosub Zhasni
End If
'---------------------------------------------------------
If Pinb.2 = 0 Then
Portc.0 = 1
Portd.0 = 1
Else
Gosub Zhasni
End If
'---------------------------------------------------------
If Pinb.3 = 0 Then
Portc.1 = 1
Portc.3 = 1
Portd.1 = 1
Portd.3 = 1
Else
Gosub Zhasni
End If
Loop
End
Zhasni:
Portc.0 = 0
Portc.1 = 0
Portc.2 = 0
Portc.3 = 0
Portd.0 = 0
Portd.1 = 0
Portd.2 = 0
Portd.3 = 0
Return
Držím tlačítko = svítí kombinace, pustím tlačítko, všecho zhasne
Napsal: 06 pro 2014, 22:58
od procesor
Nie ...
Gosub zhasni daj pred nastavenia portov do 1 a príkaz else netreba.
Kód: Vybrat vše
If Pinb.0 = 0 Then
Gosub Zhasni
Portc.1 = 1
Portd.1 = 1
End If
Toto vynuluje a hneď nastaví požadované LEDky.
Edit:
Tak som si nainštaloval bascom

a vyskúšal preložiť toto najjednoduchšie:
a neprotestuje sytax
Kód: Vybrat vše
.
.
Do
If Portb.0 = 0 Or Portb.1 = 0 Or Portb.2 = 0 Or Portb.3 = 0 Then
Portc.0 = 0
Portc.1 = 0
Portc.2 = 0
Portc.3 = 0
Portd.0 = 0
Portd.1 = 0
Portd.2 = 0
Portd.3 = 0
End If
.
.
[/b]
Napsal: 07 pro 2014, 00:11
od mato1168
spravil som to takto
Kód: Vybrat vše
$regfile = "m8def.dat"
$crystal = 4000000
$hwstack = 40
$swstack = 16
$framesize = 32
Config Portc.0 = Output 'hl.n biela
Config Portc.1 = Output 'hl.n cervena
Config Portc.2 = Output 'hl.n biela
Config Portc.3 = Output 'hl.n Z
Config Portd.0 = Output 'opakovacie biela
Config Portd.1 = Output 'opakovacie modra
Config Portd.2 = Output 'opakovacie biela
Config Portd.3 = Output 'opakovacie Z
Config Portb.0 = Input : Portb.0 = 1 'tlacit zakazane
Config Portb.1 = Input : Portb.1 = 1 'tlacit pomaly
Config Portb.2 = Input : Portb.2 = 1 'tlacit rychlejsie
Config Portb.3 = Input : Portb.3 = 1 'tlacit spat
Do
If Pinb.0 = 0 Then
Portc.1 = 1
Portd.1 = 1
End If
If Pinb.1 = 0 Then
Portc.0 = 1
Portc.2 = 1
Portd.0 = 1
Portd.2 = 1
End If
If Pinb.2 = 0 Then
Portc.0 = 1
Portd.0 = 1
End If
If Pinb.3 = 0 Then
Portc.1 = 1
Portc.3 = 1
Portd.1 = 1
Portd.3 = 1
End If
Loop
End
a funguje to ako ma
Napsal: 07 pro 2014, 00:19
od procesor
Nefunguje, postupne stlač všetky a bude ti svietiť všetko. Leda, že za každým stlačíš aj reset Tl.
Vyššie som doplnil kód s príkazmi OR a ide to skompilovať.
A robí to toto:
-po stlačení tlačidla (okamžite)sa rozsvieti príslušná kombinácia a svieti do stlačenia iného kódu.
-Reset tl. sa nemusí stláčať, iba ak je potreba zhasiť všetky LEDky.
Napsal: 07 pro 2014, 00:24
od mato1168
funguje mam tam reset tlacitko takze ked chcem zmenit kombinaciu tak ho stlacim a potom stlacim co potebujem to tvoje funguje tak ze ked stlacim inu kombinaciu tak automaticky zhasnu tie ledky ktore svietili ak som spravne pochopil
mne to vyhovuje takto kedze chcem dorobit este aby po stlaceni resetu sa rozsvietil zakladny stav tj tlacit zakazane to su dve ledky a bude tam o jedno tlacitko menej cize to bude fungovat tak ze po zapnuti sa rozsvieti zakladny stav a po stlaceni tlacitka sa rozsvieti prislusna kombinacia po stlaceni resetu sa do vrati naspet do zakladneho stavu