Hallo Werner,
danke für den Tip werde mich gleich mal umschauen.
@Alle
stimmt der Code den jetzt? (Also das die Anzeigen nichts mehr anzeigen wenn an pinb.7 ein LOW Signal anliegt)
Code:
' Hardware:
' ---------
' PD0: gelbe LED (ab 6250 Umdr./min.)
' PD6: Signaleingang
' PB0-PB6: 7-segment - Segment A bis G
' PD1-PD5: 7-segment - Ziffer - Select
' PB7: Eingang (Anzeige Tot)
$regfile = "2313def.dat" 'AT90S2313
$crystal = 8000000 '8MHz Quarz
Ddrb = &B01111111 'PortB = Ausgang
Ddrd = &B0111111 'PortD = Ausgang bis auf PD6
portd = &B10000000 'Pullup von Pinb.7 Aktivieren
Pinb.7 alias herzeigen
Dim Icount As Long At &H60
Dim Wcountlo As Word At &H60 Overlay
Dim Wcounthi As Word At &H62 Overlay
Dim Temp As Integer At &H80
Dim Temp2 As Integer At &H80 Overlay
Dim Y As String * 5 At &H70
Dim Z(5) As Byte At &H70 Overlay
Dim Frequenz As Long
Dim Freq As Word
Dim Freq1 As Word
Dim Freq2 As Word
Dim Timeout As Byte
Dim Impulse As Byte
Dim X(5) As Byte
Dim Test As Integer
Dim Test2 As Integer
Dim Zaehler As Byte
Timeout = 0
On Icp1 Oncapture
On Ovf1 Onoverflow
Config Timer1 = Timer , Prescale = 8 , Capture Edge = Rising
Enable Icp1
Enable Ovf1
Enable Interrupts
'*******************
'* Start-Animation *
'*******************
Do
Portb = 1
Portd = 2
Waitms 50
Portd = 4
Waitms 50
Portd = 8
Waitms 50
Portd = 16
Waitms 50
Portb = 2
Waitms 50
Portb = 64
Waitms 50
Portd = 8
Waitms 50
Portd = 4
Waitms 50
Portd = 2
Waitms 50
Portb = 16
Waitms 50
Portb = 8
Waitms 50
Portd = 4
Waitms 50
Portd = 8
Waitms 50
Portd = 16
Waitms 50
Portb = 4
Waitms 50
Portb = 64
Waitms 50
Portd = 8
Waitms 50
Portd = 4
Waitms 50
Portd = 2
Waitms 50
Portb = 32
Waitms 50
Loop Until Temp2 = 1 'Bis zum 1. Impuls
'******************************************
'* Hauptschleife - LED-Anzeigen ansteuern *
'******************************************
Main:
Incr Timeout 'Bei Timeout: 0 U/min.
If Timeout = 10 Then
Timeout = 10
Freq = 0
Y = Str(freq)
Z(1) = 0
Z(2) = 0
Z(3) = 0
Z(4) = 0
Z(5) = 48
End If
For Test2 = 1 To 5 'Wert sichern .....
X(test2) = Z(test2)
Next Test2
'******************************************
'* Anzeigen an *
'******************************************
if herzeigen = 1 Then 'Wenn herzeigen = 1 dann...
For Test2 = 1 To 400 '..... und 400 mal Anzeigen
For Zaehler = 1 To 5
Test = X(zaehler)
Select Case Test
Case 48 : Portb = 63
Case 49 : Portb = 6
Case 50 : Portb = 91
Case 51 : Portb = 79
Case 52 : Portb = 102
Case 53 : Portb = 109
Case 54 : Portb = 125
Case 55 : Portb = 39
Case 56 : Portb = 127
Case 57 : Portb = 111
Case Else : Portb = 0
End Select
Portd.zaehler = 1
Waitus 100 'Zeit für jede Anzeige
Portd.zaehler = 0
Next Zaehler
Next Test2
'******************************************
'* Anzeigen aus *
'******************************************
Else 'Wenn herzeigen = 0 Anzeigen aus
Portb = 0
Portd = 0
END IF
Goto Main
'*************************************
'* Interrupt-Routine (Zeiten messen) *
'* (wird bei jedem Impuls ausgelöst) *
'*************************************
Oncapture:
Disable Icp1
Incr Impulse
If Impulse = 8 Then
Impulse = 0
Timeout = 0
Wcountlo = Timer1
Timer1 = 0
Frequenz = 240000000 / Icount 'Umrechnung für 4-Zylinder
Wcounthi = 0
Freq2 = Freq1
Freq1 = Frequenz
Frequenz = Freq1 + Freq2
Frequenz = Frequenz / 2
Freq = Frequenz
If Freq > 5999 Then Portd.0 = 1 'Wenn Drehzahl über 5999 LED an
if Freq < 4000 Then Portd.0 = 0 'Wenn Drehzahl unter 4000 LED aus
If Freq < 150 Then
Freq = 0
Y = Str(freq)
Z(1) = 0
Z(2) = 0
Z(3) = 0
Z(4) = 0
Z(5) = 48
Else
Y = Str(freq)
If Z(5) = 0 Then 'Führende Nullen eliminieren
Do
Z(5) = Z(4)
Z(4) = Z(3)
Z(3) = Z(2)
Z(2) = Z(1)
Z(1) = 0
Loop Until Z(5) > 0
End If
End If
End If
End If
Temp = 1
Enable Icp1
Return
Onoverflow:
Incr Wcounthi
Return
Lesezeichen