CSE 477 Embedded System Design

Spring 2001

Instructor: C. Diorio

 

Lab 1:

Introduction to the 8051 Microcontroller

 

Objectives:

 

This lab will require you to:

 

Learn about the XS40 board and the 8051 microcontroller

How can we interface the microcontroller with other components?

Learn about the Keil Environment

Load a project in Keil

Compile a Keil project and run it on the 8051

Learn how Keil C interfaces with the microcontroller

Timers and Interrupts

How can we write an interrupt routine using the Keil C compiler

How to set up timers and counter using the function registers

 

Part 1: Learning the Keil environment

 

In this part of the lab, we will be setting the board up, testing it, setting the oscillator, and programming a simple design, into the board.  We will be creating a HEX file that contains the assembled 8051 code, and we will be using a file called ledreg.bit.  This file is an FPGA design that maps some of the I/O of the uC to the FPGA and the LED.

 

1.      Get XS40 board, plug in parallel cable, plug in the XS40 power supply.

2.      Double Click the icon "GXSTEST" on your Desktop. Select "board type" to be XS40-010XL and the correct port (usually LPT1) and test it.

3.      Double Click the icon "GXSSETCLICK" on your Desktop. Select "board type" to be XS40-010XL, the correct port (usually LPT1) and the "Divisor" to be 8. This will set the clock frequency to be 100Mhz/8 ~ 12.5 Mhz.  You will have power down the board and move J12 to the “set” position.

4.      Go to \\ifilesrv1\courses\cse477\Spring2001\lab1\, get lab1.zip and extract it into a new directory in your own user space in a directory called mylab1.

5.      Run Keil uVision2 (eval). There should be a link on the desktop.

6.      Select Project/New Project... from the Keil menu.

7.      Select your Z: drive and your "mylab1" directory, and name the project "ledreg.uv2".  When it asks what the target is, browse for the Winbond part #W78C32B.

8.      In the Keil file browser, right click on the target 1 folder and pick the options menu.  Click on the output tab and check the “Create HEX file” option.  Close the window.

9.      Right click on the source files folder and pick the "Add Files " option to add "ledreg.c" to your project.

10.  Save the project.

11.  Double click on ledreg.c in the Keil browser to open the file. 

12.  Build the project. Either go to Project/Make: Build Project or push the shortcut button (three down arrows pointing at a rectangle.  It should say something about “Creating HEX file” 0 errors, 0 warnings.”

 

Part 2: Programming the board

 

1.      Open up a windows explorer and go to the directory that you have been working in for this project.

2.      From the desktop, open the GXSLOAD utility.

3.      In the windows explorer, select both the ledreg.hex and the ledreg.bit files.

4.      Drag them both onto the GXSLOAD utility window.  This should program them both onto the board. 

5.      From the desktop, open the GXSPORT utility.  This utility allows you to directly control the values on the parallel port.  Set all of the values to 0 and hit strobe.  Then, make the low order bit 1, and hit strobe again.  This resets the microcontroller.  Your program should now be running.

6.      Modify ledreg.c to count the even decimal digits from 2 to 8.  Reprogram the board to verify the correctness of your design.

 

Have the TA verify this step of your lab.

 

Part 3: Using counters to create interrupts

 

In this part of the lab, we will be taking some C code that sets up the basic interrupts and timers.  Timer 1 is set up as a 16-bit timer that counts down and causes an interrupt every 5ms, assuming the correct clock frequency.  You need to examine the code from the first part of the lab and use that knowledge to make a 10-seconds counter.  This will require that you figure out what clock frequency to run at in order to make your seconds accurate.

 

1.      Start a new Keil Project and call it inter.uv2.  Set up the same options as you did in part one.

2.      Add the file “inter.c” to the project.  The file should compile.  However, its functionality is not complete.

3.      Add code to the interrupt handler to make the 7 segment display change every second.

4.      Recompile your code and verify the result.

 

Have the TA verify this step of your lab.