Hi. I am trying to make this Rotary Encoder work with DT-INTS on a 16F1827 device.
It gets once in the interrupt routine and never seem to exit.
Here is the code so far driving me crazy.
Code:
ASM
__config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_ON & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__config _CONFIG2, _WRT_OFF & _PLLEN_ON & _LVP_OFF & _STVREN_OFF & _BORV_25
ENDASM
DEFINE OSC 32
OSCCON= %11110000 'PLL enabled, Internal RC-8MHz
' Set LCD Data port
DEFINE LCD_DREG PORTA
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 0
' Set LCD Register Select port
DEFINE LCD_RSREG PORTA
' Set LCD Register Select bit
DEFINE LCD_RSBIT 4
' Set LCD Enable port
DEFINE LCD_EREG PORTB
' Set LCD Enable bit
DEFINE LCD_EBIT 3
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
' Set command delay time in us
DEFINE LCD_COMMANDUS 1500
' Set data delay time in us
DEFINE LCD_DATAUS 44
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
'Initializing Registers
PORTB = 0:PORTA = 0
TRISB = $33
TRISA = 0
ADCON0 = 0
ADCON1 = 0
ANSELA = 0
ANSELB = 0
INTCON = $88 ' Binary 10001000
IOCBP=$30
IOCBN=$30
OPTION_REG = 0
WPUB=$33
eeprom 0,[2,0,3,1,1,3,0,2]
led var portb.4
Flag var bit
wsave VAR BYTE $70 SYSTEM ' alternate save location for W
Q_New var Byte
Q_Old var byte
M_Count var byte [4]
P_Count var byte [4]
Q_Count var word
temp var byte
clear
For Q_Old = 0 to 3
Read Q_Old,M_Count[Q_Old]
Read Q_Old + 4,P_Count[Q_Old]
Next Q_Old
Q_Count = 0
Q_New = 0
Q_Old = 0
Flag = 0
ASM
INT_LIST macro ; IntSource, Label, Type, Resetflag?
INT_Handler IOC_INT, _Encoder, pbp, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE IOC_INT ; enable external (INT) interrupts
'---------------------------- Initialize LCD ----------------------------
Lcdout $fe, 1 ' Clear LCD screen
Lcdout "System Ready" ' Display message
Pause 500 ' Wait .5 second
Q_Count=50
Goto Main_Loop
Encoder: ' ISR
Q_New = PortB.5 + PortB.5 + PortB.4 ' get port status
If M_Count[Q_Old] = Q_New then ' if M_Count code satisfied then minus
temp=temp+1
if temp=4 then
temp=0
Q_Count = Q_Count - 1
Flag = 1 ' set flag to true to update display
endif
goto Q_Skip
endif
If P_Count[Q_Old] = Q_New then ' if M_Count code satisfied then plus
temp=temp+1
if temp=4 then
temp=0
Q_Count = Q_Count + 1
Flag = 1
endif ' set flag to true to update display
endif
Q_Skip:
Q_Old = Q_New
toggle portb.6 ' update Q_Old Byte
@ INT_RETURN
Main_Loop:
if Flag = 1 then
Lcdout $fe, 1 ' Clear LCD screen
Lcdout dec Q_Count ' Display encoder position (counts)
Flag = 0 ' reset flag to false, display updated
endif
pause 100
goto Main_Loop
Thanks,
Ioannis
Bookmarks