Sie sind auf Seite 1von 3

A Practical Application Using the multiplexed seven-segment display and timing routines (modied a little) from the previous

labs, design (the software for) and build a human reaction time measurement device. Here are the specications: It will have two SPST switches (one, SW2, is connected to the MRST input.) SW2 is optional. The Register B PullUps will have to be enabled (RBPU). It will have an LED (connected to port E pin 0). The seven-segment displays will be connected as in the previous lab. Operation of the circuit is as follows: 1 On reset, the display should be o. 2 The application should wait for SW1 to be pressed. 3 When SW1 is pressed, the display should go o (if on). 4 The application should then wait a random amount of time (not less than 1 second and not more than 10 seconds), then turn the LED on. It should then start keeping the time. 5 When SW1 is pressed again, the LED should go o, there should be a one-second delay, and then the display should display the time, in hundredths of a second, between the time the LED went on and SW1 was pressed for the second time. For times larger than .99 seconds or less than 0.1 seconds, the display should display a blinking 00 (1-second period) indicating an invalid result. 6 The application should then wait for SW1 to be released. 7 Repeat from step 2. SW2 is a reset switch. It will facilitate testing, but you should not use it to make your circuit operate in other words, you cannot replace SW1 with SW2 anywhere in the above operation description. The random time should be a value, in milliseconds, uniformly distributed in the range 1000 to 9999. To generate this, use the following code:

t = random(); // where random returns a pseudorandom number from 0 to 6553 t = t % 9000; // gives a number from 0 to 8999 t += 1000; // now t is a number from 1000 to 9999. Notice that this requires a clock that measures the time interval in hundredths of a second, (accurate to the nearest .01 seconds) not in seconds, so youll have to modify the timer from the previous lab. You will need to know that the minimum human reaction time (about .2 second) is roughly 10 times that of the maximum switch bounce (roughly 20 milliseconds.) The conditions on the valid measurements mean that you dont have to worry (much) about switch bounce. It may be that the user may press SW1 and keep it pressed until the LED goes on (at least one second, and probably several seconds). Your software should detect this and display a blinking 00 (at a 1-second period) to indicate an error. You can (and should) use the pseudo-random number generator and multiplexed display routines from earlier labs. To get credit for this laboratory, demonstrate your working model for the TA. After you complete this lab you can retire the 7-segment LED modules.

Vdd

R? 1.0 k

1.MCLR 2.RA0 3.RA1 4.RA2 5.RA3


Vdd

RB7.40 RB6.39 RB5.38 RB4.37 RB3.36 RB2.35 RB1.34 RB0.33 Vdd.32 Vss.31 RD7.30 RD6.29 RD5.28 e1 d2 c1 f1 g1 a1 b1
Vdd

The current-limiting resistors on the LED and displa should be from 100 Ohms to 500 Ohms.

6.RA4 7.RA4 8.RE0 9.RE1

.1

.1

Vdd

10.RE2 11.Vdd 12.Vss 13.OSC1/CIN

Vdd

14.OSC2/COUT RD4.27 22pF RC7/RX.26 15.RC0 PIC18F4550 16.RC1 17.RC2 18.Vusb 19.RD0 20.RD1 RC6/TX.25 RC5.24 RC4.23 RD3.22 RD2.21 e1 d1 c1 dp1 e2 d2 g2 c2
Vdd

f1 g1 a1 b1 An1 An2 f2 a2 b2

LN526 e2 d1 c2 f2 g2 a2 b2

dp2

Das könnte Ihnen auch gefallen