Polling on the bs2p40
Archiver
Posts: 46,084
I am working on a project using polling on a bs2p40 with a 4x4 matrix
keypad. The rows of the keypad are connected to auxio pins 0 through 3
(physical pins 21 through 24). The program scans the 4 rows to
determine which key is depressed and stores the key number (0 through
15) in the key variable.
My first attempt was program #1, a fragment is shown below. The
debug in the bank 1 program would display the correct key number
only for row zero and zero for the other 3 rows. The key variable
was obviously not seen correctly in bank 1!
Program #2 fixed the problem. The only difference is the reversal of
the auxio and pollin commands. It appears that the pollin command
must be executed in mainio mode even if an auxio pin is actually used
for the polling.
Moving the pollin command inside the for-next loop does not work
either unless I use a sequence like:
mainio
pollin row,0
auxio
Can anyone explain what's happening here?
marylou
_________________________
PROGRAM #1 for BANK 0
' {$stamp bs2p, polltest1.bsp}
key var nib
row var nib
auxio
pollin row,0
loop:
for row = 0 to 3
' wait for poll event here
pollrun 1
pollmode 3
goto loop
________________________
PROGRAM #2 for BANK 0
' {$stamp bs2p, polltest1.bsp}
key var nib
row var nib
pollin row,0
auxio
loop:
for row = 0 to 3
' wait for poll event here
pollrun 1
pollmode 3
goto loop
________________________
PROGRAM for BANK 1
'{$stamp bs2p}
key var nib
row var nib
debug dec ? key
run 0
keypad. The rows of the keypad are connected to auxio pins 0 through 3
(physical pins 21 through 24). The program scans the 4 rows to
determine which key is depressed and stores the key number (0 through
15) in the key variable.
My first attempt was program #1, a fragment is shown below. The
debug in the bank 1 program would display the correct key number
only for row zero and zero for the other 3 rows. The key variable
was obviously not seen correctly in bank 1!
Program #2 fixed the problem. The only difference is the reversal of
the auxio and pollin commands. It appears that the pollin command
must be executed in mainio mode even if an auxio pin is actually used
for the polling.
Moving the pollin command inside the for-next loop does not work
either unless I use a sequence like:
mainio
pollin row,0
auxio
Can anyone explain what's happening here?
marylou
_________________________
PROGRAM #1 for BANK 0
' {$stamp bs2p, polltest1.bsp}
key var nib
row var nib
auxio
pollin row,0
loop:
for row = 0 to 3
' wait for poll event here
pollrun 1
pollmode 3
goto loop
________________________
PROGRAM #2 for BANK 0
' {$stamp bs2p, polltest1.bsp}
key var nib
row var nib
pollin row,0
auxio
loop:
for row = 0 to 3
' wait for poll event here
pollrun 1
pollmode 3
goto loop
________________________
PROGRAM for BANK 1
'{$stamp bs2p}
key var nib
row var nib
debug dec ? key
run 0
Comments
auxio
for row=0 to 3
pollin row,0
next
pollrun 1
pollmode 3
loop:
get 130,key 'location where interrupt inputs are stored
for auxio pins 0 to 7
debug ? key
goto loop
Regards,
Chuck
[noparse][[/noparse]Non-text portions of this message have been removed]
I tried your suggestion and it does not work in my program.
As I said in my original posting, the pollin command that references
auxio pins must be executed while the stamp is in the mainio mode. I
have not been able to make it work any other way (and I've tried).
I am not looking for a solution since I have a working program. I was
just curious as to WHY this is happening.
I'm confused about the "get 130, key" in your program. The highest
usable memory location is 126? Also, how are "interrupts inputs"
stored?
Regards, Marylou
____________________________
--- In basicstamps@y..., CHIPKEN@a... wrote:
> Program #1 is correct but you must specify after auxio the
following:
> auxio
> for row=0 to 3
> pollin row,0
> next
>
> pollrun 1
> pollmode 3
>
> loop:
> get 130,key 'location where interrupt inputs are
stored
> for auxio pins 0 to 7
> debug ? key
> goto loop
>
> Regards,
> Chuck
>
>
> [noparse][[/noparse]Non-text portions of this message have been removed]