Smitty,
Go to Darrel Taylor's Instant Interrupt Site and download DT_INTS-14.bas and ReEnterPBP.bas
In the DT_INTS-14.bas file, comment out the Highlighted line below, as shown.
Below is a bit of untested code (I don't have a 16F628 nor 2 Available Rotary Encoders) I threw together to get you started. It did compile without errors (if you made the change to DT_INTS-14.bas above), just can't actually try it in a PIC (let alone your setup). This code should allow you do keep track of both the rotary encoders regardless of what else your program is doing.Code:'**************************************************************** '* Name : DT_INTS-14.bas * '* Author : Darrel Taylor * '* Version : 0.93 BETA * '* Date : JAN 29, 2006 * '**************************************************************** '* Rev 0.93 Fixed CMIF and EEIF problem with older PIC's * '* that have the Flags in PIR1 instead of PIR2 * '* Rev 0.92 solves a "Missed Interrupt" and * '* banking switching problem * '**************************************************************** DEFINE INTHAND INT_ENTRY wsave var byte $20 SYSTEM ' location for W if in bank0 ;wsave var byte $70 SYSTEM ' alternate save location for W ' if using $70, comment out wsave1-3 ' --- IF any of these three lines cause an error ?? ---------------------------- ' Comment them out to fix the problem ---- ' -- It depends on which Chip you are using, as to which variables are needed -- wsave1 var byte $A0 SYSTEM ' location for W if in bank1 wsave2 var byte $120 SYSTEM ' location for W if in bank2 'wsave3 var byte $1A0 SYSTEM ' location for W if in bank3 ' ------------------------------------------------------------------------------
A couple of items to mention. It assumes the you have connected your rotary encoders with the "A" Pins on PORTB.4 and 6, and "B" Pins on PORTB.5 and 7. Also, you have to have pull-ups on all 4 lines. If it "sort-of" works, try switching the lines on the encoders to the opposite pins.Code:Old_Bits VAR BYTE New_Bits VAR BYTE RotEnc1_val VAR BYTE 'Connected to PORTB<4:5> RotEnc2_val VAR BYTE 'Connected to PORTB<6:7> TRISB = %11110000 RotEncDir VAR BIT '************************ ' SETUP YOUR LCD HERE!!! '************************ INCLUDE "DT_INTS-14.bas" ' Base Interrupt System INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler RBC_INT, _Rot_Encoder, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM @ INT_ENABLE RBC_INT ;RB Port Change Interrupt Old_Bits = PORTB & (%11110000) Main: LCDOUT $FE, 2,"ROT1:", DEC2 RotEnc1_val,"ROT2:", DEC2 RotEnc2_val pause 10 GOTO Main '---[RBC - interrupt handler]--------------------------------------------------- Rot_Encoder: New_Bits = PORTB & (%11110000) IF (New_Bits & %00110000) = (Old_Bits & %00110000) then No_Change_Rot1 RotEncDir = New_Bits.5 ^ Old_Bits.4 if RotEncDir = 1 then RotEnc1_val = RotEnc1_val + 1 if RotEnc1_val = 36 then RotEnc1_val = 0 ELSE RotEnc1_val = RotEnc1_val - 1 if RotEnc1_val = 255 then RotEnc1_val = 35 ENDIF No_Change_Rot1: IF (New_Bits & %11000000) = (Old_Bits & %11000000) then DoneRotEnc RotEncDir = New_Bits.7 ^ Old_Bits.6 if RotEncDir = 1 then RotEnc2_val = RotEnc2_val + 1 if RotEnc2_val = 36 then RotEnc2_val = 0 ELSE RotEnc2_val = RotEnc2_val - 1 if RotEnc2_val = 255 then RotEnc2_val = 35 ENDIF DoneRotEnc: Old_Bits = New_Bits @ INT_RETURN
I assumed you will configure you lcd on you own as needed.
Also make sure the files downloaded from Darrel Taylor are in the some directory as the main program file.
HTH,
Steve B




Bookmarks