Код так код.
Вот:
Код
;
;===============================================================================
biphali: /////////// bi-phase driver
/// calls from main in fast cycle
///
/// 0 forward 1-0-2
/// 1 2 backward 2-0-1
/// 3 so, incr/decr nodes shifted in space. Can be stored in bits 0,1 of biphase
/// until 2->3 or 3->2 to remove this shift.
.equ CT_B1 = $80
.equ CT_B2 = $40
ldi tmp1,CT_B1 | CT_B2
sbis BIPORT-PIN,BIPHA cbr tmp1,CT_B2
sbis BIPORT-PIN,BIPHB cbr tmp1,CT_B1
eor tmp1,biphase ; <1> = BaBb 0 0 0 0 0 0
cpi tmp1,CT_B2 brlo biret;/// return if B1B2 readed same as prev. saved
eor tmp1,biphase ; restore <1>
lsr biphase lsr biphase
or tmp1,biphase cbr tmp1,3
mov biphase,tmp1 ; aabbcc00 phase history
lds tmp2,bico
cpi tmp1,$48 brne bidro; 01-00-10 00 102 forward
lds tmp1,biforw add tmp2,tmp1 rjmp bdsa
bidro: cpi tmp1,$84 brne biret; 10-00-01 00 201 backward
lds tmp1,biforw sub tmp2,tmp1
bdsa: sts bico,tmp2
biret: ret
biphali вызывается часто, чаще, чем крутится енкодер. Изменяет bico (байт).
Чаще, чем переполняется bico нужно вызывать подпрограмму которая это bico
прибавляет к счётчику (у меня 4-байтный) и обнуляет bico.
Сообщение отредактировал Maik-vs - Mar 20 2014, 04:00