EE 476: Laboratory 1
Introduction to the lab hardware/software.
Introduction.
This assignment introduces you to the software and hardware development tools
you will use this semester to work with the Atmel AT90-series microcontroller
(MCU) chips. and
program a small state machine to count up/down.
Hardware
The hardware you will be using to
support the AT90-series is the Flash MCU evaluation board, a small board providing:
- A target AT90-series microcontroller (mcu) with onboard flash program memory.
- A programmer for the target flash memory, including a serial connection
to a PC.
- Eight general pushbuttons, eight LEDs and a RESET button.
- A serial connection for applications.
- Connectors for bringing out the microcontroller signals to user-designed
peripheral equipment. Note that there is no protection on these lines. You
are connecting directly to the mcu. Prudent design suggests you might want
to use buffers when you are uncertain of voltage levels or other conditions.
The pin definitions for the connectors are shown below. The inner squares
represent pins. The outer border is a white line surrounding the plug.
A small power supply provides power to the development board. The two demo
codes given in this lab are written for the Mega163, but many of the examples
throughout the 476 web site are written for the 8515 mcu. This year we are using
the Mega163 which has more memory and A/D converters. To run the 8515 example
programs you will need to:
- Change the header file to
<Mega163.h>
- You will need to program the clock select bits in the CodeVision setup:
choose "External crystal/slow power up"=1010
- TIMSK bit definitions are different from the 8515. You must modify any reference
to TIMSK.
- UART register names have changed
- The programmer dongle connects to the PC serial port. Do
NOT use the Altera dongle.
The Liquid Crystal Display (LCD):
A 16 character, two line (16x2), LCD display 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:
- Connecting the power backwards will destroy it.
Always check the polarity before connecting the display.
- The 14 pin header is on the lower-left corner of the display. Pin 1 is
closest to the left edge of the pc-board.
- Since the display only draws about 1-2 mA, you can use port VTG pin for
+5 volts. You may need a 10k or 20k trimpot to adjust display contrast connected
as shown in the following program. But first, try hooking LCD contrast control
(pin 3) to ground.
- The LCD interface to the mcu is documented in the CodevisionC libraries
and in a short C program which you can use to test
your LCD connections. Note that this program uses a software delay to time
the display, something you can never do if your program has to respond to
external events.
- The character representation is identical to ASCII codes for numbers, letters
and most symbols. Refer to the data sheet above for a complete listing.
- The LCD display is arranged as 2 lines of 16 characters and is addressable
on a per-character basis.
Software
Software you will use consists of:
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.
- Make a subdirectory for your group in the
My Documents
folder.
Name it with your netid.
Be sure to put all your files there and to back up daily!.
- There should be a shortcut to Codevision C on the desktop.
- 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.
- Under the
Project
menu, choose Configure...
, then in the Files
tab, add the source code to the project
you just defined.
- In the
Compiler
tab, set the Chip
type to
Mega163
. Also set (s)printf features
to int,width
.
- In the
After make
tab, set the Program
the Chip
checkbox, then set CKSEL0
and CKSEL2
.
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.
- Connect the LCD and run the LCD test program.
Assignment
- All timing must be done with interrupt-driven hardware timers and not with
software wait-loops. In other words, the
delay
function is not
allowed in your code.
- All programs must be in C.
- Modify this program to:
- Count up at one count per second on the LCD when switch0 is pressed
and held. The LCD displayed count should stop counting and hold its value
when the switch is not pressed.
- When switch1 is pressed, the LCD should increment exactly one count
per press (independent of how long the butten is held down).
- When switch2 is pressed, the LCD should decrement exactly one count
per press (independent of how long the butten is held down).
- The program you write should be organized as scheduled tasks. One possible
organization could be:
- Task 1 tests the switches and runs the debounce state machine (scheduled
every 30 mSec).
- Task 2 updates the LCD display (runs every second).
Be prepared to demo the program you wrote to your TA in lab.
Your written lab report should include:
- How accurate was the interrupt time base in the program you were given?
How could you make it more accurate?
- Why did we make you use interrupts rather than wait-loops?
- Draw the state machine you used to debounce switches 1 and 2.
- The listings of your programs.
Copyright Cornell University Jan 2003