It a real pleasure to see how generous some people can be ... Thank You, AGAIN, Mr. Henrik !
...I think I missing something ... If UP do something, If Down do something else...dont ?!
But nothing happens.
Or I wired the roller wrong ?Code:'**************************************************************** @ DEVICE pic16F628A, XT_OSC, WDT_OFF, PWRT_ON, BOD_OFF, MCLR_ON, LVP_OFF Define OSC 4 ' 4MHz CMCON = 7 ' Disable on-chip comparator, PORTA in digital mode include "alldigital.pbp" TrisA = 000000 PortB = 010000 TrisB = 000000 oldState VAR BYTE newState VAR BYTE Q_Count VAR WORD DIR VAR BIT UP CON 1 DN CON 0 Main_Loop: newState = (PortB & 100000) goto encoder if dir = up then portb.0 = 1 if dir = dn then portb.1 = 1 goto Main_Loop goto encoder if dir = up then portb.4 = 1 portb.0 = 1 endif if dir = dn then portb.4 = 0 portb.1 = 1 endif goto Main_Loop encoder: If newState <> 0 THEN If newState <> oldState THEN ' Changed from last time? Select Case oldState Case 32 If NewState = 128 THEN ' Was 1 now 4 = Up Q_Count = Q_Count + 1 DIR = UP ELSE ' Was 1 now 2 = Down Q_Count = Q_Count - 1 DIR = DN ENDIF Case 64 If NewState = 32 THEN ' Was 2 now 1 = Up Q_Count = Q_Count + 1 DIR = UP ELSE ' Was 2 now 4 = Down Q_Count = Q_Count - 1 DIR = DN ENDIF Case 128 If NewState = 64 THEN ' Was 4 now 2 = Up Q_Count = Q_Count + 1 DIR = UP ELSE ' Was 4 now 1 = Down Q_Count = Q_Count - 1 DIR = DN ENDIF END SELECT oldState = NewState ENDIF ENDIF
Here ( http://www.angelfire.com/nd/maza/kenwood.html ) it's a working variant, but in other "way" , using Atmega ...




Bookmarks