atmega8 program nepracuje spravne
Moderátor: Moderátoři
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
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 = 1Pak 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...
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
Endchyby 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 = 0Kó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
EndKód: Vybrat vše
If Portb.0 = 0 And Portb.1 = 0 And Portb.2 = 0 And Portb.3 = 0 ThenAk 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 Theneš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 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
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 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]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
Enda funguje to ako ma
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.
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