'-------------------------------------------------------------- ' Stoppuhr - Programm '-------------------------------------------------------------- $regfile = "m8def.dat" $crystal = 10000000 $hwstack = 32 $swstack = 10 $framesize = 40 'Ports konfigurieren Config Portd = &B11110000 Config Portc = &B00011111 Config Portb = &B00000000 'Interrupts konfigurieren Config Int1 = Low Level Config Int0 = Low Level On Int1 Uhrstart On Int0 Uhrstop On Timer0 Tim0over On Compare1a Timerirq 'Variablen definieren Dim I As Byte Dim Dis As Byte Dim Disa(6) As Byte Dim D1 As Bit Dim D2 As Bit Dim D3 As Bit Dim D4 As Bit Dim D5 As Bit Dim P1 As Bit Dim P2 As Bit Dim P3 As Bit Dim P4 As Bit Dim P5 As Bit Dim P6 As Bit Dim P As Bit Dim Rel As Byte Dim Led As Bit Dim Dipco As Byte Dim Modus As Byte Dim A As Byte Dim B As Byte Dim C As Byte Dim D As Byte Dim Ms As Byte Dim Hs As Byte Dim Zs As Byte Dim S1 As Byte Dim S2 As Byte Dim M1 As Byte Dim M2 As Byte Dim H1 As Byte Dim H2 As Byte Dim Zaehler As Long Dim Uhrmod As Byte Dim D2flag As Bit Dim D3flag As Bit Dim Zaehlflag As Bit Dim Tim0multi As Integer Dim Zto As Integer Dim Strx As String * 6 Dim Sdis As String * 1 Dim X As Byte Dim Ix As Byte Dim Strl As Byte Dim Ztoms As Long Zto = 40 Dim D0flag As Bit Dim D1flag As Bit Dim Uhrflag As Bit Dim Ccfgflag As Bit '===================== ' Modusabfrage '===================== Modusabfrage: Gosub Leer Gosub Pnull Select Case Modus 'Anzeige aus Case 0 'Countdown-Zähler Case 1 Gosub Null Gosub Uhrkonfig Uhrmod = 5 M2 = 3 'Uhrstart1-Stop2 Case 2 Gosub Null Gosub Uhrkonfig Uhrmod = 1 Enable Int1 'Uhrstart1-Stop2 One Shot Case 3 Gosub Null Gosub Uhrkonfig Uhrmod = 1 Enable Int1 'Uhrstart1-Stop2 automatisches Rücksetzen nach 2 Sekunden Case 4 Gosub Null Gosub Uhrkonfig Uhrmod = 1 Enable Int1 'Uhr läuft wenn 1 offen Case 5 Gosub Null Gosub Uhrkonfig Uhrmod = 1 Enable Int1 'Zähler 1plus 2minus Case 6 Gosub Null 'Zähler wenn Impuls in zto 1-2 Case 7 Gosub Null Enable Interrupts Enable Timer0 'zto-Einstellung Case 8 Gosub Null Led = 1 Case 9 Disa(2) = 12 Disa(3) = 9 Disa(4) = 0 Disa(5) = 11 Case 10 Disa(2) = 12 Disa(3) = 0 Disa(4) = 1 Disa(5) = 11 Case 11 Disa(2) = 12 Disa(3) = 1 Disa(4) = 1 Disa(5) = 11 Case 12 Disa(2) = 12 Disa(3) = 2 Disa(4) = 1 Disa(5) = 11 Case 13 Disa(2) = 12 Disa(3) = 3 Disa(4) = 1 Disa(5) = 11 Case 14 Disa(2) = 12 Disa(3) = 4 Disa(4) = 1 Disa(5) = 11 Case 15 Disa(2) = 12 Disa(3) = 5 Disa(4) = 1 Disa(5) = 11 Case Else End Select '=================== ' Programm '=================== Displayschleife: Do 'Dip-Codierer abfragen A = Pinb.0 B = Pinb.1 C = Pinb.2 D = Pinc.5 B = B * 2 C = C * 4 D = D * 8 Dipco = A + B Dipco = Dipco + C Dipco = Dipco + D Dipco = 15 - Dipco If Dipco <> Modus Then Disable Interrupts Disable Int1 Disable Int0 Disable Timer0 Disable Compare1a Stop Timer0 Stop Timer1 Uhrflag = 0 D0flag = 0 D1flag = 0 D2flag = 0 D3flag = 0 Ccfgflag = 0 Tim0multi = 0 Config Int1 = Low Level ''' Zaehler = 0 '''Zähler wird gespeichert Gosub Uhrnull Rel = 0 Led = 0 Modus = Dipco Goto Modusabfrage End If Select Case Modus 'Countdown-Zähler Case 1 Gosub Uhrmod If Ccfgflag = 0 Then Led = 1 Gosub Countconfig Else Led = 0 End If If Uhrflag = 0 And Pind.3 = 1 Then Enable Int1 'Stoppuhr Kanal 1 Start, Kanal 2 Stop Case 2 Gosub Uhrmod If Uhrflag = 0 And Pind.3 = 1 Then Enable Int1 'Stoppuhr Kanal 1 Start, Kanal 2 Stop - One Shot Case 3 Gosub Uhrmod 'Stoppuhr Kanal 1 Start, Kanal 2 Stop - Automatisches Rücksetzen Case 4 Gosub Uhrmod If Tim0multi >= 40 And Pind.3 = 1 Then Disable Timer0 Stop Timer0 Enable Int1 Tim0multi = 0 End If 'Stoppuhr Kanal 1 Offenzeit Case 5 Gosub Uhrmod 'Zähler Kanal 1 Plus, Kanal 2 Minus Case 6 If Pind.3 = 0 And D3flag = 0 Then D3flag = 1 Gosub Zaehlerplus Elseif Pind.2 = 0 And D2flag = 0 Then D2flag = 1 Gosub Zaehlerminus End If If Pind.3 = 1 And D3flag = 1 Then D3flag = 0 If Pind.2 = 1 And D2flag = 1 Then D2flag = 0 Gosub Zaehlmod 'Zählerplus wenn Kanal 1 und 2 nacheinander bis 1/2 Sek Case 7 If Pind.3 = 0 And D3flag = 0 And Pind.2 = 1 Then Config Timer0 = Timer , Prescale = 1024 Tim0multi = 0 D3flag = 1 Elseif Pind.2 = 0 And Tim0multi < Zto And D3flag = 1 And Zaehlflag = 0 Then Stop Timer0 Zaehlflag = 1 D2flag = 0 Gosub Zaehlerplus Elseif Tim0multi >= Zto And Pind.3 = 1 Then Stop Timer0 D3flag = 0 Elseif Pind.2 = 1 And Pind.3 = 1 And Zaehlflag = 1 Then Zaehlflag = 0 D3flag = 0 End If Gosub Zaehlmod 'timeout-Einstellung in 1/40s (schnelllauf einarbeiten) Case 8 If Pind.1 = 0 And D1flag = 0 And Pind.0 = 1 And Zto < 8000 Then D1flag = 1 Zto = Zto + 10 Elseif Pind.0 = 0 And D0flag = 0 And Pind.1 = 1 And Zto > 10 Then D0flag = 1 Zto = Zto - 10 End If If Pind.1 = 1 And D1flag = 1 Then D1flag = 0 If Pind.0 = 1 And D0flag = 1 Then D0flag = 0 Gosub Timoutmod Case Else End Select 'Multiplexer (15=Leerlauf) For I = 0 To 13 'Auswahl der Displaystellen nach Ms Portc = &B00001111 Select Case I Case 0 'Rechte Displaystelle Portd = &B10110000 Dis = Disa(1) P = P1 Case 1 If D1 = 1 Then Portd = &B10010000 Else Portd = 0 End If Case 2 Portd = &B10100000 Dis = Disa(2) P = P2 Case 3 If D2 = 1 Then Portd = &B10000000 Else Portd = 0 End If Case 4 Portd = &B00110000 Dis = Disa(3) P = P3 Case 5 If D3 = 1 Then Portd = &B00100000 Else Portd = 0 End If Case 6 Portd = &B00010000 Dis = Disa(4) P = P4 Case 7 If D4 = 1 Then Portd = &B11010000 Else Portd = 0 End If Case 8 Portd = &B11100000 Dis = Disa(5) P = P5 Case 9 If D5 = 1 Then Portd = &B11000000 Else Portd = 0 End If Case 10 'linke Displaystelle Portd = &B11110000 Dis = Disa(6) P = P6 Case 11 'Relais aus If Rel = 0 Then Portd = &B01010000 Else Portd = 0 End If Case 12 'Relais an If Rel = 1 And Tim0multi < 80 Then Portd = &B01110000 Elseif Rel = 1 And Tim0multi > 80 Then Rel = 0 Stop Timer0 Else Portd = 0 End If Case 13 'Led If Led = 1 Then Portd = &B01000000 Else Portd = 0 End If Case 14 Case 15 Case Else End Select 'Segementanzeigen schreiben Select Case Dis 'Anzeige des Wertes Case 0 If P = 0 Then Portc = &B00000000 Else Portc = &B00010000 End If Case 1 If P = 0 Then Portc = &B00001000 Else Portc = &B00011000 End If Case 2 If P = 0 Then Portc = &B00000001 Else Portc = &B00010001 End If Case 3 If P = 0 Then Portc = &B00001001 Else Portc = &B00011001 End If Case 4 If P = 0 Then Portc = &B00000010 Else Portc = &B00010010 End If Case 5 If P = 0 Then Portc = &B00001010 Else Portc = &B00011010 End If Case 6 If P = 0 Then Portc = &B00000011 Else Portc = &B00010011 End If Case 7 If P = 0 Then Portc = &B00001011 Else Portc = &B00011011 End If Case 8 If P = 0 Then Portc = &B00000100 Else Portc = &B00010100 End If Case 9 If P = 0 Then Portc = &B00001100 Else Portc = &B00011100 End If Case 10 'Leere Anzeige If P = 0 Then Portc = &B00001111 Else Portc = &B00011111 End If Case 11 'klammer links If P = 0 Then Portc = &B00000101 Else Portc = &B00010101 End If Case 12 'klammer rechts If P = 0 Then Portc = &B00001101 Else Portc = &B00011101 End If Case 13 't If P = 0 Then Portc = &B00000111 Else Portc = &B00010111 End If End Select Waitus 850 Next I Loop End '================== ' Subroutinen '================== Leer: For I = 1 To 6 Disa(i) = 10 Next I Dis = 10 D2flag = 0 D3flag = 0 Zaehlflag = 0 Return Null: For I = 1 To 6 Disa(i) = 0 Next I Dis = 0 Return Uhrnull: Ms = 0 Hs = 0 Zs = 0 S1 = 0 S2 = 0 M1 = 0 M2 = 0 H1 = 0 H2 = 0 Return Pnull: P1 = 0 P2 = 0 P3 = 0 P4 = 0 P5 = 0 P6 = 0 D1 = 0 D2 = 0 D3 = 0 D4 = 0 D5 = 0 Return Zaehlerplus: Incr Zaehler If Zaehler = 1000000 Then Zaehler = 0 Return Zaehlerminus: If Zaehler > 0 Then Decr Zaehler Return Tim0over: Incr Tim0multi Return Uhrkonfig: Enable Interrupts Compare1a = 1241 Return Countconfig: If Pind.1 = 0 And D1flag = 0 And Pind.0 = 1 And M2 < 6 Then D1flag = 1 If M2 = 0 And M1 < 5 Then M1 = M1 + 1 Else M1 = M1 + 5 End If If M1 = 10 Then M1 = 0 M2 = M2 + 1 End If Elseif Pind.0 = 0 And D0flag = 0 And Pind.1 = 1 Then D0flag = 1 If M2 = 0 And M1 < 6 And M1 > 1 Then M1 = M1 - 1 Elseif M1 > 4 Then M1 = M1 - 5 Elseif M2 > 0 Then M1 = M1 + 5 If M1 > 9 Then M1 = M1 - 10 M2 = M2 - 1 End If End If If Pind.1 = 1 And D1flag = 1 Then D1flag = 0 If Pind.0 = 1 And D0flag = 1 Then D0flag = 0 Return Uhrstart: Disable Int1 Select Case Modus Case 4 Gosub Uhrnull Uhrmod = 1 Enable Compare1a Config Timer1 = Timer , Prescale = 8 , Compare A No_output = Disconnect Uhrflag = 1 Enable Int0 Case 5 If Uhrflag = 1 Then Uhrflag = 0 Disable Compare1a Stop Timer1 Config Int1 = Low Level Else Uhrflag = 1 Enable Compare1a Config Timer1 = Timer , Prescale = 8 , Compare A No_output = Disconnect Config Int1 = Rising Waitus 600 End If Enable Int1 Case Else Enable Compare1a Config Timer1 = Timer , Prescale = 8 , Compare A No_output = Disconnect Uhrflag = 1 Enable Int0 End Select Return Uhrstop: Disable Compare1a Stop Timer1 Uhrflag = 0 Disable Int0 If Modus = 4 Then Config Timer0 = Timer , Prescale = 1024 Enable Timer0 End If Return Zaehlmod: P4 = 1 Strx = Str(zaehler) Strl = Len(strx) For I = 1 To 6 Ix = I - 1 X = Strl - Ix Sdis = Mid(strx , X , 1) Disa(i) = Val(sdis) Next I Return Timoutmod: Ztoms = Zto * 26 P4 = 1 Strx = Str(ztoms) Strl = Len(strx) For I = 1 To 6 Ix = I - 1 X = Strl - Ix Sdis = Mid(strx , X , 1) Disa(i) = Val(sdis) Next I Return Uhrmod: Gosub Pnull Select Case Uhrmod Case 1 Disa(1) = Ms Disa(2) = Hs Disa(3) = Zs Disa(4) = S1 Disa(5) = S2 Disa(6) = M1 D5 = 1 P4 = 1 Case 2 Disa(1) = Hs Disa(2) = Zs Disa(3) = S1 Disa(4) = S2 Disa(5) = M1 Disa(6) = M2 P3 = 1 D4 = 1 Case 3 Disa(1) = Zs Disa(2) = S1 Disa(3) = S2 Disa(4) = M1 Disa(5) = M2 Disa(6) = H1 P2 = 1 D5 = 1 D3 = 1 Case 4 Disa(1) = S1 Disa(2) = S2 Disa(3) = M1 Disa(4) = M2 Disa(5) = H1 Disa(6) = H2 D4 = 1 D2 = 1 Case 5 Disa(1) = 10 Disa(2) = S1 Disa(3) = S2 Disa(4) = M1 Disa(5) = M2 Disa(6) = 10 D3 = 1 End Select Return Timerirq: Timer1 = 0 If Modus = 1 Then Ccfgflag = 1 If Ms > 0 Then Decr Ms Else Ms = 9 If Hs > 0 Then Decr Hs Else Hs = 9 If Zs > 0 Then Decr Zs Else Zs = 9 If S1 > 0 Then Decr S1 Else S1 = 9 If S2 > 0 Then Decr S2 Else S2 = 5 If M1 > 0 Then Decr M1 Else M1 = 9 If M2 > 0 Then Decr M2 Else Disable Compare1a Stop Timer1 Disable Int0 Disable Int1 Rel = 1 Config Timer0 = Timer , Prescale = 1024 Enable Timer0 Tim0multi = 0 Uhrflag = 0 M1 = 0 S2 = 0 S1 = 0 End If End If End If End If End If End If End If Else Incr Ms If Ms = 10 Then Ms = 0 Incr Hs End If If Hs = 10 Then Hs = 0 Incr Zs End If If Zs = 10 Then Zs = 0 Incr S1 End If If S1 = 10 Then S1 = 0 Incr S2 End If If S2 = 6 Then S2 = 0 Incr M1 End If If M1 = 10 Then M1 = 0 Incr M2 If Uhrmod = 1 Then Uhrmod = 2 End If If M2 = 6 Then M2 = 0 Incr H1 If Uhrmod = 2 Then Uhrmod = 3 End If If H1 = 10 Then H1 = 0 Incr H2 If Uhrmod = 3 Then Uhrmod = 4 End If If H2 = 100 Then H2 = 0 End If End If Return End 'end program