Target device is 16F88, configured for 8MHz internal oscillator and internal weak pull-ups on port B (so no external resistors required)
LCD is used to indicate rotation by the form of a number which increases or decreases depending on encoder rotation.
I have also included a bargraph function just like you see on audio equipment ranging from 0 = no bars to 255 = 16 bars.
Encoder and data sheet I used can can be found here:
http://uk.rs-online.com/web/p/products/692-8471/
The encoder has three connections labelled: A (connect to port B6), B (connect to port B7) & C (connect to GND),
Flowchart works by waiting for port B to be triggered. When port B is triggered it is then checking to see if port B6 has changed. If not then nothing will happen.
If port B6 has changed, then the value of port B7 is read.
Code: Select all
B6 changed from B7 is read as Encoder is rotating
0 - 1 0 CCW
0 - 1 1 CW
1 - 0 0 CCW
1 - 0 1 CW
If display is showing 0 then after one full rotation clockwise display shows 28.
If you want display to indicate a higher number after one rotation, then change the all 1's in the Count = Count+1 to a higher value.
In the simulation the bargraph shows a y with 2 dots on the top, but with hardware the correct block is displayed.
Martin