EE 476: Laboratory 0

Learning the hardware and software.


This assignment introduces you to the software and hardware development tools you will use this semester to work with the Atmel MEGA-series microcontroller (MCU) chips. You will use the STK500 development board to run some C programs. The STK500 pushbuttons, LEDs, and a serial connection to the PC will be used to demonstrate basic compiler, i/o, and debugging techniques. You will run demo programs, use a debugger, and make minor modifications to the existing programs.


The hardware you will be using to support the MEGA-series is the Flash MCU evaluation board, a small board providing:


Software you will use is freely downloadable and consists of:

More information


  1. 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. There should be a two wire connector from pins D.0 and D.1 to the RS232 jumper.

  2. Make sure the crystal on the STK500 is actually 16 MHz.

  3. There will two serial connections to the STK500. One for programming the Mega644 and one for serial communication between the running program and the PC, which will be running hyperterm. Set up hyperterm for 9600 baud, no parity, 1 stop-bit, no flow-control.

  4. Put all files on your Z drive! Do not creat a project on the local drive! Be sure to put all your files there and to back up daily!.

  5. There should be a shortcut to AVRstudio on the desktop or start menu.

  6. To invoke hyperterm on the PC, you will need to use Start...Run...hypertrm from the Windows Start menu. Connect hyperterm to whatever serial port the USB dongle configures. Use Control Panel...System...Hardware Tab...Device Manager Button...+Ports to find out which serial port is connected to the USB dongle. The STK500 serial port RS232 Spare will be connnected to the dongle. Set up hyperterm for 9600 baud, no parity, 1 stop-bit, no flow-control.

  7. After you define a new project, you can add a C source file and edit it.
    1. Save this code into your z drive. This program blinks LEDs and responds to buttons. It is organized as three task subroutines. You will modify this code in the assignment below.
    2. In the AVRstudio Project menu choose Project Wizard. When the dialog box appears, choose New Project.
    3. In the new dialog box choose a GCC project, give the project a name, and indicate a source file to use. Choose a location on your Z drive to store the project.
    4. In the next dialog box choose to debug with AVR simulator and choose ATmega644, then press Finish
    5. In the menu item Project-> Configuration Options -> General -> Frequency enter 16000000 because the crystal frequency is 16 MHz.
    6. Paste this code into the newly created source file.
    7. Choose the menu item Build from the Build menu. A message window will open to tell you if there are errors in the code.
    8. If the compile is successful, you should be able to download the program to the STK500 board and see some blinking LEDs.
      To download, select the Tools>Program AVR>Autoconnect menu item which will open a dialog box. In the dialog box:
      1. In the Main tab, set the ISP frequency (Settings... dropdown) to 57 Khz, then press Write then Close.
        Make sure the device is Mega644.
      2. In the Program Tab, Flash box, select the hex file generated by the compiler. The file will be in the
        project folder>default folder. Press the Program button. If the program does not download to the chip, call a TA. Note that the hex file name is NOT unpated for you and will default to the last project compiled on the computer.
      3. If the Mega644 is new (unprogrammed):
        1. Go to the Fuses tab in the programmer window and set the SUT_CLKSEL fuse to:
          Ext crystal osc 8- MHz; startup time: 16k clk+65 mSec.
        2. Uncheck the CLKDIV8 box.
        3. Uncheck the JTAGEN box and answer YES in the confirming dialog. (If you leave the box checked, PORTC does not work correctly).
        4. Click Program

  8. Timing of all functions in this lab, and every exercise in this course will be handled by interrupt-driven counters, not by software wait-loops. This will be enforced because wait-loops are hard to debug and tend to limit multitasking. Specifically, you may not use the delay library routine delay_ms. Using delay_us will be acceptable when you need to produce delays on the order of a few microseconds.


  1. Using the short demo code downloaded above, modify the code:
    1. To stop blinking LED 1 when button 6 is pushed.
    2. To blink 8 times faster.
    3. Add an LED and 300 ohm resistor as shown above. Make your program blink this LED rather than the one on the STK500.
    4. Make a separate version of the code which blinks all eight LEDs in sequence at a rate of 4 LEDs/second.
    5. Show all these to your TA.
  2. Using the assert command .
    1. Download AssertGCC644.c, uart.c and uart.h and put them in the same folder. Build a new project with AssertGCC644.c and uart.c as source files. The assert macro tells you what condition failed, the function, and the source file. This utility can very useful for debugging and is often better than just using printf because conditional logic is included and because all asserts in a program can be removed by inserting the macro #define NDEBUG before including assert.h.
    2. Modify the demo code's task 3 to assert when you push button D.6.
    3. Modify the demo code's task 2 to assert after ten seconds. The printed message might be something like:
      Assertion failed: (time<10), function task2, file ../AssertGCC644.c, line 90
    4. When you are eady to remove asserts (for a fully debugged code) insert the macro #define NDEBUG before including the assert.h.
    5. Show all these to your TA.

    There is NO written lab report for this exercise, but your attendance is mandatory and your performance in lab will be included in the lab 1 grade.

    Copyright Cornell University Jan 2009