-
Wenn du keine grossen Datenmengen schnell ueber RS232 senden willst..wo ich bei 3^3 LED's nicht ausgehe, reicht dir normal auch der interne?
BOD ist die Brown-Out Detection und resetet den uC wenn die Betriebsspannung zu klein wird, aber du wirst den Aufbau eh am Netz betreiben.
-
So hab nun doch keinen Würfel, sondern ein 5*5 panel, da dies noch im Regal lag.
http://www.youtube.com/watch?v=83N7au7Ujvk
5 Programme die über einen Taster durchgeschaltet werden können. die grünen LEDs rechts zeigen das aktuelle Programm (1-5 zählen binär). Die rote LED zeigt den gedrückten Taster an.
Das Video wurde durchs konvertieren etwas schneller.
Code:
$regfile = "m32def.dat"
$framesize = 32
$swstack = 32
$hwstack = 32
$crystal = 16000000
$baud = 9600
'--- IN/OUT CONFIG ---
Config Porta = Output
Config Portc = Output
Config Portd = Output
Config Pinb.2 = Input
Config Pina.6 = Input
'---------------------
'---PINS BENENNEN-----
S5 Alias Portc.0
S4 Alias Portc.1
S3 Alias Portc.2
S2 Alias Portc.3
S1 Alias Portc.4
Z5 Alias Porta.0
Z4 Alias Porta.1
Z3 Alias Porta.2
Z2 Alias Porta.3
Z1 Alias Porta.4
Taster Alias Pinb.2
Sled1 Alias Portd.5
Sled2 Alias Portd.4
Sled3 Alias Portd.3
Tled Alias Portd.2
'---------------------
'---UNTERPROGRAMME----
Declare Sub Mustera()
Declare Sub Musterb()
Declare Sub Musterc()
Declare Sub Musterd()
Declare Sub Mustere()
'---------------------
'---Taster & status --
Portd.6 = 1
Portd.5 = 1
Portd.4 = 1
Portd.3 = 1
Portd.2 = 1
Portb.2 = 1
Porta.6 = 1
'---------------------
'---VARIABLEN---------
Dim A As Integer
A = 0
'---------------------
Do
'-------LEDS AUS------
Porta.1 = 1
Porta.0 = 1
Porta.2 = 1
Porta.3 = 1
Porta.4 = 1
Portc.0 = 1
Portc.1 = 1
Portc.2 = 1
Portc.3 = 1
Portc.4 = 1
'---------------------
If Taster = 0 Then
Incr A
Tled = 0
End If
If A = 6 Then
A = 1
End If
If A = 1 Then
Call Mustera()
Sled1 = 0
Sled2 = 1
Sled3 = 1
Tled = 1
End If
If A = 2 Then
Call Musterb()
Sled1 = 1
Sled2 = 0
Sled3 = 1
Tled = 1
End If
If A = 3 Then
Call Musterc()
Sled1 = 0
Sled2 = 0
Sled3 = 1
Tled = 1
End If
If A = 4 Then
Call Musterd()
Sled3 = 0
Sled2 = 1
Sled1 = 1
Tled = 1
End If
If A = 5 Then
Call Mustere()
Sled3 = 0
Sled2 = 1
Sled1 = 0
Tled = 1
End If
Loop
Sub Mustera()
Z2 = 1
S1 = 0
S5 = 0
Z1 = 0
Waitms 50
S1 = 1
S5 = 1
Z1 = 1
S2 = 0
S4 = 0
Z2 = 0
Waitms 50
S2 = 1
S4 = 1
Z2 = 1
S3 = 0
Z3 = 0
Waitms 50
S3 = 1
Z3 = 1
S4 = 0
S2 = 0
Z4 = 0
Waitms 50
S4 = 1
S2 = 1
Z4 = 1
S5 = 0
S1 = 0
Z5 = 0
Waitms 50
S5 = 1
S1 = 1
Z5 = 1
Z4 = 0
S1 = 0
S5 = 0
Waitms 50
Z3 = 0
Z4 = 1
Waitms 50
Z3 = 1
Z2 = 0
Waitms 50
End Sub
Sub Musterb()
S3 = 0
Z3 = 0
Waitms 70
S2 = 0
S4 = 0
Z2 = 0
Z4 = 0
Waitms 70
S1 = 0
S5 = 0
Z1 = 0
Z5 = 0
Waitms 70
Z5 = 1
Z1 = 1
S5 = 1
S1 = 1
Waitms 70
S2 = 1
S4 = 1
Z2 = 1
Z4 = 1
Waitms 70
End Sub
Sub Musterc()
Z1 = 0
S1 = 0
Waitms 70
S1 = 1
S2 = 0
Waitms 70
S2 = 1
S3 = 0
Waitms 70
S3 = 1
S4 = 0
Waitms 70
S4 = 1
S5 = 0
Waitms 70
Z1 = 1
Z2 = 0
Waitms 70
Z2 = 1
Z3 = 0
Waitms 70
Z3 = 1
Z4 = 0
Waitms 70
Z4 = 1
Z5 = 0
Waitms 70
S5 = 1
S4 = 0
Waitms 70
S4 = 1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ub
Ich nehm stark an das der Code extrem verringert werden kann, werde mich die tage da mal etwas schlauer machen. Gibts denn irgendwo ne gute basic befehlsübersicht?
-
In der Bascom Hilfe ist eine komplette Befehlsreferenz Erfasst die meiner Meinung nach auch sehr gut aufgebaut ist und relativ informativ.
Übrigens solltest du event. drüber nachdenken die Tasterabfrage anstelle von if Taster = 1 mit Debounce zu machen. Da du in der Abfrage direkt eine increment drin hast kann es dir sonst passieren, dass die Variable nicht nur um 1 erhöht wird.