Hallo Furtion, hallo roboterheld,
mir gehts eigentlich gar nicht um die Lösung meiner Programmieraufgabe, sonder eher darum, dass ich herausbekomme, warum ausgerechnet diese Konstellation nicht funktioniert. So ein Kleinkram kann für eine Menge Verwirrung sorgen wenn man mal ein umfangreicheres Projekt hat.
Könnt ihr dasselbe Problem beobachten wenn ihr die Funktion mal bei euch laufen lasst?
Im Anhang nochmal das komplette Programm (mittlerweile recht zerrupft).
Allein durch die Zeile "Local Pe As Word" ändert sich der Ausgabewert der Funktion obwohl nirgens mit "Pe" gearbeitet wird.
Code:
$crystal = 8000000
Config Lcd = 20 * 4 'Anzeigemodus 40 x 4 Zeichen
Config Lcdpin = Pin , E = Portb.6 , Rs = Portb.7 , Db4 = Portb.3 , Db5 = Portb.2 , Db6 = Portb.1 , Db7 = Portb.0 , E2 = Portb.5
Dim X As Integer , Mini As Byte , Maxi As Byte , Ausgabe As Byte , Teststring As String * 10
Dim A As Long , B As Long
Dim ___lcdno As Byte
Config Servos = 1 , Servo1 = Portc.0 , Reload = 10 , Timer = Timer0
Config Portb = Output
Config Portd = Input
Enable Interrupts
Declare Function Ausgabe(byval Prozent As Byte) As String
___lcdno = 0
Initlcd
Cls
Portd = 1
Mini = 30
Maxi = 160
X = Maxi - Mini
X = X / 2
X = X + Mini
Do
If Pind.0 = 0 Then X = X + 1
If Pind.1 = 0 Then X = X - 1
If Pind.2 = 0 Then X = X + 10
If Pind.3 = 0 Then X = X - 10
Waitms 50
Dim P As Integer , P2 As Integer , Y As Integer
Y = X
P = Maxi - Mini
P = P / 100
P2 = Mini + Y
P = P2 / P
Locate 1 , 1
Teststring = Ausgabe(90)
Servo(1) = X
Loop
End
Function Ausgabe(byval Prozent As Byte)
Local Pe As Word
Local Temp As Integer
Lcd Prozent
Local Temp2 As Word
Local Temp3 As String * 20
Temp = Prozent / 10
For Temp2 = 1 To Temp Step 1
Temp3 = Temp3 + "##"
Next
Ausgabe = Str(prozent) + " " + Temp3
Temp3 = ""
Temp2 = 0
Ausgabe = Str(prozent)
End Function
Lesezeichen