0% found this document useful (0 votes)
68 views

Programming Reaction Timer Report

This program uses an embedded system to measure a user's reaction time to an LED signal. It uses software routines like delay functions to control timing. Interrupts from a programmable interrupt timer are used to track time in milliseconds, hundredths of seconds, tenths of seconds, and full seconds. The main function initializes the 7-segment display and calls other functions. These functions reset LEDs, blink an LED until a button is pressed to start a countdown, display time values on the 7-segment display, and randomly turn on an LED for the user to react to by resetting time variables.

Uploaded by

jonathan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Programming Reaction Timer Report

This program uses an embedded system to measure a user's reaction time to an LED signal. It uses software routines like delay functions to control timing. Interrupts from a programmable interrupt timer are used to track time in milliseconds, hundredths of seconds, tenths of seconds, and full seconds. The main function initializes the 7-segment display and calls other functions. These functions reset LEDs, blink an LED until a button is pressed to start a countdown, display time values on the 7-segment display, and randomly turn on an LED for the user to react to by resetting time variables.

Uploaded by

jonathan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Programming Reaction Timer

Reaction timer is embedded system that works by measuring the user reaction to signal and
display LEDS in the time interval. This program uses the following function

1. Software Routine Function


This programming function works by maintaining the timing of various operations in
microprocessor. This is done by ensuring controls such as ON/OFF after specific delay period.
Delay function works by compelling the controller to devote all of its resources to executing a
while loop of some sort that involves increasing the variable until a certain value is achieved and
obstructing the remainder of the code’s execution path. The example below demonstrates how it
works
void delay_ms (short ms)
{
volatile short loop;
while (ms-- > 0)
{
for (loop = 0; loop < 2100; loop++);
}
}
1. Interrupt Function
The program function call is done in every PIT interrupt, that is 1000 interrupts in 1 second,
modified from the "Laboratory 5" code. The PIT Get PIVR function reads the PIT status and
Removes all pending interrupts.
void ISR_System(void)
{
PIT_GetPIVR(); /* Reads the PIT status & clears pending interrupts (not assigned - we're not
interested in the result) */

/*
* Interrupt processing... (Note 1000interrupts = 1 second from previous defined function)
*/

if (++m_seconds == 10) /* Increases count in millisecond and also setting 10 milliseconds to 0


*/
m-seconds = 0;

if ((hertz % 10) == 0) /* Defines the hundredth of milliseconds */


{
if (++h_seconds == 10) /* Increases the count to its hundredth and sets the 10
hundredth of a second back to 0 */
h_seconds = 0;
}

if ((hertz % 100) == 0) /* Identifies a tenth of a second */


{
if (++t_seconds == 10) /* Increases the count to its 10th and sets the tenth tenth of a
second back to 0 */
t_seconds = 0;
}

if (++hertz == 1000) /* Increases the interrupt (hertz) count and sets the thousandth interrupt
back to 0 */
{
hertz = 0;

if (++seconds == 10) /* Increases the second count and sets the tenth second back
to 0 */
seconds = 0;
}

}
2. Initialization and program start
This is entry point of the program; it works by assigning of an initial value for the data object 7
segments Display before making call flash –lead () function
int main()
{
Configure7SegmentDisplay (); /* Initializes the 7 Segment Display */

flash_LED(); /* Calls the flash_LED() function */

return 0;
}
3. LEDs reset and blinking of LED1
The program function helps to display the last recorder timer values on the 7 Segment
Display (shows 0.000 the first time it runs)
void flash_LED( ){
/* Displays the last recorded timer values on the 7 Segment Display (shows 0.000 the
first time it runs) */
Set7SegmentDisplayValue(M_SECONDS, Digit[m_seconds]);
Set7SegmentDisplayValue(H_SECONDS, Digit[h_seconds]);
Set7SegmentDisplayValue(T_SECONDS, Digit[t_seconds]);
Set7SegmentDisplayValue(SECONDS, secDigit[seconds]);

4. Turns all the LEDs off


 It prevents auto-initialization when the random green LED in reaction () was LED1 */
delay_ms(250);
 This loop blinks LED1 red until Button 1 is pressed then calls the countdown () function
Set All LEDs (LEDs All Off);

/* Prevents auto-initialization when the random green LED in reaction () was LED1 */
delay_ms(250);

/* This loop blinks LED1 red until Button 1 is pressed */


while(IsButtonReleased(BUTTON1))
{
SetLEDcolor(LED1, RED);
delay_ms(250);
if(IsButtonPressed(BUTTON1)) break; /* Lets us exit the while loop before its
execution finishes */
SetLEDcolor(LED1, OFF);
delay_ms (250);
}

countdown (); /* Calls the countdown () function */


}
5. LED countdown for the reaction test
 This function Resets all the 7segments display and shows 0 for each digit. This function
also Determines if the first LED is turned off and the last LED to continue with the
reaction test.
6. Reaction Test
 Randomly generate a number between 0 and 7 to turn on a green LED
int reaction()
{
rnum = rand() % 7;
SetLEDcolor(rnum, GREEN);
 Resets the time variables to 0
hertz = 0;
seconds = 0;
t_seconds = 0;
h_seconds = 0;
m_seconds = 0;

You might also like