hallo,
Ik ben bezig om een rotary encoder uit te lezen, en heb de volgende code gebruikt
Device = 18F452
XTAL = 20
ALL_DIGITAL = 1
PORTB_PULLUPS = 1
include "poorten.inc"
Symbol GIE = INTCON.7
Symbol INT0IF = INTCON.1
Dim KnobPos As Byte ' The knobs last known position
Dim MaxPos As Byte ' Set how far KnobPos is allowed to count. Max is 255
Dim Dent As Bit ' If set, the knob is currently in a dent position
Dim Direction As Bit ' If set, means rotation in one direction, otherwise the other...
ON_INTERRUPT HWINT
'Skip over interrupt routines
GoTo Start
'**************************************************************************
HWINT:
If Dent = 0 Then GoTo INTEND 'No need for analysis unless main loop has set this bit
Direction = PORTB.1 ' A simple way to determine direction of rotation
Dent = 0 ' Semafor to tell the main loop that a movement has occured
INTEND:
Clear INT0IF ' Restore pin 1 interrupt flag
Context Restore ' Interrupt handler end here
'**************************************************************************
Start:
' General interrupt settings
Clear IPR1 ' Enable low priority for
Clear IPR2 ' all peripheral interupts
Set RCON.7 ' ENABLE INTERRUPT PRIORITY HANDLING
Clear INTCON2.7 ' WEAK PULL UP'S ON PORT B
' PortB.0 setup
Clear INTCON2.6 ' INTEDG0 = 0 interrupt on falling edge PortB.0
Set INTCON.4 ' INT0IE = 1 enable PortB.0 interrupts
Clear INT0IF ' INTCON.1 = 0 clear the flag to start with
' Set up initial value for variables
MaxPos = 255 ' Set the maximum counter value for knob position
KnobPos = 128 ' Set initial knob value
Dent = 0 ' This makes for an initial run through the main loop
Print At 2, 1, "Turn that knob!"
While 1 > 0
DelayMS 2 ' A delay to minimize the "slide noice" from the quad
If PORTB = 255 And Dent = 0 Then ' The quad has returned to a dent position
If Direction = 1 Then ' Direction as set in the interrupt handler
If KnobPos < MaxPos Then Inc KnobPos ' Only increment if not yet max
Else
If KnobPos > 0 Then Dec KnobPos ' Don't go below zero
End If
Print At 1, 1, DEC3 KnobPos
Dent = 1 ' Indicate that we have returned to a dent position
Set GIE ' Enable global interrupts
End If
Wend
Het uitlezen gaat goed allen , ik moet de knop twee keer draaaien voordat die omhoog of omlaag gaat.
Nu is mijn vraag, of dat er iemand is die mij kan helpen om dit optelossen?
Of dat er een code heb die gebruikt kan worden bij de alps encoder die bij conrad verkocht word.
Ik hoop dat er iemand is die mij hierbij kan helpen.
De code is geschreven met proton.