On 11 June 2013 13:26, Manu Abraham wrote: > Hi, > > Rewrote the Rotary encoder for use with an 18F4550 in C18. > > I can't really make out what is wrong in there. It looks as though > everything makes sense, but the result doesn't make sense, > ie the increments/decrements, I cannot see (at least 0-9) > Change is quite random. > > The code is here: > > http://goo.gl/Qm0Re > > If someone could lend another pair of eyes, would be very helpful. > On line 66, your comment suggests that you expect enc_s to potentially be something other than 0 (zero) at this point. It won't because on line 58 it is re-initialised to 0 (zero) on every call of the interrupt. To make it behave the way you expect, on line 58 declare it as "static u8 enc_s =3D 0;". You can leave out the declaration of "read" since you're not using it any more. If you did decide to use the "read" variable for debouncing, it could (and should in order not to waste resources) be declared separately since it doesn't need to be static. The effect of the static keyword is that your initialisation to 0 will only happen on the first call, and to ensure that the variable is saved in between subsequent calls to the interrupt handler. Someone previously posted a link to the wikipedia page which probably explains this better than I just did Regards Patrick --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .