Bascom Programm

Gast #3022025
Ich habe eine Frage. Was ist an diesem Programm falsch ?

$regfile = "m8def.dat"
$crystal = 1000000

Ddrd = &B11111111
Portc = &B00011111

Do

If Pinc.0 = 0 Then

Portd = 1
Waitms 100
Portd = 3
Waitms 100
Portd = 7
Waitms 100
Portd = 15
Waitms 100
Portd = 31
Waitms 100
Portd = 63
Waitms 100
Portd = 127
Waitms 100
Portd = 255
Waitms 100
Portd = 254
Waitms 100
Portd = 252
Waitms 100
Portd = 248
Waitms 100
Portd = 240
Waitms 100
Portd = 224
Waitms 100
Portd = 192
Waitms 100
Portd = 128
Waitms 100
Portd = 0
Waitms 100
Portd = 128
Waitms 100
Portd = 192
Waitms 100
Portd = 224
Waitms 100
Portd = 240
Waitms 100
Portd = 248
Waitms 100
Portd = 252
Waitms 100
Portd = 254
Waitms 100
Portd = 255
Waitms 100
Portd = 127
Waitms 100
Portd = 63
Waitms 100
Portd = 31
Waitms 100
Portd = 15
Waitms 100
Portd = 7
Waitms 100
Portd = 3
Waitms 100
Portd = 1
Waitms 100
Portd = 0
Waitms 100

Else
If Pinc.1 = 0 Then

Portd = 129
Waitms 150
Portd = 195
Waitms 150
Portd = 231
Waitms 150
Portd = 255
Waitms 150
Portd = 126
Waitms 150
Portd = 60
Waitms 150
Portd = 24
Waitms 150
Portd = 0
Waitms 150

Else
If Pinc.2 = 0 Then

Portd = 1
Waitms 100
Portd = 3
Waitms 100
Portd = 7
Waitms 100
Portd = 15
Waitms 100
Portd = 31
Waitms 100
Portd = 63
Waitms 100
Portd = 127
Waitms 100
Portd = 255
Waitms 100
Portd = 254
Waitms 100
Portd = 252
Waitms 100
Portd = 248
Waitms 100
Portd = 240
Waitms 100
Portd = 224
Waitms 100
Portd = 192
Waitms 100
Portd = 128
Waitms 100
Portd = 0
Waitms 100

Else
If Pinc.3 = 0 Then

Portd = 129
Waitms 100
Portd = 66
Waitms 100
Portd = 36
Waitms 100
Portd = 24
Waitms 100
Portd = 36
Waitms 100
Portd = 66
Waitms 100

Else

Portd = 255
Wait 1
Portd = 0
Wait 1


End If

Loop




Entschuldigung, wenn ich im falschen Forum dafür bin
.

Danke im Vorraus !
Gast #3022045
Ja, damit stimmt was nicht. Sie nützen nichts bzw können nicht 
funktionieren weil du alle niederwertigen Bits von Port C als Ausgänge 
definierst und in deinen If then Abfragen als Eingänge behandelst.

Das passt nicht.
#3022142
Hoi

Du musst nach jedem "If" Befehl auch wieder "End If" schreiben und nicht 
einmal erst am Ende.
Mit "If" sagst du dem mC das er jetzt etwas prüfen/vergleichen/rechnen 
soll, damit der mC auch weiss wann diese Anwendung fertig ist, muss ein 
"End If" nach dem letzten Befehl hinein.

Dein Aufbau des Code würde ich auch einmal etwas Ordnen.

Gruss Philippe
Gast #3022163
Du musst das ELSEIF in einem Wort schreiben siehe BASCOM-Hilfe:

IF expression THEN
[ ELSEIF expression THEN ]
[ ELSE ]
END IF

Ports sind defaultmäßig Eingang aber man sieht hier, dass es besser wäre 
explizit zu schreiben:
PortC=Input  oder DDRC=&b00000000

Du solltest außerdem immer Stackangaben im Programm schreiben
Gast #3022181
$regfile = "m8def.dat"
$crystal = 1000000

Ddrd = &B11111111
Portc = &B00011111

Do

If Pinc.0 = 0 Then

Portd = 1
Waitms 100
Portd = 3
Waitms 100
Portd = 7
Waitms 100
Portd = 15
Waitms 100
Portd = 31
Waitms 100
Portd = 63
Waitms 100
Portd = 127
Waitms 100
Portd = 255
Waitms 100
Portd = 254
Waitms 100
Portd = 252
Waitms 100
Portd = 248
Waitms 100
Portd = 240
Waitms 100
Portd = 224
Waitms 100
Portd = 192
Waitms 100
Portd = 128
Waitms 100
Portd = 0
Waitms 100
Portd = 128
Waitms 100
Portd = 192
Waitms 100
Portd = 224
Waitms 100
Portd = 240
Waitms 100
Portd = 248
Waitms 100
Portd = 252
Waitms 100
Portd = 254
Waitms 100
Portd = 255
Waitms 100
Portd = 127
Waitms 100
Portd = 63
Waitms 100
Portd = 31
Waitms 100
Portd = 15
Waitms 100
Portd = 7
Waitms 100
Portd = 3
Waitms 100
Portd = 1
Waitms 100
Portd = 0
Waitms 100

Else
If Pinc.1 = 0 Then

Portd = 129
Waitms 150
Portd = 195
Waitms 150
Portd = 231
Waitms 150
Portd = 255
Waitms 150
Portd = 126
Waitms 150
Portd = 60
Waitms 150
Portd = 24
Waitms 150
Portd = 0
Waitms 150

Else
If Pinc.2 = 0 Then

Portd = 1
Waitms 100
Portd = 3
Waitms 100
Portd = 7
Waitms 100
Portd = 15
Waitms 100
Portd = 31
Waitms 100
Portd = 63
Waitms 100
Portd = 127
Waitms 100
Portd = 255
Waitms 100
Portd = 254
Waitms 100
Portd = 252
Waitms 100
Portd = 248
Waitms 100
Portd = 240
Waitms 100
Portd = 224
Waitms 100
Portd = 192
Waitms 100
Portd = 128
Waitms 100
Portd = 0
Waitms 100

Else
If Pinc.3 = 0 Then

Portd = 129
Waitms 100
Portd = 66
Waitms 100
Portd = 36
Waitms 100
Portd = 24
Waitms 100
Portd = 36
Waitms 100
Portd = 66
Waitms 100

Else

Portd = 255
Wait 1
Portd = 0
Wait 1


End If
End If
End If
End If


Loop

jetzt meckert bascom nichtmehr
#3022404
alex schrieb:
> jetzt meckert bascom nichtmehr

wenn das programm macht was es soll, dann ist ja gut. ich befürchte 
aber, dass hier einfach 3x "End If" eingefügt wurde nur um die 
syntaxprüfung zu bestehen. ob das ganze semantisch auch stimmt steht auf 
einem anderen blatt, und das kann uns (fast) nur thedeather sagen. ich 
jedenfalls habe keine lust mir diese elends langen zusweiseungen mit 
pausen dazwischen genau anzuschauen.
Gast #3022429
Auch ein "3-Zeiler" wird bei mir kommentiert ( ' in BASCOM), das ist 
beim Programmieren keine Last, aber es hilft einem selbst, nach einem 
Jahr das eigene Programm zu verstehen.
Bei einem fremden Programm lese ich ohne Kommentare gar nicht bis zur 5. 
Zeile .....
#3022550
Bussard schrieb:
> Auch ein "3-Zeiler" wird bei mir kommentiert ( ' in BASCOM),

Bei diesem 'Programm' würde es schon reichen, wenn er einfach nur den 
Code sauber und korrekt einrücken würde. Auch das würde schon einiges an 
Unübersicht aus dem Code rausnehmen. Der nächste Schritt wären dann 
enweder Datenfelder und/oder eine Aufteilung in Einzelfunktionen.

Antwort schreiben

Eine eigene Frage? Dieser Thread ist über 13 Jahre alt. Stell sie in einem eigenen Thread – dort lesen mehr Leute mit, und sie wird öfter und schneller beantwortet.

Neuen Thread starten

Eine Lösung, Ergänzung oder Rückmeldung zu diesem Thread? Dann antworte hier.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.