please dont rip this site

PIC Micro Controller C Input / Output Routine


Quadrature Encoder ISR

by David Kott

struct RotaryEncoderStruct {
      int unused:4;  // RB[0:3]
      int A:1;   // RB4
      int B:1;   // RB5
      int unused2:2;  // RB6-7
};

struct RotaryEncoderStruct RotaryEncoder;

#pragma BYTE PORTB = 0x06

#pragma BYTE RotaryEncoder = 0x06 // Place structure right over PORTB at
location 0x06


USHORT g_usEncoderCount = 0;

#pragma INT_RB
void
PortBInterrupt (void)
{

      static BYTE OldPortB;
      BYTE byTemp;
      static struct RotaryEncoderStruct OldEncoder;


      if (OldPortB != (byTemp=(PORTB & 0x30))) {


      OldPortB = byTemp;

      if (RotaryEncoder.A == OldEncoder.A) {
     if (RotaryEncoder.B == RotaryEncoder.A)
    --g_usEncoderCount;
     else
    ++g_usEncoderCount;
      } else {
     OldEncoder.A = RotaryEncoder.A;
     if (RotaryEncoder.B == RotaryEncoder.A)
    ++g_usEncoderCount;
     else
    --g_usEncoderCount;
      }



     }

   // Handle more PORTB stuff here, like a button, or something.


}

Questions:


file: /techref/microchip/language/c/io/qenc-dk.htm, 2KB, , updated: 2004/8/3 04:22, local time: 2008/9/30 16:55,
TOP NEW HELP FIND: 
38.103.63.60:LOG IN
©2008 PLEASE DON'T RIP! DO: LINK / DIGG! / MAKE!

 ©2008 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it!
<A HREF="http://piclist.org/techref/microchip/language/c/io/qenc-dk.htm"> PIC C I/O Routine - Quadrature Encoder ISR</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be reviewed) Just type in the box and press the Post button. (HTML welcomed!): A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Did you find what you needed?

  PICList 2008 contributors:
o List host: MIT, Site host massmind.org, Top posters @20080930 Apptech, Jinx, Xiaofan Chen, olin piclist, Vitaliy, Alan B. Pearce, JonnyMac, William \Chops\ Westfield, Tamas Rudnai, Gerhard Fiedler,
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Shultz Electronics, Timothy Weber, on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
  'What can I do?' - SiCKO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .