CSE 466 Lab1 - Heartbeat

 

Goals

 

    1. Familiarize yourself with the Keil development tools, particularly use of the debugger.

    2. Familiarize yourself with the laboratory equipment (scopes, programmer).

    3. Write a simple C program to control the Atmel 89C55 microcontroller.

 

The task that your microcontroller should perform is to flash an LED on one of the I/O ports at variable speeds.  The period of the LED flash will be controlled by a set of DIP switches on another I/O port.  The exact relationship between the DIP switch settings and the speed of the LED flash is your decision.  The flash rate should vary between about 4 Hz (fast but visible flash) and 0.25 Hz. Although there are on-chip timers, we won't use them for this lab.  Therefore, you should probably write some sort of delay loop to time the LED flash.  

 

 

Instructions

  1. Setup the hardware as shown in the diagram above.  Be sure to connect GND, VCC, and !EA to the appropriate voltage levels.  !EA controls external memory addressing, so this pin should be pulled high because we are not using external memory.  Each pin of the chip can sink only a certain amount of current, so you need to select the resistor value to connect the LED to the chip.  Look in the documentation for the chip to determine the maximum current per pint and calculate the required resistance (see page 17 in the 89C55 document).  Don't forget to consider the voltage drop across the LED.   

  2. Check that your LED works by connecting the pin on the port to ground.  If the LED lights up, you're all set.  You can test that the DIP switches work by using the probe in your lab kit.

  3. Connect a crystal between pins XTAL1 and XTAL2.  Use the scope to look at the signal generated by crystal. Can you measure the frequency?  What if you measure the output on ALE?  Is the frequency the same as that of the crystal?

  4. Open the Keil2 development environment.  Select "New Project" from the Project menu and give the project a name.  Be sure to save the project in a network drive that is accessible to you. When prompted to select the device to use for the project, select 89C55.  Right click on the target folder at the left side of your screen and select "Options for target".  In the box that pops up set Xtal to the frequency of your crystal.  Set the memory model to "Small" and the Code Rom Size to "Compact".

  5. Create a new file and call it "main.c".  Under the Project menu select add file and add newly created source file to your project.  At the top of your source file add the line "#include <At89x55.h>".  This tells the compiler to include constant definitions appropriate to the 89C55.  Go ahead and open the file At89x55.h to get an idea of the constants that are included.  All of the constants are defined to be addresses on the chip but you don't need to worry too much about these addresses at the moment.  Port 0 is identified by the constant P0.  If you want to access just the least-significant bit (pin) of Port 0, you can use the constant P0_0.

  6. Write your program in the main file.  Remember that the standard C functions (printf, getc, etc.) are not available in this environment. (We'll see later that these can actually be used, but it takes some extra effort). Try to guess at how long the delay needs to be.  This can be made more accurate in the simulation step.

  7. Build the program by pushing F7 or selecting "Build Project" under the Project menu.  If you get errors, fix them and rebuild.

  8. Simulate your code.  Open the debugger.  Set a breakpoint at a sensible point and step through the code to determine the period with which your LED will flash.  The "sec" value in the left hand window will show you the amount of elapsed time. You can set values on Port 2 by using the VTREGs.  These virtual registers allow you to set values for simulation.  In the lower left corner of your screen click on the command line and type "dir VTREG".  To set a value, simply type "VAR = value".  You can also add variables to watch in the window at the bottom middle part of the screen.

  9. Open the disassembly window and look at the assembly code generated by the compiler.  Hit reset and single step through the assembly.  Does the code do anything other than what your C code specified?  If so, what does it do? (It's ok if you don't understand the specific assembly instructions, just try to make some sense of what is happening by stepping through the code and looking at the code.)

  10. Burn it.  Load the hex file generated by your build onto a floppy disk (it will have the same name as your project name).  Take the floppy and your chip to the black programmer.  Place the chip in the holder.  Make sure the device that is selected is the Atmel 89C55.   From the File menu select Name and give the name of your file (i.e. "a:\file.hex").  From the File menu select Load to load the file into a buffer.  Hit ESC to go back to a higher menu. From the PROM menu select Program to program the chip with the code in the buffer.

To Turn-In

Last update: 03/28/2000 02:09 PM