Reputation: 2092
I'm hoping someone can help me on this.
I made a function for an 8051 microcontroller that accepts input from a button and I'm using a cyclic buffer of 8 bits to store key states so I can make debouncing not an issue.
The code to store data in the buffer and to check for one key is here:
VALIDPRESS equ 0Fh ;0Fh = detect as valid if key held somewhat
CYCLICBUFFER equ 10h ;10h is a randomly picked value as example
mov R0,#CYCLICBUFFER ;memory location for key buffer
mov C,KEY ;KEY = GPIO pin button is attached to
mov A,@R0 ;A = data found at address CYCLICBUFFER
rlc A ;Shift in new detected value
mov @R0,A ;Store updated byte to address CYCLICBUFFER
cjne A,#VALIDPRESS,nokey ;See if buffer contains bits in right order
;If it does, the key is valid
nokey:
There's only one thing... I have very limited memory available and I think I can somehow use one bit from the 8-bit buffer to store a flag. I want that flag to represent if that specific key is allowed to be held down or to be pressed only.
I'll show in the left column how data flows into my buffer as key presses are detected. What I'd like to have happen is whats shown in the right column below.
Let x equal unknown value, and a through m represent new button scan values 1 through 13 respectively, and let Z equal the custom flag that is never allowed to be changed by the keyscan routine.
Loop count, Current data flow, Desired data flow
0 xxxxxxxx Zxxxxxxx
1 xxxxxxxa Zxxxxxxa
2 xxxxxxab Zxxxxxab
3 xxxxxabc Zxxxxabc
4 xxxxabcd Zxxxabcd
5 xxxabcde Zxxabcde
6 xxabcdef Zxabcdef
7 xabcdefg Zabcdefg
8 abcdefgh Zbcdefgh
9 bcdefghi Zcdefghi
10 cdefghij Zdefghij
11 defghijk Zefghijk
12 efghijkl Zfghijkl
13 fghijklm Zghijklm
Is there an easy way to solve this without using lots of memory or lots of clock cycles?
Upvotes: 1
Views: 153