Reflex Timer
I. Introduction
Microcontrollers often need to perform operations based upon some length of time. This can be used for communication purposes (e.g., serial communication), event counters, measuring time, or performing operations at certain intervals.
The 80c51 has 2 16-bit timer/counters registers which can be configured to perform a variety of operations. When configured as a timer, the timer will count from the user specified value down to 0. Upon reaching 0 an interrupt will be generated, at which time an interrupt service routine can be performed. The following timer register descriptions provide the neccessary information for the timers/counters in the various modes of operations.
Timer Register Descriptions:
TMOD Timer Mode Register
------------------------------
|Gate|C/T|M1|M0|Gate|C/T\|M1|M0|
------------------------------
|<-Timer 1----><---Timer 0 --->
Gate Gating Control.
0= Timer enabled
1 = Timer enabled if INTx\ is high
C/T\ Counter or Timer Selector
0 = Internal count source (clock/12)
1 = External count source (Tx pin)
M1, M0 Mode Control
M1 M0 Mode
----------------------------------
0 0 Mode 0, 13 bit count mode
0 1 Mode 1, 16 bit count mode
1 0 Mode 2, Auto reload mode
1 1 Mode 3, Multiple mode
-----------------------------------------------------------------------------
TCON Timer Control Receiver Register
---------------------------
|TF1|TR1|TF0|TR0| | | | |
---------------------------
<-Timer Controls><-Unused for timers
TRx Timer x run control
0 = Timer not running
1 = Timer running
TFx Timer x flag
0 = timer has not rolled over
1 = timer has rolled over
----------------------------------------------------------------------------
Formula to load the value of TH1 corresponding to required baud rate
Clock Frequency (12 MHz)
----------------------- = Baud Rate
12 x 32 x (256-TH1)
In this lab you will build a reflex timer to measure a person's reaction time. The reflex timer works by lighting up an led after a random lenght of time and the user will have to respond by pushing a button as quickly as possible. In this lab you will need to calculate how long it took the user to respond and display it on the LCD in milliseconds (10-3 seconds).
The specs are as follows:
II. Schematic:
The materials needed are listed and a general setup
is provided. However, it is your job to figure out the
connections.
HINT: you can refer to previous labs, we have used
all these components previously.
III. Apparatus Required:
IV. Program
/* main.c */
#pragma SMALL DB OE
#include
V. Procedure: