| ??? 05/17/00 04:04 Read: times |
#2711 - RE: Rotary Encoder and an 8051 |
You might also consider what how you respond when you miss a level in the sequence, perhaps some turning the dial quicker than you setup its polling rate? You could deal with this by mapping to a dibit result such as: (this is not the dial output) NC equ 00b ;= no change UP equ 01b ;= up DN equ 10b ;= down SK equ 11b ;= ignore:skipped a state So your grey-scale runs: DL NC UP DN SK --------------- 00::00:10:01:11 01::01:00:11:10 11::11:01:10:00 10::10:11:00:01 Take last and current dial position to map a result. LS::CU::RZ ---------- 00::00::NC 00::01::DN 00::10::UP 00::11::SK 01::00::UP 01::01::NC 01::10::SK 01::11::DN 10::00::DN 10::01::SK 10::10::NC 10::11::UP 11::00::SK 11::01::UP 11::10::DN 11::11::NC This leads to a datatable (16 byte mode): .dialtbl: . db nc,dn,up,sk,up,nc,sk,dn . db dn,sk,nc,up,sk,up,dn,nc Assuming you have r7 holding the last image with leading zeroes, and r6 with the current reading with leading zeros: .dowhat: . mov a,r7 ;get last . rl a ;shift two bits left . rl a . or a,r6 ;combine with current . add a,#2 ;adj for skip . movc a,@a+pc ;fetch from table . ajmp there .dialtbl: . db nc,dn,up,sk,up,nc,sk,dn . db dn,sk,nc,up,sk,up,dn,nc .there: Here you only need to test for which of the four states you are in and process it. Since a SK state is ambiguous, you'd probably treat it as a do-nothing state. You don't want to guess wrong if it might result in turning the volume up too high. If you wanted to play with your DPTR, you could exploit the JMP @A+DPTR as an ONGOTO and re-equate NC,UP,DN,SK to be the offsets into a jump table. Its good code though I avoid DPTR as much as possible: .dowhat: . mov a,r7 ;get last . rl a ;shift two bits left . rl a . or a,r6 ;combine with current . add a,#2 ;adj for skip . movc a,@a+pc ;fetch from table . ajmp there .dialtbl: . db nc,dn,up,sk,up,nc,sk,dn . db dn,sk,nc,up,sk,up,dn,nc .there: . mov dptr,#ongoto . jmp @a+dptr .ongoto: .nc equ $-ongoto . ajmp donc .up equ $-ongoto . ajmp doup .dw equ $-ongoto . ajmp dodn .sk equ $-ongoto . ajmp dosk I advise you proof everything as I'm writing this at midnight local time. :-) There may be a shorter routine, but this is respectable enough. You could filter out the NC cases with a coded quick-out, and you could screen SK as they are inversions of each other. That's the fun of coding... many ways to do everything. :-) Jay C. Box |
| Topic | Author | Date |
| Rotary Encoder and an 8051 | 01/01/70 00:00 | |
| RE: Rotary Encoder and an 8051 | 01/01/70 00:00 | |
| RE: Rotary Encoder and an 8051 | 01/01/70 00:00 | |
| RE: Rotary Encoder and an 8051 | 01/01/70 00:00 | |
| RE: Rotary Encoder and an 8051 | 01/01/70 00:00 | |
| RE: Rotary Encoder and an 8051 | 01/01/70 00:00 | |
| RE: Rotary Encoder and an 8051 | 01/01/70 00:00 | |
| RE: Rotary Encoder and an 8051 | 01/01/70 00:00 | |
| RE: Rotary Encoder and an 8051 | 01/01/70 00:00 | |
| RE: Rotary Encoder and an 8051 | 01/01/70 00:00 | |
| RE: Rotary Encoder and an 8051 | 01/01/70 00:00 | |
| RE: Rotary Encoder and an 8051 | 01/01/70 00:00 | |
| RE: Rotary Encoder,bouncing problems | 01/01/70 00:00 | |
RE: Rotary Encoder,bouncing problems | 01/01/70 00:00 |



