das ist mein neuer code (also mit do-loop):
Code:
$regfile = "m32def.dat"
$crystal = 16000000
$hwstack = 32
$swstack = 32
$framesize = 64
Declare Function Tastenabfrage() As Byte
Config Lcd = 20 * 4
Config Lcdpin = Pin , Db4 = Portc.0 , Db5 = Portc.1 , Db6 = Portc.2 , Db7 = Portc.3 , E = Portc.4 , Rs = Portc.5
Config Lcdbus = 4
Config Adc = Single , Prescaler = Auto
Config Pina.7 = Input
Porta.7 = 1
Config Portc.7 = Output
Portc.7 = 1
Config Timer1 = Timer , Prescale = 1024
Enable Timer1
Enable Interrupts
Timer1 = 49910
On Timer1 Isr_von_timer1
Config Timer0 = Counter , Edge = Falling
Enable Timer0
Timer0 = 255
On Timer0 Isr_von_timer0
Dim A As Integer
Dim Taste As Byte
Dim Volt As Single
Dim Secu As Single
Dim Minu As Single
Dim Hour As Single
Dim X As Single
Dim Tasten_flag As Byte
Dim F As Single
Dim T As Single
Dim Freq As Single
Dim W As Word
Dim J As Word
Dim Y As Word
Dim S As Single
Dim Ws As Word
Const Ref = 5 / 1023
Initlcd
A = 1
X = 1
Secu = 00
Minu = 00
Hour = 00
T = 0
Tasten_flag = 0
F = 0
Cursor Off
Cls
Locate 1 , 4
Lcd "Daten-Terminal "
Locate 2 , 1
Lcd "Hier koennen Sie"
Locate 3 , 1
Lcd "ermittelte Daten"
Locate 4 , 1
Lcd "Speichern!!! "
Do
Taste = Tastenabfrage()
If Taste <> 0 Then
Select Case Taste
Case 1
Waitms 50
Cls
Y = 1
Tasten_flag = 0
Do
Cursor Off
Start Adc
W = Getadc(6)
Volt = W * Ref
Volt = Volt * 5.2941
Locate 1 , 1
Lcd "Die aktuelle "
Locate 2 , 1
Lcd "Spannung betraegt: "
Locate 3 , 1
Lcd Volt ; " Volt "
W = Getadc(7)
If W < 500 Then
Select Case W
Case 400 To 450
J = 1
Case 330 To 380
J = 2
Case 260 To 305
J = 3
Case 180 To 220
J = 4
Case 90 To 130
J = 5
End Select
End If
If J <> Y Then
Tasten_flag = 1
Exit For
End If
Loop Until Tasten_flag = 1
Case 2
Waitms 50
Cursor Off
Cls
Y = 2
Tasten_flag = 0
Writeeeprom Secu , 1
Writeeeprom Minu , 10
Writeeeprom Volt , 20
Writeeeprom Freq , 30
Cls
Locate 1 , 1
Lcd "Speichern von: "
Locate 2 , 1
Lcd "Frequenz, Laufzeit "
Locate 3 , 1
Lcd "und Batteriespannung"
Locate 4 , 1
Lcd "Daten jetzt abrufbar"
Case 3
Waitms 50
Cursor Off
Cls
Y = 3
Tasten_flag = 0
Do
Cursor Off
Freq = F / T
Locate 1 , 1
Lcd "Sekunden = " ; T
Locate 2 , 1
Lcd "Signale = " ; F
Locate 3 , 1
Lcd "==> Frequenz:"
Locate 4 , 1
Lcd Freq ; "Hz"
Start Adc
W = Getadc(7)
If W < 500 Then
Select Case W
Case 400 To 450
J = 1
Case 330 To 380
J = 2
Case 260 To 305
J = 3
Case 180 To 220
J = 4
Case 90 To 130
J = 5
End Select
End If
If J <> Y Then
Tasten_flag = 1
Exit For
End If
Loop Until Tasten_flag = 1
Case 4
Cls
Y = 4
Tasten_flag = 0
Do
Cursor Off
S = Secu
If Secu = 60 Then
Secu = 00
Minu = Minu + 1
Elseif Minu = 60 Then
Minu = 00
Hour = Hour + 1
End If
Locate 2 , 1
Lcd "Zeit = "
Locate 2 , 8
Lcd Hour ; Minu ; Secu ;
Start Adc
W = Getadc(7)
If W < 500 Then
Select Case W
Case 400 To 450
J = 1
Case 330 To 380
J = 2
Case 260 To 305
J = 3
Case 180 To 220
J = 4
Case 90 To 130
J = 5
End Select
End If
If J <> Y Then
Tasten_flag = 1
Exit For
End If
Loop Until Tasten_flag = 1
Case 5
Waitms 50
Cls
Y = 5
Tasten_flag = 0
Do
Cursor Off
Readeeprom Secu , 1
Readeeprom Minu , 10
Readeeprom Volt , 20
Readeeprom Freq , 30
Locate 1 , 1
Lcd Freq ; " Hz "
Locate 2 , 1
Lcd Secu ; " Sekunde(n) "
Locate 3 , 1
Lcd Minu ; " Minute(n) "
Locate 4 , 1
Lcd Volt ; " Volt "
Start Adc
W = Getadc(7)
If W < 500 Then
Select Case W
Case 400 To 450
J = 1
Case 330 To 380
J = 2
Case 260 To 305
J = 3
Case 180 To 220
J = 4
Case 90 To 130
J = 5
End Select
End If
If J <> Y Then
Tasten_flag = 1
Exit For
End If
Loop Until Tasten_flag = 1
End Select
End If
Loop
Isr_von_timer1:
Timer1 = 49910
Incr Secu
Incr T
Toggle Portc.7
Return
Isr_von_timer0:
Timer0 = 255
Incr F
Return
Function Tastenabfrage() As Byte
Tastenabfrage = 0
Start Adc
Ws = Getadc(7)
If Ws < 500 Then
Select Case Ws
Case 400 To 450
Tastenabfrage = 1
Case 330 To 380
Tastenabfrage = 2
Case 260 To 305
Tastenabfrage = 3
Case 180 To 220
Tastenabfrage = 4
Case 90 To 130
Tastenabfrage = 5
End Select
End If
End Function
End
wenn ich jetzt auf taste 5 drücke, dann zeigt er mir überall 0,0 an ,außer bei secunden. außerdem muss ich, wenn ich eine taste drücke mind. 200ms oder so drauf drücken, anstonsten kommt wieder die anzeige:
daten-terminal
hier koennen sie
ermittelte daten
speichern!!!
woran liegt das??
gruß
chris
Lesezeichen