|
发表于 2010-8-24 18:38:44
|
显示全部楼层
"还是自己来搞定吧! "
that's overly complicated.
the state chart actually provides you with a very simple way to read a rotary switch. if you simply read the levels of A and B, and compare the results of previous and current read, you will know 1) if the rotary switch has turned, and 2) if it turns in a particular direction.
for example, if your last read is 00 and the current read is 01, you know, per your state chart, that the rotary has turned counter-clock wise.
so you can define a 4-bit array:
const unsigned char state-chart[]={
0, //input of 00/00 is stationary
-1, //input of 00/01 -> counter clock wise
1, //00/10 -> clock wise
0, //00/11 -> invalid
1, //01/00 -> clock wise
0, //01/01 -> stationary
0, //01/10 -> invalid
-1, //01/11 -> counter clock
.....
then all you need to do in your code is to compose a unsigned char whose bit 0..1 contain the current read and bit 2..3 contain the previous read and use it to index state-chart[]. |
|