Forum: Mikrocontroller und Digitale Elektronik Bascom Programm


von thedeather11 (Gast)


Lesenswert?

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 !

von thedeather11 (Gast)


Lesenswert?

Er zeigt mir an, dass etwas mit den If...then Befehlen nicht stimmt. :(

von Win7fan (Gast)


Lesenswert?

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.

von Samuel C. (dragonsam)


Lesenswert?

Naja, du machst 4 mal 'if' auf und nur einmal wieder zu ;)

von smufte (Gast)


Lesenswert?

If Pinc.0 = 0 Then

versuchs mit
If Port c.0 = 0 Then


und deine auflistung gibt mir auch zu denken..
da wird wohl gleich der nächste fehler kommen..

von Samuel C. (dragonsam)


Lesenswert?

If Pinc.0 = 0 Then

stimmt schon, mit Portc.0 würde er nur das Ausgaberegister auslesen, in 
diesem Fall den Status der Pullups.

von Thomas (Gast)


Lesenswert?

Was soll denn an Port D passieren? Diese Schreibweise ist mir jedenfalls 
unbekannt, da gehts mir wie dem Compiler ;)

von Samuel C. (dragonsam)


Lesenswert?

Schließ' alle if's ab, dann passt das, der Rest ist schon richtig ;)

von smufte (Gast)


Lesenswert?

Du bist dir sicher dass die ports so gesetzt werden? Was hat das für ein 
Sinn ?

von Samuel C. (dragonsam)


Lesenswert?

Das ist kein Problem, warum sollte es eines sein?

von Philippe B. (philippe27)


Lesenswert?

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

von smufte (Gast)


Lesenswert?

Portd = 100 ?????????

von Samuel C. (dragonsam)


Lesenswert?

smufte schrieb:
> Portd = 100 ?????????

Was is das Problem damit? Wir der Port halt auf 01100100 gesetzt ...

von Stefan (Gast)


Lesenswert?

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

von smufte (Gast)


Lesenswert?

Das kennen ich so in dieser Form noch gar nicht. Nagut kann ich ja bei 
Gelegenheit mal probieren.

von alex (Gast)


Lesenswert?

$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

von fgdsr (Gast)


Lesenswert?

thedeather11 schrieb:
> Ich habe eine Frage. Was ist an diesem Programm falsch ?
>

die "Programmiersprache"?

von Daniel F. (df311)


Lesenswert?

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.

von Bussard (Gast)


Lesenswert?

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 .....

von Electronics'nStuff (Gast)


Lesenswert?

Naja, das ist kein Programm das ist eine Tabelle.
Mit programmieren hat das eig. nix zu tun.

von Karl H. (kbuchegg)


Lesenswert?

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.

von Weingut P. (weinbauer)


Lesenswert?

den größten Teil könnte man gut zusammenfassen

z.B.

Portd=1
for x=1 to 8
  shift portd, left,1
  incr portd
  waitms 100
next
for x=1 to 8
  shift portd, left,1
  waitms 100
next

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.