PDA

View Full Version : Reaction timer using 16f877a and pbp



sphinxifm
- 14th July 2007, 13:42
i am building a project that consists of two buttons connected to a pic 16f877a that needs to have a time delay and at the end of the delay a light comes on and the button has to be pressed, the first to press their button is the winner and their led lights for 30 seconds and then goes off but the time delay needs to be a random time between 2 and 10 seconds each time the game is played. (ie not the same time delay every time) could anyone help with this problem as i have been searching through the forums but am unable to find any code for pbp that can help. i have built the circuit and can place the led's and buttons on any port. it would also be very useful if it was possible to display on a couple of 7 seg displays the time between the light coming on and the button being pressed. i will post all details of the project as soon as its completed. many thanks in advance for all/any help.

sphinxifm
- 14th July 2007, 14:04
Power On

Turn on power led (PORTA.0)

Play “WELCOME” Message (PORTB.1)

Turn On Ready led (PORTA.1)

Wait for START button (PORTB.0)

Turn Off ready led (PORTA.1)

Play game “START” message (PORTB.2)

Turn On game active led (PORTA.3)
Turn On Green led (PORTA.4)
Run random timer sequence

Play “FIRE” message (PORTB.3)
Turn off green led (PORTA.4)
Turn on Red led (PORTA.5)

Read input from p1 (PORTC.1)
Read input from p2 (PORTC.2)

On interrupt from p1 or p2 (PORTC.1 & PORTC.2)
Play “BANG” (PORTB.4)

If p1 Turn on P1 led (PORTC3)
Play “PLAYER 1 WINS” (PORTB.5)

If p2 Turn on P2 led (PORTC4)
Play “PLAYER 2 WINS” (PORTB.6)

Wait 30 seconds
Turn off p1 and p2 led (PORTC3 & PORTC4)

Goto Wait for Start Button

milestag
- 14th July 2007, 14:17
Why not start with something like this:

http://www.radioshack.com/sm-whats-a-microcontroller-basic-stamp-kit--pi-2117994.html

It will teach you basics of microcontrollers, so you can learn to write your own programs. It even includes a "reaction timer" example. Or get a beginners book on PIC BASIC, which will also have examples to get you going in the right direction.

I think many people here could write that program for you in about 20 minutes, but then what have YOU learned? If you do it yourself you will also be much more qualified to document the project. If you understand just a FEW basic commands, then this should be a very easy project.

If you run into problems, then this forum is a great place to get help. But you need to at least TRY. Not just ask for some pre-written code.

milestag
- 14th July 2007, 14:28
OK, by the time I posted, you had already sent a second post.

Your first post is an "idea".

Your second post is an "outline", not quite a flowchart or pseudocode though.

So what's the problem?? Convert what you have into actual code. Get each part working, then put it together.

Are you just looking for encouragement??

"Go do it! What are you afraid of? You can't break the PIC by trying! You don't even have a question yet. Staring at that circuit won't make it work, DO SOMETHING!"

Sorry, military training flashback ;)