CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How many times I press the button?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nemero16



Joined: 21 Nov 2009
Posts: 19

View user's profile Send private message

How many times I press the button?
PostPosted: Wed Jul 07, 2010 3:21 pm     Reply with quote

Hi I am working with a 4x4 keyboard that sends input to a PIC18F using this configuration:
Code:

char readkey()
{ char c;
     
     output_low(PIN_C1);
     output_low(PIN_C2);
     output_low(PIN_C3);
    output_high(PIN_C0);
       
     if(input(PIN_C4))
     { c='1';
         return (c);
     }
     
     if(input(PIN_C5))
     { c='4';
         return (c); 
     }
     
     if(input(PIN_C6))
     { c='7';
         return (c);   
     }
     
     if(input(PIN_C7))
     { c='*';
         return (c);
     }
    output_low(PIN_C0); 
    output_low(PIN_C0);
    output_low(PIN_C2);
    output_low(PIN_C3);
    output_high(PIN_C1);
       
     if(input(PIN_C4))
     { c='2';
         return (c);
     }
     
     if(input(PIN_C5))
     { c='5';
         return (c);
     }
     
     if(input(PIN_C6))
     { c='8';
         return (c);
     }
     
     if(input(PIN_C7))
     { c='0';
         return (c);
     }
     output_low(PIN_C1);
     output_low(PIN_C0);
     output_low(PIN_C1);
     output_low(PIN_C3);
     output_high(PIN_C2);
       
     if(input(PIN_C4))
     { c='3';
         return (c); 
     }
     
     if(input(PIN_C5))
     { c='6';
         return (c);
     }
     
     if(input(PIN_C6))
     { c='9';
         return (c);
     }
     
     if(input(PIN_C7))
     { c='#';
         return (c);
     }
     output_low(PIN_C2); 
     output_low(PIN_C0);
     output_low(PIN_C1);
     output_low(PIN_C2);
     output_high(PIN_C3);
       
     if(input(PIN_C4))
     { c='A';
         return (c);
     }
     
     if(input(PIN_C5))
     { c='B';
         return (c);
      }
     
     if(input(PIN_C6))
     { c='C';
         return (c);
      }
     
     if(input(PIN_C7))
     { c='D';
         return (c);
      }
    output_low(PIN_C3);
        c='\0';
        return (c);
}


I would like to add a function that reads how many times in a time of 2 seconds you press a certain button... for example PIN_C4... and the value of how many times I press the button is returned as char. How can I do this?
nemero16



Joined: 21 Nov 2009
Posts: 19

View user's profile Send private message

PostPosted: Thu Jul 08, 2010 11:07 am     Reply with quote

no one knows help me?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 08, 2010 11:51 am     Reply with quote

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).
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group