An extensive review of rotary encoders (Incremental and Absolute) is provided in this video. Debouncing, using interrupts, binary and gray-code encoding, and other details of the rotary encoders are discussed in this video.
Demo code can be downloaded from the following link: