PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 08, 2010 11:51 am |
|
|
I think the reason for no answers is that we think you want us to write
the program for you.
I'll try to help, but you need to write the program.
Use the interrupt-driven keypad buffer program shown in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=42707&start=4
It will capture keys in the background, without any code in the foreground
process. All you need to do is to check if keys are in the buffer by
calling the bkbhit() routine. If it returns TRUE, then call bgetc() to get
the keys from the buffer.
You can use this idea to make your program. Initialize the keypad
buffer, as shown in the first few lines in main(), in that code.
Then you can call the delay_ms(2000) function to delay for 2 seconds.
Then you can check bkbhit() in a loop, and if there is a key, then get it
by calling bgetc(). Check if it's the key that you are looking for.
If it is, then increment a counter variable. Keep doing that until bkbhit()
shows there are no more keys in the buffer. Also, to prevent someone
from typing keys while you are checking the buffer, you could disable
interrupts.
If you want to continuously do this checking for keys in 2 seconds, then
you probably want to clear the keypad buffer before each 2 secnd period.
You need to write a clear_buffer() routine that disables interrupts, and
then sets next_in and next_out to 0x00, and then re-enable interrupts.
That way, you will have an empty buffer when you start the test.
Remember the Row pins must have pull-up resistors on them, for the
keypad driver to work. (Use 10K). |
|