我经常用到编码器 看下我程序:单片机是用的三星的(1MS扫描一次)I/O是cd1port1.1,cd1port2.7自己定义的 cd1scan: sb1 ld r0,encflag BTJRF cd1canfirst,r0.0 ldb r1,cd1port1.1 BTJRF cd1scanout,r1.0 and encflag,#11111110b BTJRF cd1add,r0.1 ldb R1,cd1port2.7 BTJRT cd1scanout,r1.0 or encflag,#04h and encflag,#11110111b ;dec tempo jr cd1scanout cd1add: ldb R1,cd1port2.7 BTJRF cd1scanout,r1.0 or encflag,#04h or encflag,#08h ;inc tempo jr cd1scanout cd1canfirst: ldb r1,cd1port1.1 BTJRT cd1scanout,r1.0 or encflag,#00000011b ldb r1,cd1port2.7 BTJRT cd1scanout,r1.0 and encflag,#11111101b cd1scanout: ret |