' Drehzahlmesser für 4-Zylinder Motoren ' (c) formtapez (August 2003) ' ' PD0: gelbe LED ' PD5: rote LED ' PD6: Signaleingang ' PB0-PB6: 7-segment - Segment A bis G ' PD1-PD4: 7-segment - Ziffer - Select $regfile = "2313def.dat" 'AT90S2313 $crystal = 8000000 '8MHz Quarz Ddrb = &B11111111 'PortB = Ausgang Ddrd = &B0111111 'PortD = Ausgang bis auf PD6 Dim Icount As Long At &H60 Dim Wcountlo As Word At &H60 Overlay Dim Wcounthi As Word At &H62 Overlay Dim Zahl1 As Long Dim Zahl As Long Dim Temp As Integer At &H80 Dim Temp2 As Integer At &H80 Overlay Dim Frequenz As Long Dim Frequenz1 As Long Dim Freq1 As Word Dim Freq2 As Word Dim Freq3 As Word Dim Freq4 As Word Dim Freq As Word Dim Timeout As Byte Dim X(4) As Byte Dim Y As String * 4 At &H70 Overlay Dim Z(4) As Byte At &H70 Overlay Dim Test As Integer Dim Test3 As Integer Dim Zaehler As Byte Dim Impulse As Byte Timeout = 0 Impulse = 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 = 12 Then Timeout = 0 Freq = 0 Y = Str(freq) Z(1) = 0 Z(2) = 0 Z(3) = 0 Z(4) = 48 End If For Test3 = 1 To 4 'Wert sichern ..... X(test3) = Z(test3) Next Test3 For Test3 = 1 To 1024 '..... und 1024 mal Anzeigen For Zaehler = 1 To 4 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 Test3 Goto Main '************************************* '* Interrupt-Routine (Zeiten messen) * '* (wird bei jedem Impuls ausgelöst) * '************************************* Oncapture: Disable Interrupts Incr Impulse Temp = 1 'für Unterbrechung Animation Timeout = 0 If Impulse = 16 Then Impulse = 0 Wcountlo = Timer1 Timer1 = 0 Zahl1 = Wcounthi Wcounthi = 0 Zahl = Zahl1 * 65536 Zahl = Zahl + Wcountlo Frequenz = 480000000 / Zahl 'Umrechnung für 4-Zylinder Freq4 = Freq3 'gleitende Mittelwertbildung Freq3 = Freq2 Freq2 = Freq1 Freq1 = Frequenz Frequenz1 = Freq1 + Freq2 Frequenz = Freq3 + Freq4 Frequenz = Frequenz1 + Frequenz Frequenz = Frequenz / 4 Freq = Frequenz If Freq > 5999 Then Portd.0 = 1 Else Portd.0 = 0 ' gelbe LED ab 6000 U/min If Freq > 6099 Then Portd.5 = 1 Else Portd.5 = 0 ' rote LED ab 6100 U/min Y = Str(freq) If Z(4) = 0 Then 'Führende Nullen eliminieren Do Z(4) = Z(3) Z(3) = Z(2) Z(2) = Z(1) Z(1) = 0 Loop Until Z(4) > 0 End If End If Enable Interrupts Return Onoverflow: Incr Wcounthi Return