'Der superschnelle und geniale AssemblerCode für Drehgeber 'von Ulrich. Ursprünglich für 4 Encoderkanäle ausgelegt, ist er 'zur Verwendung mit Bascom auf 1 Kanal eingedampft und angepasst. 'Quelle: 'Beitrag "Re: Versetzte Rechtecksignale auswerten, kein drehgeber" ' 'Die Kanäle A/B müssen auf beide Nibbles gleich verteilt sein. 'Hier: Pinb.2 und Pinb.6 'Gegebenenfalls muss die Anzahl bzw. die Richtung der shifts 'und bitmoves(BST/BLD) bei anderen A/B-Pins angepasst werden. $regfile = "attiny861.dat " $crystal = 8000000 $hwstack = 64 $swstack = 64 $framesize = 64 'clkdiv/8 übersteuern --> div/1: Clkpr = 128 Clkpr = 0 '8MHz Waitms 1 Ddra = &b11111101 Porta = &b00000010 Ddrb = &B00011011 Portb = &B01100100 'optional serielle Ausgabe 'Open "ComA.1:128000,8,N,1,inverted" For Output As #1 Config Lcd = 16x2 Config Lcdbus = 4 Config Lcdpin = Pin , Db4 = Porta.4 , Db5 = Porta.5 , Db6 = Porta.6 , Db7 = Porta.7 , E = Porta.3 , Rs = Porta.2 Cursor Off Cls Locate 1 , 1 Lcd "Summe : " Dim Enc_summe As Integer Dim Enc_out As Integer Dim Pinb_old As Byte Dim P As Word Do $asm lds R19, {Enc_out} 'Integer 16-bit Lo_Byte lds R20, {Enc_out+1} 'Integer 16-bit Hi_Byte lds R17, {Pinb_old} '**** der aktive Kern braucht nur 16 Takte linearen Code. 'Keine Sprünge, keine Bedingungen, keine Tabelle, ... Swap R17 ' A - > B Position in R15 , Pinb sts {pinb_old},R15 eor R17,R15 ' alt EOR neu bst R17,2 bld R17,5 LSL R17 LSL R17 ' Bit nach carry -> plus CLR R15 ' R15 = 0 adc R19,R15 ' Kanal 1 adc R20,R15 ' optional 16 Bit Zähler LSL R17 ' Bit nach carry -> minus sbc R19,R15 sbc R20,R15 ' 16 Bit Zähler '**** sts {Enc_out},R19 sts {Enc_out+1},R20 $end Asm Incr P If P = 30000 Then 'Verzögerung für Lcd-Demo P = 0 'Print #1 , "Summe " ; Summe ; " Wert " ; Wert_alt ; 'Print #1 , 'Cls Enc_summe = Enc_out / 4 'Drehgeber hat 4 Imp/Rastung Locate 1 , 9 Lcd " " If Enc_summe < 0 Then Locate 1 , 9 Else Locate 1 , 10 Lcd Enc_summe End If Loop End 'Close #1
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.