PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Zähler



DaveWagner
21.12.2008, 13:52
Hallo

Ich will einen Zähler bauen ,der, wenn man auf einen Taster drückt, immer um eins nach oben zählt.Das ganze bis 99 also im zweistelligen Bereich.


$regfile = "m8def.dat"
$crystal = 1000000 ' 1MHZ crystal

Ddrc = &B000000
Ddrd = &B0000000
Config Pind.2 = Input





Dim Vari1 As Byte
Vari1 = 0
Config Int0 = Rising
Enable Interrupts
Enable Int0
On Int0 Unterprogramm


Do

Vari1



Unterprogramm:
Vari1 = Vari1 + 1

Return


0:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 1
Portd.4 = 1
Portd.5 = 1

1:

Portd.1 = 1
Portd.7 = 1


2:
Portd.0 = 1
Portd.1 = 1
Portd.6 = 1
Portd.4 = 1
Portd.3 = 1

3:
Portd.0 = 1
Portd.1 = 1
Portd.6 = 1
Portd.7 = 1
Portd.3 = 1

4:
Portd.5 = 1
Portd.6 = 1
Portd.1 = 1
Portd.7 = 1

5:
Portd.0 = 1
Portd.5 = 1
Portd.6 = 1
Portd.7 = 1
Portd.3 = 1

6:
Portd.0 = 1
Portd.5 = 1
Portd.6 = 1
Portd.4 = 1
Portd.3 = 1
Portd.7 = 1

7:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1

8:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 1
Portd.4 = 1
Portd.5 = 1
Portd.6 = 1

9:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 1
Portd.5 = 1
Portd.6 = 1

Ich weiß jetzt nicht wie das Hauptprogramm aussehen soll.
Wie kann ich sagen das die Variable Vari1 angezeigt werden soll ?
Das ganze soll auf 7 Segment Displays angezeigt werden.

Mfg

David Wagner

Dirk
21.12.2008, 14:09
Hallo David,

in diesem Thread:
https://www.roboternetz.de/phpBB2/viewtopic.php?t=33170
... gibt's einige schöne Programmschnipsel und Anschlußbeispiele.

In Deinem eigenen Thread vom November:
https://www.roboternetz.de/phpBB2/viewtopic.php?t=44085
... hattest du das ja schon viel weiter entwickelt! Mach doch da einfach weiter!?

Gruß Dirk

DaveWagner
23.12.2008, 17:19
Hallo

Hab mir den anderen Thread angeschaut, doch ich werde einfach nicht schlauer.

Die Anzeige zeigt mir jetzt immer Null an , auch wenn ich den Taster drücke.
Kann mir einer einfach einen konkreten Vorschlag geben, was ich anders machen muss
Hier mein Programm:

$regfile = "m8def.dat"
$crystal = 1000000 ' 1MHZ crystal


Config Pind.0 = Output
Config Pind.1 = Output
Config Pind.7 = Output
Config Pind.3 = Output
Config Pind.4 = Output
Config Pind.5 = Output
Config Pind.6 = Output


Config Int0 = Rising
Enable Interrupts
Enable Int0
On Int0 Unterprogramm



Dim I As Integer
I = 0

Do


Select Case I
Case 0 : Gosub Null
Case 1 : Gosub Eins
Case 2 : Gosub Zwei
Case 3 : Gosub Drei
Case 4 : Gosub Vier
Case 5 : Gosub Fuenf
Case 6 : Gosub Sechs
Case 7 : Gosub Sieben
Case 8 : Gosub Acht
Case 9 : Gosub Neun


End Select





Loop















Unterprogramm:
I = I + 1

Return


Null:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 1
Portd.4 = 1
Portd.5 = 1
Portd.6 = 0
Wait 9
Return

Eins:

Portd.1 = 1
Portd.7 = 1
Portd.3 = 0
Portd.4 = 0
Portd.5 = 0
Portd.6 = 0
Portd.0 = 0
Wait 9
Return

Zwei:
Portd.0 = 1
Portd.1 = 1
Portd.6 = 1
Portd.4 = 1
Portd.3 = 1
Portd.5 = 0
Portd.7 = 0
Wait 9
Return
Drei:
Portd.0 = 1
Portd.1 = 1
Portd.6 = 1
Portd.7 = 1
Portd.3 = 1
Portd.5 = 0
Portd.4 = 0
Wait 9
Return

Vier:
Portd.5 = 1
Portd.6 = 1
Portd.1 = 1
Portd.7 = 1
Portd.4 = 0
Portd.3 = 0
Portd.0 = 0
Wait 9
Return

Fuenf:
Portd.0 = 1
Portd.5 = 1
Portd.6 = 1
Portd.7 = 1
Portd.3 = 1
Portd.4 = 0
Portd.1 = 1
Wait 9
Return

Sechs:
Portd.0 = 1
Portd.5 = 1
Portd.6 = 1
Portd.4 = 1
Portd.3 = 1
Portd.7 = 1
Portd.1 = 0
Wait 9
Return


Sieben:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 0
Portd.4 = 0
Portd.5 = 0
Portd.6 = 0
Wait 9
Return

Acht:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 1
Portd.4 = 1
Portd.5 = 1
Portd.6 = 1
Wait 9
Return

Neun:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 1
Portd.5 = 1
Portd.6 = 1
Portd.4 = 0
Wait 9
Return

Mfg

David

Sauerbruch
23.12.2008, 19:30
Der Controller ist ja praktisch immer in einem der 10 Unterprogrammen, da er dort immer 9 Sekunden wartet, um dann für ein paar Mikrosekunden in die Hauptschleife zurückzukehren.
Ich weiß nicht 100%, ob Interrupts "angenommen" werden können, wenn der Controller in einem Unterprogramm ist.
(Würde mich aber auch interessieren, BtW...)

Probier doch mal aus, die wait 9 - Befehle am Ende der 10 Gosubs rauszunehmen, und stattdessen ein einziges wait 9 nach dem Befehl End Select zu schreiben. Läuft auf´s selbe hinaus, aber das Programm ist dann nahezu immer in der Hauptschleife.

DaveWagner
23.12.2008, 20:06
Hallo
Sauerbruch

hab gerade deinen Vorschlag draufgeladen.
Wie du schon gesagt hast läuft es auf das Selbe hinaus und jetzt zeigt die Anzeige wieder nur eine Null an und reagiert nicht auf den Input.

mfg

David

for_ro
23.12.2008, 20:08
Die Anzeige zeigt mir jetzt immer Null an , auch wenn ich den Taster drücke.


Wie ist denn dein Taster angeschlossen? Mit PullUp? In deinem Code ist keiner drin.

Gruß

Rolf

Neutro
23.12.2008, 20:09
Hallo hier ein Beispiel das dir sicherlich weiterhilft:

'-------------------------------------------------------------------------------
'Tasterzähler


$regfile "m8def.dat"


'-------------------------------------------------------------------------------
'Eingänge

Config Pinc.1 = Input 'um 1 runterzählen
Config Pinc.0 = Input 'um eins hochzählen

'Ausgänge

Config Portd.0 = Output
Config Portd.1 = Output
Config Portd.2 = Output
Config Portd.3 = Output
Config Portd.4 = Output
Config Portd.5 = Output
Config Portd.6 = Output
Config Portd.7 = Output


'Alle Ports auf "1"

Portd.0 = 1
Portd.1 = 1
Portd.2 = 1
Portd.3 = 1
Portd.4 = 1
Portd.5 = 1
Portd.6 = 1
Portd.7 = 1
Portc.0 = 1
Portc.1 = 1
'-------------------------------------------------------------------------------
'Variable setzen

Dim A As Byte
A = 0 'Startwert

'-------------------------------------------------------------------------------
'Hauptprogramm

Do

If Pinc.0 = 0 Then 'Zähler hochzählen
Incr A
Waitms 50
End If

If Pinc.1 = 0 Then 'Zähler runterzählen
Decr A
Waitms 50
End If

If A > 10 Then '10 als Maximalwert
A = 0
Else
End If

If A = 1 Then
Portd.0 = 0 'hier hätte man auch case verwenden können
Else
Portd.0 = 1
End If

If A = 2 Then
Portd.1 = 0
Else
Portd.1 = 1
End If

If A = 3 Then
Portd.2 = 0
Else
Portd.2 = 1
End If

If A = 4 Then
Portd.3 = 0
Else
Portd.3 = 1
End If

If A = 5 Then
Portd.4 = 0
Else
Portd.4 = 1
End If

If A = 6 Then
Portd.5 = 0
Else
Portd.5 = 1
End If

If A = 7 Then
Portd.6 = 0
Else
Portd.6 = 1
End If

If A = 8 Then
Portd.7 = 0
Else
Portd.7 = 1
End If

If A = 9 Then 'beim Zählerstand von 9 zurücksetzen
A = 0
End If


Loop

MfG

Neutro

PS: wie funktioniert der Code Tag eigentlich?[/code]

Sauerbruch
23.12.2008, 20:59
Du könntest den Fehler etws eingrenzen, indem Du mal

Dim I as Integer
I = 5

schreibst (um zu sehen, ob dann ´ne 5 im Display erscheint). Ist dem so, ist tatsächlich was mit dem Interrupt nicht in Ordnung. Womit wir bei der Frage von for_ro wären, ob der Int0-Eingang ordentlich beschaltet ist, d.h. mit PullUp- bzw. PullDown-Widerstand.

Carlos31
23.12.2008, 21:47
hi , bin selber neu in bascom , ich versuch nur zu helfen , hab dein code geändert mit pinc.0 kannst raufzählen , mit pinc.1 runterzählen , ich hoffe dich geholfen zu haben , ist mein erster versuch :-)
Schöne grüsse aus Österreich




$regfile = "m8def.dat"
$crystal = 1000000 ' 1MHZ crystal


Config Pind.0 = Output
Config Pind.1 = Output
Config Pind.7 = Output
Config Pind.3 = Output
Config Pind.4 = Output
Config Pind.5 = Output
Config Pind.6 = Output
Config Pinc.0 = Input
Config Pinc.1 = Input
Portc.0 = 1
Portc.1 = 1





Dim I As Byte
I = 0

Do

If Pinc.0 = 1 Then
Incr I
End If
If Pinc.1 = 1 Then
Decr I
End If

If I >= 9 Then
I = 0
End If

Portd = 0
Select Case I
Case 0 : Gosub Null
Case 1 : Gosub Eins
Case 2 : Gosub Zwei
Case 3 : Gosub Drei
Case 4 : Gosub Vier
Case 5 : Gosub Fuenf
Case 6 : Gosub Sechs
Case 7 : Gosub Sieben
Case 8 : Gosub Acht
Case 9 : Gosub Neun


End Select

Waitms 500


Loop














Return


Null:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 1
Portd.4 = 1
Portd.5 = 1
Portd.6 = 0
Wait 9
Return

Eins:

Portd.1 = 1
Portd.7 = 1
Portd.3 = 0
Portd.4 = 0
Portd.5 = 0
Portd.6 = 0
Portd.0 = 0
Wait 9
Return

Zwei:
Portd.0 = 1
Portd.1 = 1
Portd.6 = 1
Portd.4 = 1
Portd.3 = 1
Portd.5 = 0
Portd.7 = 0
Wait 9
Return
Drei:
Portd.0 = 1
Portd.1 = 1
Portd.6 = 1
Portd.7 = 1
Portd.3 = 1
Portd.5 = 0
Portd.4 = 0
Wait 9
Return

Vier:
Portd.5 = 1
Portd.6 = 1
Portd.1 = 1
Portd.7 = 1
Portd.4 = 0
Portd.3 = 0
Portd.0 = 0
Wait 9
Return

Fuenf:
Portd.0 = 1
Portd.5 = 1
Portd.6 = 1
Portd.7 = 1
Portd.3 = 1
Portd.4 = 0
Portd.1 = 1
Wait 9
Return

Sechs:
Portd.0 = 1
Portd.5 = 1
Portd.6 = 1
Portd.4 = 1
Portd.3 = 1
Portd.7 = 1
Portd.1 = 0
Wait 9
Return


Sieben:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 0
Portd.4 = 0
Portd.5 = 0
Portd.6 = 0
Wait 9
Return

Acht:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 1
Portd.4 = 1
Portd.5 = 1
Portd.6 = 1
Wait 9
Return

Neun:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 1
Portd.5 = 1
Portd.6 = 1
Portd.4 = 0
Wait 9
Return

Carlos31
23.12.2008, 21:49
ups hab es gerade gesehen
config pind.x = output
soll heissen
config port.x = output
komischerweise bascom schluckt es trotzdem :-)

for_ro
23.12.2008, 22:19
config pind.x = output <--------------- dies ist laut Help korrekt
config portd.x = output <--------------- dies ist laut Help nicht korrekt, funktioniert aber


@ Carlos31,
sein Code benutzte den Int0 um sofort und einmalig in eine ISR zugehen. Dies bringt bei einem Taster sicherlich Prell-Probleme mit sich, aber ansonsten wird die ISR nur einmal aufgerufen.
Dein Code pollt den Eingang und wenn er auf 1 ist, zählt deine IF Abfrage hoch. Wenn du nicht innerhalb der 500ms loslässt, erhöht sie auch mehrfach.

Als dritte Lösung gibt es übrigens auch noch den Debounce Befehl, der genau zum Entprellen von Tastern gemacht ist.

@ DaveWagner
Einen Fehler in deinem Code habe ich gerade noch gesehen. Zum Darstellen einer 5 muss das Segment an PortD.1 auf 0 sein, sonst kommt eine 9 heraus.
Hast du das Ganze eigentlich in Hardware gemacht oder probierst du am Simulator aus?

Gruß

Rolf

DaveWagner
24.12.2008, 14:13
Hallo

Danke für eure zahlreichen Antworten.
Ich hab jetzt Teile aus Neutros Vorschlag übernommen (das heißt statt dem Unterprogramm, Incr Variable hergenommen und statt Select Case ,If Funktionen)
Jetzt funktioniert das ganze eigentlich ganz gut.( Ich teste das ganze an Hardware, da ich es dann auch hernehmen will.

Eine Frage habe ich noch.
Muss ich jetzt für jede Zahl eine Deklaration schreiben oder kann man das eleganter und zeitsparender lösen.
(Ich benutze wiegesagt Sieben-Segment-Anzeigen)
Wenn nicht, geht es dann bei Display-Modulen ?

Mfg
David

DaveWagner
25.12.2008, 12:32
Hallo

Jetzt ist doch wieder ein Problem aufgetaucht. Das Programm hängt bei bestimmten Zahlen.
Momentan bleibt es immer bei eins stehen und läuft nicht weiter darüber hinaus.
Vorher blieb es bei 5 oder 6 immer stehen.
Ich hab auch schon einen anderen Controller hergenommen.
Doch das bewirkt keinen Unterschied.
Kann das am Prgramm liegen ?

Hier mal mein Programm:



$regfile = "m8def.dat"
$crystal = 1000000 ' 1MHZ crystal


Config Portd.0 = Output
Config Portd.1 = Output
Config Portd.7 = Output
Config Portd.3 = Output
Config Portd.4 = Output
Config Portd.5 = Output
Config Portd.6 = Output
Config Portd.2 = Input
Config Portb.1 = Input

Portd.2 = 1
Portb.1 = 1


Dim A As Integer
A = 0

Do

If Pind.2 = 1 Then 'Zähler hochzählen
Incr A
Waitms 50
End If

If Pinb.1 = 0 Then 'Zähler runterzählen
Decr A
Waitms 50
End If

If A >= 10 Then '10 als Maximalwert
A = 0
Else
End If

If A = 0 Then
Gosub Null
End If

If A = 1 Then
Gosub Eins
End If

If A = 2 Then
Gosub Zwei
End If

If A = 3 Then
Gosub Drei
End If

If A = 4 Then
Gosub Vier
End If

If A = 5 Then
Gosub Fuenf
End If

If A = 6 Then
Gosub Sechs
End If

If A = 7 Then
Gosub Sieben
End If

If A = 8 Then
Gosub Acht
End If


If A = 9 Then
Gosub Neun
End If

If A = 10 Then
Gosub Zehn
End If

If A = 11 Then
Gosub Elf
End If

If A = 12 Then
Gosub Zwoelf
End If

If A = 13 Then
Gosub Dreizehn
End If

If A = 14 Then
Gosub Vierzehn
End If

If A = 15 Then
Gosub Fuenfzehn
End If

If A = 16 Then
Gosub Sechzehn
End If

If A = 17 Then
Gosub Siebzehn
End If

If A = 18 Then
Gosub Achtzehn
End If

If A = 19 Then
Gosub Neunzehn
End If












Loop















Unterprogramm:
A = A + 1

Return


Null:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 1
Portd.4 = 1
Portd.5 = 1
Portd.6 = 0
Waitms 450
Return

Eins:

Portd.1 = 1
Portd.7 = 1
Portd.3 = 0
Portd.4 = 0
Portd.5 = 0
Portd.6 = 0
Portd.0 = 0
Waitms 450
Return

Zwei:
Portd.0 = 1
Portd.1 = 1
Portd.6 = 1
Portd.4 = 1
Portd.3 = 1
Portd.5 = 0
Portd.7 = 0
Waitms 450
Return
Drei:
Portd.0 = 1
Portd.1 = 1
Portd.6 = 1
Portd.7 = 1
Portd.3 = 1
Portd.5 = 0
Portd.4 = 0
Waitms 450
Return

Vier:
Portd.5 = 1
Portd.6 = 1
Portd.1 = 1
Portd.7 = 1
Portd.4 = 0
Portd.3 = 0
Portd.0 = 0
Waitms 450
Return

Fuenf:
Portd.0 = 1
Portd.5 = 1
Portd.6 = 1
Portd.7 = 1
Portd.3 = 1
Portd.4 = 0
Portd.1 = 0
Waitms 450
Return

Sechs:
Portd.0 = 1
Portd.5 = 1
Portd.6 = 1
Portd.4 = 1
Portd.3 = 1
Portd.7 = 1
Portd.1 = 0
Waitms 450
Return


Sieben:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 0
Portd.4 = 0
Portd.5 = 0
Portd.6 = 0
Waitms 450
Return

Acht:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 1
Portd.4 = 1
Portd.5 = 1
Portd.6 = 1
Waitms 450
Return

Neun:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 1
Portd.5 = 1
Portd.6 = 1
Portd.4 = 0
Waitms 450
Return

Zehn:
Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 1
Portd.4 = 1
Portd.5 = 1
Portd.6 = 0
Portc.1 = 1
Portc.2 = 1
Portc.0 = 0
Portc.5 = 0
Portc.6 = 0
Portc.4 = 0
Portc.3 = 0

Waitms 450
Return

Elf:
Portc.1 = 1
Portc.2 = 1
Portc.0 = 0
Portc.5 = 0
Portc.6 = 0
Portc.4 = 0
Portc.3 = 0
Portd.1 = 1
Portd.7 = 1
Portd.3 = 0
Portd.4 = 0
Portd.5 = 0
Portd.6 = 0
Portd.0 = 0
Waitms 450
Return

Zwoelf:

Portc.1 = 1
Portc.2 = 1
Portc.0 = 0
Portc.5 = 0
Portc.6 = 0
Portc.4 = 0
Portc.3 = 0
Portd.0 = 1
Portd.1 = 1
Portd.6 = 1
Portd.4 = 1
Portd.3 = 1
Portd.5 = 0
Portd.7 = 0

Waitms 450
Return

Dreizehn:


Portc.1 = 1
Portc.2 = 1
Portc.0 = 0
Portc.5 = 0
Portc.6 = 0
Portc.4 = 0
Portc.3 = 0
Portd.0 = 1
Portd.1 = 1
Portd.6 = 1
Portd.7 = 1
Portd.3 = 1
Portd.5 = 0
Portd.4 = 0

Waitms 450
Return

Vierzehn:
Portc.1 = 1
Portc.2 = 1
Portc.0 = 0
Portc.5 = 0
Portc.6 = 0
Portc.4 = 0
Portc.3 = 0

Portd.5 = 1
Portd.6 = 1
Portd.1 = 1
Portd.7 = 1
Portd.4 = 0
Portd.3 = 0
Portd.0 = 0
Waitms 450
Return

Fuenfzehn:

Portc.1 = 1
Portc.2 = 1
Portc.0 = 0
Portc.5 = 0
Portc.6 = 0
Portc.4 = 0
Portc.3 = 0


Portd.0 = 1
Portd.5 = 1
Portd.6 = 1
Portd.7 = 1
Portd.3 = 1
Portd.4 = 0
Portd.1 = 0
Waitms 450
Return

Sechzehn:

Portc.1 = 1
Portc.2 = 1
Portc.0 = 0
Portc.5 = 0
Portc.6 = 0
Portc.4 = 0
Portc.3 = 0

Portd.0 = 1
Portd.5 = 1
Portd.6 = 1
Portd.4 = 1
Portd.3 = 1
Portd.7 = 1
Portd.1 = 0

Waitms 450
Return

Siebzehn:

Portc.1 = 1
Portc.2 = 1
Portc.0 = 0
Portc.5 = 0
Portc.6 = 0
Portc.4 = 0
Portc.3 = 0


Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 0
Portd.4 = 0
Portd.5 = 0
Portd.6 = 0

Waitms 450
Return

Achtzehn:

Portc.1 = 1
Portc.2 = 1
Portc.0 = 0
Portc.5 = 0
Portc.6 = 0
Portc.4 = 0
Portc.3 = 0

Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 1
Portd.4 = 1
Portd.5 = 1
Portd.6 = 1

Waitms 450
Return

Neunzehn:

Portc.1 = 1
Portc.2 = 1
Portc.0 = 0
Portc.5 = 0
Portc.6 = 0
Portc.4 = 0
Portc.3 = 0

Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 1
Portd.5 = 1
Portd.6 = 1
Portd.4 = 0

Waitms 450
Return

Frohe Weihnachten

David

Neutro
25.12.2008, 16:21
Nun das dürfte daran liegen das die Eingänge auf eine logische 0 (GND) reagieren sollten weil die Internen Pull ups aktiviert sind
Also If PinXX = 0 Then ....
Mir ist auch aufgefallen das du den CPort nicht Configuriert hast.
Hast du dich eigentlich überhaupt schon mal mit den Bascom AVR Grundlagen beschäftigt? Schau noch mal ins WIKI rein.

Mfg

Neutro

for_ro
25.12.2008, 20:15
Hallo David,
ich hoffe, dass deine Anzeige nicht bis 99 gehen wird, sonst wird das ja ein riesiges Programm.
Du kannst auch einen ganzen Port mit einem Befehl setzen.
Anstelle von:

Portd.0 = 1
Portd.1 = 1
Portd.7 = 1
Portd.3 = 1
Portd.4 = 1
Portd.5 = 1
Portd.6 = 0
Portc.1 = 1
Portc.2 = 1
Portc.0 = 0
Portc.5 = 0
Portc.6 = 0
Portc.4 = 0
Portc.3 = 0

wäre das dann für die "10" einfach

Portd=191 'oder auch PortD = &B10111111, damit du die einzelnen Bits noch siehst
Portc=6

Und der nächste Schritt wäre dann, diese Werte in ein Array abspeichern:
Segmente_zehner(1)=6
Segmente_Einer(0)=191 'siehe Bemerkung unten

Damit hättest du dann auch die ganzen Ifs eingespart und dein Programm sähe dann recht übersichtlich aus:


$regfile = "m8def.dat"
$crystal = 1000000 ' 1MHZ crystal
$sim
Ddrd = &B11111101 'Pind.2 ist ein Eingang
Ddrc = &B11111111
Config Pinb.1 = Input

Portd.2 = 1
Portb.1 = 1

Dim Segmente_einer(10) As Byte , Segmente_zehner(10) As Byte

Dim A As Byte '256 Werte reichen doch
Dim Einer As Byte , Zehner As Byte

Segmente_einer(1) = &B10000011 'bit 2 muss immer gesetzt sein, weil das der Pullup für PORTD.2 ist
Segmente_einer(2) = &B01011111 'bit 2 muss immer gesetzt sein, weil das der Pullup für PORTD.2 ist
'...... 'hier musst du noch die anderen Werte hinschreiben
Segmente_einer(10) = &B10111111 'Arrays fangen leider mt Index 0 an, deshalb nehmen wir die 10 für die 0

Segmente_zehner(1) = &B00000110
'...... 'hier musst du noch die anderen Werte hinschreiben

A = 0

Do
If Pind.2 = 1 Then 'Zähler hochzählen
Incr A
Waitms 50
End If

If Pinb.1 = 1 Then 'Zähler runterzählen
Decr A
Waitms 50
End If
If A > 19 Then '10 als Maximalwert
A = 0
End If

Zehner = A / 10
If Zehner = 0 Then Zehner = 10 'siehe oben
Einer = A Mod 10
If Einer = 0 Then Einer = 10

Portd = Segmente_einer(einer)
Portc = Segmente_zehner(zehner)
Waitms 450
Loop

End

Das wäre alles.

Ich habe den Taster an PINB.1 genauso abgefragt wie den an PIND.2, oder funktioniert der tatsächlich anders herum?

Gruß

Rolf