EE 476: Laboratory 1
Stop watch.
Introduction.
In this assignment you will build a stopwatch. The stopwatch will have a start/stop function and a split function. The split function will copy the current measured interval to the LCD display while leaving the main interval timer (and display) running.
Procedure:
- Make sure the evaluation board is connected to power and to the PC as specified
in the evaluation board description. Turn on the power supply with the switch
on the board. An LED in the middle of the board should cycle from red to yellow
to green. For this first lab, there should be jumpers on the PortB to the
LED header and on PortD to the switch header. Ask your instructor for help
if these are not installed.
- After you define a new project, you can add a C source file and edit it.
- Save this code (from the Program
Organization page) into your directory. This program blinks LEDs and
responds to buttons. It is organized as three task subroutines. You will
modify this code in the assignment below.
- In the Codevision file menu choose to make a new file. When the prompt
comes up, choose
Project
. When asked if you wish to use CodeWizard
,
decline the offer. At this point, you have made a new project, now you
need to configure it. The configure dialog should be open but if it is
not, under the Project
menu, choose Configure...
- In this dialog box, in the
Files
tab, add the source code
to the project you just defined.
- In the
Compiler
tab, set the Chip type to Mega32
.
Set clock speed to 16 MHz.
Set (s)printf features
to int,width
.
- In the
After make
tab, set
the Program the Chip
checkbox.
Set CKSEL0
and CKSEL2
.These select the clock
source.
You may need to uncheck the Check Signature
box.
Then close the configure dialog.
- Click on the compile icon. A message window will open to tell you if
there are errors in the code. If there are errors, The open the listing
file to see where they are. If the compile is successful, you should be
able to download the program to the STK500 board and see some blinking
LEDs.
- You will need to generate a time base for measuring times. I suggest that you use
the multiple task timing scheme from this code.
- Remember that a switch which is pushed reads back a logic zero.
One button will need to be debounced. The spilt and reset buttons don't need to be debounced, but the start/stop button will need it, otherwise button bounces will make the stopwatch unreliable.
- The Liquid Crystal Display (LCD):
A 16 character, two line (16x2), LCD display will be used as a numerical display. The display we are using has an industry-standard interface. A more detailed data sheet for a similar display shows the command set. There are several aspects of the display you should note:
Assignment
- All timing must be done with interrupt-driven hardware timers and not with
software wait-loops.
- All programs must be in C.
- Produce an C language program which implements a stopwatch with three buttons:
- The LCD should be used to display
min:sec:tenths
for total elapsed time on the first line.
- The LCD should be used to display
min:sec:tenths
for a split time on the second line.
- Button one should reset both displays when pushed only if the timer is stopped.
- Button two should record the current elapsed time on the split time display when pushed.
- Button three should start the timer if it is stopped, and stop it if it is running. This button will need to be debounced.
- Stopwatch accuracy should be as good as the MCU crystal oscillator.
Be prepared to demo the program you wrote to your TA in lab.
Your written lab report should include:
- How would you measure time-base accuracy?
- Why did we make you use interrupts rather than wait-loops?
- The scheme you used to detect the pushbutton state. (e.g. polling loop,
interrupt)
- Other design aspects of the assignment.
- A heavily commented listing of your code.
Copyright Cornell University Oct 2005