The University of Michigan – Dearborn

The Electrical and Computer Engineering Department

ECE 473 – Embedded System Design

--------------------------------------------------------------------------------------

Lab: Lab #3

Title: Calculator Design: Interrupt and Timer Application

Goal: Learn to generate time delay and wake up interrupt and using LCD interface.

Time duration: 2 weeks

Work mode: Lab Groups (up to two members per group)

Lab purpose: 1.Be familiar with wake up interrupt

2. Be familiar with the timer overflow flag

2. Learn to use LCD to display result

3. Learn to connect I/O ports by using jumper wire

Requirements: Detail knowledge of LCD, interrupt and timer overflow flag

Lab description:

Design of calculator is one of the most important applications for embedded system, which would be used a lot in many real time systems.

In this experiment, you are to design a software application which can perform 3-bit binary addition and subtraction. The inputs to the application will be two 3-bits binary digits using the push buttons and the output will be displayed in decimal using the LCD.

Use two of the Push Buttons on project board to input 1’s and 0’s. When each number has been inputted correctly, then use a third push button (call it “confirm” button) to call wake up interrupt. The interrupt routine stores each number onto a FIFO. After you input the two 3-bits binary numbers, use two other push buttons to select “ADD” or “SUB” to perform the calculation, and then display the result on the LCD. For example: if your inputs in binary are “111” and “001”, and you select the “sub” button, then the LCD will display is 7-1= 6, that is the LCD will display the inputs, the operator (ADD or SUB) and the output all in Decimal.

The main routine scans all the input buttons every 1 second. Use a timer overflow to generate the 1sec delay and while scanning let LED5 blinking. Make sure LED5 blink at 1 Hz (The default bus clock is 16 MHz).

I/O devices Description:

1. There are five PBs (push buttons) on the project board that will be used in this lab. One button used as a “confirm” button, two for inputting the 3-bit binary numbers (the 3-bit binary number will be interred one bit at a time), and the last two for the operations “ADD” and “SUB”.

2. There are five LEDs on the project board. Three LEDs correspond to “confirm”, binary number one and binary number two, which would change status (“ON” à “OFF” or “OFF” à “ON”) when corresponding signal has been scanned by system successfully. The other two LEDs correspond to “ADD” and “SUB”.

3. The last LED (which has been assigned for the operator “SUB”) should be kept blinking at 1 Hz while there is no calculations (no input to the program available).

PBMCUSLK LED5 and PB5 do NOT support "Direct Connect" feature, so please use jumper wire to connect to I/O.

4. There is one LCD on project board, which used to display calculation result.

Use scope to capture the LED5 waveform and to generate the frequency of it.

Please answer these questions:

1. Figure 1 shows the basic timer hardware in the HCS12 microcontroller. Please describe how each part works, and try to describe how did you generate the waveform by using timer overflow.

2. What happens if you do not reset the flag in the interrupt service routine?

3. Which instruction in your microcontroller is used for the following?

a) Unmasking interrupts

b) Masking interrupts

c) Returning from an interrupt service routine?

4. Use the same pin connected to LED 5 on project board and LED1 on development board. Are these two LEDs blink at the same time? If no, explain why.