CSE 477 – Digital System Design
Spring 2003
Carl Ebeling

Lab 1 : Programming the 8051 Microcontroller

Objectives:

The goal of this first lab is to get you up to speed on the Keil compiler for the 8051 and on the Aldec design tools for FPGAs.  In this lab you will: 

1.      Learn to use Keil Environment

2.      Make, compile and debug a simple program using the Keil tools

3.      Use the Aldec tools to design, test and debug a simple HW component

By Lab 3, you will combine an 8051 running your program with HW components to interface to an ultrasonic sensor or accelerometer and an stereo audio codec.

Getting Started with the Keil tools

There are some on-line tutorials that are a pretty good introduction to using the Keil environment.  Find the CD folder in the Keil folder and run the SETUP.EXE program.  This will give you a menu - you want the "Tutorials and Training" option.  The three tutorials, "Creating Projects", "Testing and Debugging" and "Advanced Simulation" are all worthwhile (just ignore the market-speak).

There are also Keil manuals in the lab, the on-line Help from within Keil, and the following links:

Primer for the Keil 8051 C compiler (a good intro)

The Keil "Getting Started" guide (more advanced)

Your First Program

Here is about the simplest program you can imagine.  Start a project, type in this program (or cut and paste) and then use the debugger to step through the program.

Follow these steps:

1.      Start up Keil uVision2.  You can use the eval version to write and debug your project, but when it comes to making the .hex file, you will have to use the full version which requires a dongle.

2.      Use Project/New Project to start a project – call it ledreg.  Use a Generic 8051 when you have to choose a part for the target.

3.      Set the target options to SMALL code size and SMALL data size, and check the option to produce a .hex file.

4.      Add the program program below, called ledreg.c

5.      Compile and then use the debugger to step through the program, watching the registers and the output port P0


#pragma code

#include <reg51.h>

void main() {
  char i;

  while (1) {     
    for (i = 0; i < 100; i++) {
      P0 = i;
    }
  }
}


Your Second Program

When we run this program on the hardware, we will connect P0 to the bargraph LEDs or a 7-segment display.  Of course it will run way too fast, but we can fix that by adding a delay loop.  Change the program as follows:

1.      Turn on one LED at a time, shifting through the LEDs.

2.      Read P1, which will be connected to switches that will determine a) the direction the LEDs should be lit and b) the speed at which the bit shifts.

Turn in your modified C program that rotates the LEDs. Demonstrate that your program works using the Keil debugger and have us sign off on the C programs.


Starting out with the Aldec Tools

If you have not used the Aldec tools yet, you will have to spend some time coming up to speed.  There are three tutorials that you should work through here. Aldec Tutorial #1, Aldec Tutorial #2, Aldec Tutorial #3

The component you design in this part will be used (with some modification) in Lab3 to interface to the stereo codec.  The codec is connected to use Mode 2, which takes input in the form of 20-bit numbers, one per channel, in serial format.  Each number consists of 32 bits, with the 20-bit number left justified.  Three clocks are required.  The first clock, MCLK, is the system clock (12.5MHz), the second is SCLK, which runs at MCLK/4 (~3MHz), and the third is LRCLK, which runs at SCLK/64.  LRCLK is high for 32 SCLK cycles, during which the left channel value is shifted in, and low for 32 cycles, during which the right channel is shifted in.  Refer to the documentation for the timing of these signals.

Design a component that provides the clocks and the data input for the audio codec.  The input will be two 16-bit values, LEFT and RIGHT.  Your component should sample these values at the start of each LRCLK cycle, and provide the numbers to the codec in the right format.

Write a test fixture to test your design.  This test fixture should provide the inputs to the component and check the outputs, including the clock frequencies and the serial data value.  I suggest that your component be written as a single Verilog file, with a test schematic that incorporates the test fixture, your component, and the clock generator.

What to Turnin

The printed, signed C program for the LED rotate program.

The printed, signed schematics, Veriog programs and waveforms for your codec interface.