HOME

Lab components

Objective

Reading

Links

Part 1 to 3

Turnin

CSE 477: Embedded System Design
(Spring 1999)
Lab 2: 
Microcontrollers: 
             Timers and Interrupts

Objectives:

In this lab will you will learn the following: 

  • Timers and Interrupts
    • how to write an interrupt routine using the Keil C compiler.
    • how to set up timers and counters using the special function registers (sfr), such as TCON and TMOD.
    • how to use multiple interrupts to do timing.
  • Microcontrollers
    • how to find and read pinouts from specifications
  • Two-axis Accelerometers
    • how to interface an accelerometer to a microcontroller.

Reading
This lab has two handouts: 

  • XS40 board pin-out
  • Atmel documentation for the 89C55

Other Relevant Links
 

Part 1-- External Interrupt Example 
 
 
All parts of the lab should be done with the OKI 8051 chip, the standard 8051 that does not have 20K flash memory. Don't forget to put the J7 jumper in the right position for the OKI chip (jumper on first two pins. The bit file used for the FPGA will be ledreg.bit.

Make a Keil project using the existing button.c found in the \\ifilesrv1\cse477\lab2 directory. This program is the one from Lab 1 which lights up the segment in order, but an interrupt routine has been added that lights up all the LEDs on the digit display when the button is pressed. The trigger for this interrupt routine comes from an external interrupt pin. 

Here is a diagram that shows how to connect a switch to the pin to trigger the interrupt:

You should now change this program:

  1. The present program works on external interrupt 0 (EX0). Use the Atmel documents and class notes to find what has to be changed to use EX1. Pay attention to what needs to be changed in the interrupt control registers, such as, IE (interrupt enable)
Part 2 -- Clocking Example
The inter.c file demonstrates how to time the period of a clock signal (this clock is the oscillator that is found in the lab kits). In summary, one interrupt routine keeps track of elapsed time and the other interrupt routine counts 10 cycles of the clock. The 7-segment display is changed every 10 cycles to show the current clock frequency.  What code is used to display this frequency?

Make a Keil project with the inter.c file. Attach the clock generator probe from your Lab Kit to the appropriate pin. 
 


(Check that the output of the  clock goes high and low with the probe) 

Part 3 -- Design an interface to the Accelerometer.
The accelerometer we will give you measures acceleration along two, orthogonal axes.  This can be used to measure tilt in the X and Y dimensions by measuring the force of gravity in each dimension.  The measured acceleration is given on two pins, one for each dimension, using a pulse width code as described in class and in the documentation.  You should decide how to interface the accelerometer to the microcontroller so that the two acceleration values are available to a program running in the microcontroller.

Now write a program that uses the 7-segment display to implement an electronic level that shows the tilt of the accelerometer.  Light up a segment (or 2) to show in which direction the accelerometer is tilted.  If there is no tilt, light up the center segment.  For extra credit, flash the lights to indicate the degree of tilt.  Think about the user interface when designing this part.

Use the information and programs from previous parts to get started. The accelerometer works in a simple way. There are is output for the x and y direction (one pin x, one pin y). When the duty cycle of the output pin is about 50%, then the accelerometer is level in that direction. If the duty cycle is bigger or smaller than 50%, the accelerometer is tilted to one side or the other in that direction. The resistor added to the accelerometer determines the period of the output. The 1.2 Mohm gives a 10 ms period.
 
 
 
Careful:
WATCH POWER AND GROUND
DON'T DROP, OR IT BREAKS

Here is the interface to the accelerometer:
 
E B D C A
Common (Gnd) self test Xout Yout Vdd

 

What to Turnin
Demonstrate part all parts and hand in the code for interfacing to the accelerometer. You should also be able to answer detailed questions about every part.

 BACK TO TOP

 Last Updated:
3/24/99

Contact the instructor at:cse477-webmaster@u.washington.edu