We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]
posted on 2013/05/13 03:10:54 AM CEST
Hi,
i`m trying connect the rotary encoder ED1112S-20 to development board with PIC18F45K22,
and needed code or/and library to rotary encoder for mikroC Pro.
Please Help me.
USER Comments
posted on 2013/05/19 05:29:34 AM CEST
Hi Petko!
It's part of one of my projects that you find in the following:
-I used change notice interrupt to detect rotary encoder's pins state on turn.
-Depend on which pin you want to connect to micro some variable should be change.
-This routine has been written for PIC32, but I think you can use on other MCU's series.
-Note that you should put "Rotary1 = 0;" in your code after its value has been changed.
If you have any questions feel free to ask me!
Good luck :)
//##############################################################
char ClrPort, ModeF1, ModeR1;
int Rotary1;
unsigned long RotaryNew1, RotaryOld1;
void Rotary_Interrupt() iv IVT_CHANGE_NOTICE ilevel 5 ics ICS_AUTO {
ClrPort = PORTD;
RotaryNew1 = (PORTD & 0x40A0);
if(RotaryNew1!=RotaryOld1) {
if (ModeF1 == 0) if ((RotaryOld1 == 0x40A0) && (RotaryNew1 == 0x4020)) ModeF1 = 1;
if (ModeF1 == 1) if ((RotaryOld1 == 0x4020) && (RotaryNew1 == 0x4000)) ModeF1 = 2;
if (ModeF1 == 2) if ((RotaryOld1 == 0x4000) && (RotaryNew1 == 0x4080)) ModeF1 = 3;
if (ModeF1 == 3) if ((RotaryOld1 == 0x4080) && (RotaryNew1 == 0x40A0)) ModeF1 = 4;
if (ModeF1 == 4) {
Rotary1++;
ModeF1 = 0;
ModeR1 = 0;
}
if (ModeR1 == 0) if ((RotaryOld1 == 0x40A0) && (RotaryNew1 == 0x4080)) ModeR1 = 1;
if (ModeR1 == 1) if ((RotaryOld1 == 0x4080) && (RotaryNew1 == 0x4000)) ModeR1 = 2;
if (ModeR1 == 2) if ((RotaryOld1 == 0x4000) && (RotaryNew1 == 0x4020)) ModeR1 = 3;
if (ModeR1 == 3) if ((RotaryOld1 == 0x4020) && (RotaryNew1 == 0x40A0)) ModeR1 = 4;
if (ModeR1 == 4) {
Rotary1--;
ModeR1 = 0;
ModeF1 = 0;
}
if (!RotaryNew1.B14) {
//Write your code here... (Push button section)
}
RotaryOld1 = RotaryNew1;
}
ClrPort = PORTD;
ClrPort = PORTD;
CNIF_bit = 0;
}
void main() {
DisableInterrupts();
TRISD5_bit = 1; //Rotary encoder1 pin1
TRISD7_bit = 1; //Rotary encoder1 pin2
TRISD14_bit = 1; //Rotary encoder1 button pin
CNCON = 0x8000; //Change notice configuration register
CNEN = 0x39C000; //Change notice enable
CNPUE = 0x39C000; //Change notice pull-up enable
ClrPort = PORTD; //You should Read the port that contained change notice pins to clear its status
IPC6.CNIP0 = 1; //Change notice interrupt Priority bit
IPC6.CNIP1 = 0; //Change notice interrupt Priority bit
IPC6.CNIP2 = 1; //Change notice interrupt Priority bit
IFS1.CNIF = 0; //Change notice interrupt flag bit
IEC1.CNIE = 1; //Change notice interrupt enable bit
EnableInterrupts();
Rotary1=0;
ModeF1=0;
ModeR1=0;
}
//##############################################################
Do you want to report abuse comment ID: 730 in "rotary encoder code mikroC Pro" request.