Hallo
Ich habe jetzt versucht es mit der Methode mit String umzusetzen doch ich habe ein paar Probleme damit.
Und zwar muss ich die Variable Ergebnis als Double deklarieren damit keine Fehler angezeigt werden.
Zudem zeigt mir Bascom an dass 29% Speicher benutzt werden. Das heißt ich kann das Ganze nicht mehr kompilieren weil ich nur die Demo habe.
Wenn ich den Befehl Lcd Ergebnis weglasse nimmt das Programm nur 20% in Anspruch.
Ich war mir bei der Deklaration von Rechnung auch nicht ganz sicher ob das stimmt.
Hier der Quellcode
Code:
$regfile = "M16def.dat" ' use the Mega16
$crystal = 1000000
Config Lcdpin = Pin , Db4 = Porta.3 , Db5 = Porta.2 , Db6 = Porta.1 , Db7 = Porta.0 , E = Porta.4 , Rs = Porta.5
Config Lcd = 16 * 2
Initlcd
Config Pinb.0 = Input 'Zahl 0
Config Pinb.1 = Input 'Zahl 1
Config Pinb.2 = Input 'Zahl 2
Config Pinb.3 = Input 'Zahl 3
Config Pinb.4 = Input 'Zahl 4
Config Pind.0 = Input 'Zahl 5
Config Pind.1 = Input 'Zahl 6
Config Pind.2 = Input 'Zahl 7
Config Pind.3 = Input 'Zahl 8
Config Pind.4 = Input 'Zahl 9
Config Pind.5 = Input 'Plus
Config Pind.7 = Input 'Minus
Config Pina.6 = Input 'Mal
Config Pina.7 = Input 'Geteilt
Config Pinc.7 = Input 'DELETE
Config Pinc.6 = Input 'AC
Config Pinc.5 = Input '=
Config Pinc.4 = Input 'Komma
Config Pinc.3 = Input 'Shift
Config Pinc.2 = Input 'x Hoch y
Config Pinc.0 = Output ' Beleuchtung
Portb.0 = 1 'Zahl 0
Portb.1 = 1 'Zahl 1
Portb.2 = 1 'Zahl 2
Portb.3 = 1 'Zahl 3
Portb.4 = 1 'Zahl 4
Portd.0 = 1 'Zahl 5
Portd.1 = 1 'Zahl 6
Portd.2 = 1 'Zahl 7
Portd.3 = 1 'Zahl 8
Portd.4 = 1 'Zahl 9
Portd.5 = 1 'Plus
Portd.7 = 1 'Minus
Porta.6 = 1 'Mal
Porta.7 = 1 'Geteilt
Portc.7 = 1 'Beleuchtung
Portc.6 = 1 'AC
Portc.5 = 1 '=
Portc.4 = 1 'Komma
Portc.3 = 1 'Shift
Portc.2 = 1 'x Hoch y
Dim Positionzeile As Integer
Dim Positionspalte As Integer
Dim Stelle As Integer
Dim Ergebnis As Double
Dim X As Integer
Positionzeile = 1
Positionspalte = 1
Dim Rechnung$ As String * 15
Rechnung$ = String(15 , 65)
Do
If Positionspalte > 16 Then
Positionzeile = 2
Waitms 50
End If
If Positionzeile > 2 Then
Positionzeile = 1
Waitms 50
End If
If Pinb.0 = 0 Then
Cursor Off
Locate Positionzeile , Positionspalte ' Zahl 0 schreiben
Lcd "0"
Positionspalte = Positionspalte + 1
Rechnung$ = Rechnung$ + "0"
Waitms 300
End If
If Pinb.1 = 0 Then
'Zahl 1 schreiben
Cursor Off
Locate Positionzeile , Positionspalte
Lcd "1"
Positionspalte = Positionspalte + 1
Rechnung$ = Rechnung$ + "1"
Waitms 300
End If
If Pinb.2 = 0 Then
Cursor Off
Locate Positionzeile , Positionspalte
Lcd "2"
Positionspalte = Positionspalte + 1
Rechnung$ = Rechnung$ + "2"
Waitms 300
End If
If Pinb.3 = 0 Then
Cursor Off
Locate Positionzeile , Positionspalte
Lcd "3"
Positionspalte = Positionspalte + 1
Rechnung$ = Rechnung$ + "3"
Waitms 300
End If
If Pinb.4 = 0 Then
Cursor Off
Locate Positionzeile , Positionspalte
Lcd "4"
Positionspalte = Positionspalte + 1
Rechnung$ = Rechnung$ + "4"
Waitms 300
End If
If Pind.0 = 0 Then
Cursor Off
Locate Positionzeile , Positionspalte
Lcd "5"
Positionspalte = Positionspalte + 1
Rechnung$ = Rechnung$ + "5"
Waitms 300
End If
If Pind.1 = 0 Then
Cursor Off
Locate Positionzeile , Positionspalte
Lcd "6"
Positionspalte = Positionspalte + 1
Rechnung$ = Rechnung$ + "6"
Waitms 300
End If
If Pind.2 = 0 Then
Cursor Off
Locate Positionzeile , Positionspalte
Lcd "7"
Positionspalte = Positionspalte + 1
Rechnung$ = Rechnung$ + "7"
Waitms 300
End If
If Pind.3 = 0 Then
Cursor Off
Locate Positionzeile , Positionspalte
Lcd "8"
Positionspalte = Positionspalte + 1
Rechnung$ = Rechnung$ + "8"
Waitms 300
End If
If Pind.4 = 0 Then
Cursor Off
Locate Positionzeile , Positionspalte
Lcd "9"
Positionspalte = Positionspalte + 1
Rechnung$ = Rechnung$ + "9"
Waitms 300
End If
If Pind.5 = 0 Then
Cursor Off
Locate Positionzeile , Positionspalte
Lcd "+"
Positionspalte = Positionspalte + 1
Rechnung$ = Rechnung$ + "+"
Waitms 300
End If
If Pind.7 = 0 Then
Cursor Off
Locate Positionzeile , Positionspalte
Lcd "-"
Positionspalte = Positionspalte + 1
Rechnung$ = Rechnung$ + "-"
Waitms 300
End If
If Pina.6 = 0 Then
Cursor Off
Locate Positionzeile , Positionspalte
Lcd "x"
Positionspalte = Positionspalte + 1
Rechnung$ = Rechnung$ + "x"
Waitms 300
End If
If Pina.7 = 0 Then
Cursor Off
Locate Positionzeile , Positionspalte
Lcd "/"
Positionspalte = Positionspalte + 1
Rechnung$ = Rechnung$ + "/"
Waitms 300
End If
If Pinc.6 = 0 Then
Cls
Cursor Off
Positionspalte = 1
Positionzeile = 1
Waitms 300
End If
If Pinc.7 = 0 Then
Portc.0 = 1
Wait 7
Portc.0 = 0
Wait 4
End If
If Pinc.5 = 0 Then
Rechnung$ = Rechnung$ + "="
Waitms 300
Lcd Ergebnis
End If
For Stelle = 1 To Len(rechnung$)
If Mid(rechnung$ , Stelle , 1) = "+" Then
Ergebnis = Val(mid(rechnung$ , 1 , Stelle)) + Val(mid(rechnung$ , Stelle + 1 , Len(rechnung$)))
End If
Next Stelle
Loop
Kann man den Code noch irgendwie ändern dass ich wenigstens die vier Grundrechenarten in Bascom schaffe zu flashen ?
Mfg
David
Lesezeichen