'Drehzahlmesser - InitCapture mit Timer1 'Hardware: PD6: Signaleingang ' PD1-PD4: 7-segment - Ziffer - Select ' PB0-PB6: 7-segment - Segment A bis G $regfile = "2313def.dat" $crystal = 8000000 Ddrb = &B11111111 Ddrd = &B00111111 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 Zahl2 As Long Dim Zahl As Long Dim Frequenz As Long Dim Y As String * 4 At &H70 Overlay Dim Z(4) As Byte At &H70 Overlay Dim Test As Integer Dim Zaehler As Integer On Icp1 Oncapture On Ovf1 Onoverflow Config Timer1 = Timer , Prescale = 1 , Capture Edge = Rising Enable Icp1 Enable Ovf1 Enable Interrupts Main: If Z(4) = 0 Then Z(4) = Z(3) Z(3) = Z(2) Z(2) = Z(1) Z(1) = 0 End If For Zaehler = 1 To 4 Test = Z(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 Waitms 5 Portd.zaehler = 0 Next Zaehler Goto Main Oncapture: Disable Interrupts Wcountlo = Timer1 Timer1 = 0 Zahl1 = Wcounthi Zahl2 = Wcountlo Wcounthi = 0 Zahl = Zahl1 * 65536 Zahl = Zahl + Zahl2 Frequenz = 120000000 / Zahl ' Drehzahl (Umdr./min. bei 4-Taktern) Y = Str(frequenz) Enable Interrupts Return Onoverflow: Incr Wcounthi Return End