Embedded System Lab Manual
Embedded System Lab Manual
Embedded System Lab Manual
SYSTEM
ECE3637
LAB MANUAL
Revised Date
April, 2015
Revision History
Revised
Date
April 23,2015
Revised By
January 20,
2013
Revised Topics
Lab.01 Using KEIL
Lab.02 Software Delay
Lab.03 8051 IO Ports
Lab.04 Switch De-bounce
Lab.05 Soft Timer
Lab.06 8051 Timers
Lab.07 PWM generation
Lab.08 Interfacing a DC motor
Lab.09 8051 External Interrupt
Lab.10 Serial Communication
Lab.11 8051 Timers and Serial Interrupts
Lab.12 Switch De-bounce using FSM
Lab.13 LCD interfacing
Lab.14 Keypad matrix
Lab.15 Interfacing ADC
Lab.16 Stepper Motor Interfacing
Lab.01 Setup development for STM32
Lab.02 Bare bone project for STM 32
Lab.03 Configure a GPIO pin as output
Lab.04 Create a software delay
Lab.05 Configure a GPIO pin as input
using debugger
Lab.06 De-bounce a witch input and
count its state changes
Lab.07 implement a time cyclic
executive using Timer
Lab.08 Start development and debugging
of course project
Lab.09 Implementing FSM
Lab.10 implement a multistate machine
Lab.11 Implement a multistate cyclic
executive
Lab.12 Using LCD library
Lab.13 Using USART library
Lab.14 Keypad matrix
Lab.15 ADC
Lab.16 Demonstration and Evaluation of
Course project.
2
January 20,
2012
Remarks by Mentor:
Remarks by HOD:
TABLE OF CONTENTS
S.
No
TOPICS
PAGE
NO.
Using KEIL
Software Delay
10
8051 IO Ports
14
Switch De-bounce
19
Soft Timer
23
8051 Timers
26
PWM generation
51
55
59
8
9
10 Serial Communication
42
45
48
13 LCD interfacing
51
14 Keypad matrix
55
15 Interfacing ADC
59
63
Lab. 01
Experiment title:
Using KEIL to write an 8051 Assembly language program and burning its hex file to the
controller.
5
Equipment:
Procedure:
Run the KEIL software.
Click on project from the menu and then select new uVision project.
Name the project toggle and save it in a new folder with the name My First Project.
Copy a startup file.asm for the 8051 in My First Project if not copied automatically.
A window will open to select the target device. Select ATMEL and then AT89S52 and
click on ok.
Select new from the menu to create a source file.
A text window will open to write the code.
Write the code given below in asssembly language to toggle ports 1 & 2 after a delay.
Learning outcomes:
The students must be able to develop a project written in an assembly language.
Get to know how to use the source editor, compiler/debugger, simulator in an integrated
development environment and creating the hex file.
Learn to get the hex file burnt to the microcontroller using a universal programmer.
7
Questions:
What is an IDE? What is the name and version of the IDE used in this lab?
What is an assembler? What are its input and output files? Which assembler is used in
this lab?
What is a linker? What are its input and output files? Which linker is used in this lab?
Each student is required to perform the lab and submit the following
Performa along with the lab report.
1 = Unsatisfactory
Excellent
2 = Fair
3= Satisfactory
4 = Very good
5=
Questions
Rating
Remarks
(1 to
5)
1. To what extent did you learn on the material in the
lab?
2. Are you able to apply knowledge gained in the lab to
similar problems?
3. Are you able to analyze and interpret data recorded
in the lab?
Lab. 02
Experiment title:
Implementing a software delay
9
Equipment:
Procedure:
To test the operation of the ports of your 8051 Trainer in the lab you
can download the C program for Toggling LEDs on P2 given below:
10
For you Compiler, make sure the hex option in the Link is checked so the hex
file for the above program is produced.
Learning outcomes:
To toggle and test the 8051 Trainer and its ports using C program
11
Questions:
Each student is required to perform the lab and submit the following
Performa along with the lab report.
12
1 = Unsatisfactory
Excellent
2 = Fair
3= Satisfactory
Questions
4 = Very good
Rating
5=
Remarks
(1 to
5)
1. To what extent did you learn on the material in the
lab?
2. Are you able to apply knowledge gained in the lab to
similar problems?
3. Are you able to analyze and interpret data recorded
in the lab?
13
Lab. 03
Experiment title:
Programming the I/O ports
a) Port mirror
b) Implementing sliding LEDs
Equipment:
KEIL simulator
8051 trainer/AT 89s52
Procedure:
In this Lab we test the 8051's port for input operation.
Download the C program for Sending P1 Switch Data to P2 LED given
below.
Learning outcomes:
Configuring ports as inputs and outputs
Questions:
Assignment:
Write a code such that P1.0 is an input connected to a switch and P1.7 is an output
connected to a led and P2.0 is connected to the oscilloscope
a) If switch = 0 then a square wave of 1Hz IS generated at P2.7 and the led blinks
with the same frequency.
b) If switch = 1 then a square wave of 2Hz IS generated at P2.7 and the led blinks with the same
frequency.
17
Each student is required to perform the lab and submit the following
Performa along with the lab report.
1 = Unsatisfactory
Excellent
2 = Fair
3= Satisfactory
Questions
4 = Very good
Rating
5=
Remarks
(1 to
5)
1. To what extent did you learn on the material in the
lab?
2. Are you able to apply knowledge gained in the lab to
similar problems?
3. Are you able to analyze and interpret data recorded
in the lab?
Lab. 04
Experiment title:
Implementing an input counter using switch de-bounce
Equipment:
KEIL uVision4/5 compiler
8051 trainer/AT 89s52
Universal programmer G540/G840
Procedure:
Write and test a C program to count up in binary on your 8051 Trainer.
The counter should start counting from 0 and go up to 255 after a
delay of 1 second.
Change the time delay in between the counts. Make sure the time
delay is long enough that you can observe the LED counting up.
In the above step,the maximum count was FFH(or 255). Modify the
above program to set maximum count to 10 (00001010).
Change the maximum count to the value of your age and observe the
LED counting up to that number.
19
Learning outcomes:
Be able to write a software delay to implement a counter.
Developing a portable system.
.
20
Questions:
If variable is 8 bit in length used in a counter, what would be the value in the counter
after 256 iterations if it started from 0.
21
Each student is required to perform the lab and submit the following
Performa along with the lab report.
1 = Unsatisfactory
Excellent
2 = Fair
3= Satisfactory
Questions
4 = Very good
Rating
5=
Remarks
(1 to
5)
1. To what extent did you learn on the material in the
lab?
2. Are you able to apply knowledge gained in the lab to
similar problems?
3. Are you able to analyze and interpret data recorded
in the lab?
22
Lab. 05
Experiment title:
Implementing a soft timer on 8051 trainer using C
Equipment:
Keil uVision4/5 compiler
8051 trainer
Universal programmer
Procedure:
Write a C program to implement a timer which can down count using
8051 trainer.
It should show the binary count on the LEDs connected to one of the
ports for example P2.
A push button is connected to P1.0.
P0 will be configured as an input.
The dip switched connected to this P0 will be used to load the timer maximum value.
Switch de-bounce will be implemented for P1.0.
Write a C program using KEIL such that the timer maximum value is loaded via the dip
switches connected to P0.
When the push button connected to P1.0 is pressed and released the timer starts down
counting from the maximum value loaded by the dip switches to zero.
This down counting binary pattern must be shown on led connected to P2.
Write a delay function such that there is a delay of exactly one second between the
counts.
23
When the down count reaches zero an LED connected to P1.1 is turned on.
One more feature is that whenever the push button connected to P1.0 is pressed and
released during the down counting the timer stops and when it is again pushed the timer
resumes. (optional)
Learning outcomes:
Be able to write a software delay to implement a timer.
Developing a portable system.
.
Questions:
How can we implement an infinite loop using for loop?
How can we time out an infinite loop?
24
Each student is required to perform the lab and submit the following
Performa along with the lab report.
1 = Unsatisfactory
Excellent
2 = Fair
3= Satisfactory
Questions
4 = Very good
Rating
5=
Remarks
(1 to
5)
1. To what extent did you learn on the material in the
lab?
2. Are you able to apply knowledge gained in the lab to
similar problems?
3. Are you able to analyze and interpret data recorded
in the lab?
Lab. 06
Experiment title:
Timer programming
a) Generating a Hardware delay using an 8051 timer
b) Implementing a pulse counter using an 8051 timer
Equipment:
8051 Trainer
8051 KEIL Compiler
Oscilloscope
Speaker (optional)
74LS04 Inverter (optional)
Universal programmer
Procedure:
Hardware delay:
One can use the 8051 Timer to generate time delay to toggle a bit
using the following program:
26
Pulse counter:
Connect the square wave from function generator to pin P3.4 for Timer
0 and set the frequency to 1 Hz.
Write and run a program for counter/timer 0 to count up from 00 to a
maximum of 255 (FFH) as each pulse is fed into the 8051.
27
Learning outcomes:
To program the 8051 timer in different modes.
Learn to use 8051 timers as pulse counters.
Questions:
(a) timer/counter 0
(b) timer/counter 1
If timer/counter 0 is used in mode 1 to count an external event, explain
when TF0 is set to high.
If timer/counter 1 is used in mode 2 to count an external event, explain
when TF0 is set to high.
29
Each student is required to perform the lab and submit the following
Performa along with the lab report.
1 = Unsatisfactory
Excellent
2 = Fair
3= Satisfactory
Questions
4 = Very good
Rating
5=
Remarks
(1 to
5)
1. To what extent did you learn on the material in the
lab?
2. Are you able to apply knowledge gained in the lab to
similar problems?
3. Are you able to analyze and interpret data recorded
in the lab?
Lab. 07
Experiment title:
PWM generation
a) Using software delay
b) Using 8051 timers
Equipment:
Procedure:
a) Using software delay:
Write a C program to generate a square wave frequency on a pin of P2.
31
Now examine the frequency using the oscilloscope. Modify the count
value to make it exactly 200Hz frequency.
Modify the above program to make Variable frequencies.
Modify the above program for different duty cycles. (25%, 75%)
Connect the 8 DIP switches on the trainer to P1. Then use the Switches
to change the frequency and examine the Freq. oscilloscope.
If you have access to a Buzzer, connect it to pin P2.7 with a 74LS04
Inverter as a driver and see how the buzzer creates different sounds.
You can also connect this pin to an Led on the trainer through the dip
switch.
32
Learning outcomes:
To be able to generate PWM signals of any duty cycle using software delays in 8051.
.
Questions:
Can this PWM signal be used to control the speed of a dc motor?
What is the maximum source sink current of an 8051 port pin.
Can we generate quadrature encoded signal in 8051?
Each student is required to perform the lab and submit the following
Performa along with the lab report.
33
1 = Unsatisfactory
Excellent
2 = Fair
3= Satisfactory
Questions
4 = Very good
Rating
5=
Remarks
(1 to
5)
1. To what extent did you learn on the material in the
lab?
2. Are you able to apply knowledge gained in the lab to
similar problems?
3. Are you able to analyze and interpret data recorded
in the lab?
34
Lab. 08
Experiment title:
Interfacing a DC motor to 8051
Equipment:
KEIL compiler
Motor driver circuit
Dc motor
Oscilloscope
8051 trainer
Universal programmer
G540
Procedure:
Using your 8051 trainer, build the circuit shown in Figure 17-6 (or 1718 in older edition) of the textbook.
35
Truth table:
clockwise. Use
P1.1=0 for CW and P1.1=1 for CCW. If you have set up serial 8051
communication, use
x86 PC to send letters R and L for clockwise and counter clockwise,
respectively.
After making sure that Activity 1 works, write and run the following:
Use P1.7 and P1.6 to choose the speed of rotation.
Learning outcomes:
To interface a DC motor to the 8051.
To write a program to control the speed and direction of DC motor rotation by the user.
36
Questions:
What is a use of Optoisolator ?
True or false. The DC motor speed is proportional to width of square wave applied to the
DC.
Give the RPM for DC motor used in this Lab
What is the disadvantage of using CPL instruction for turning on and
off the DC motor?
Explain the PWM
37
Each student is required to perform the lab and submit the following
Performa along with the lab report.
1 = Unsatisfactory
Excellent
2 = Fair
3= Satisfactory
Questions
4 = Very good
Rating
5=
Remarks
(1 to
5)
1. To what extent did you learn on the material in the
lab?
2. Are you able to apply knowledge gained in the lab to
similar problems?
3. Are you able to analyze and interpret data recorded
in the lab?
38
Lab. 09
Experiment title:
8051 interrupts programming
Programming the external hardware interrupts
Equipment:
8051 trainer
8051 KEIL Compiler
Square wave generator
Procedure:
Write an 8051 program to get data from a single bit of P1.0 (connected
to DIP SW) and send it to P2.7 (connected to LED) continuously while
an interrupt can do the following:
Connect the INT0 (or INT1) pin to a normally high debounce SW and
any time the switch is pressed, a single LED is turned on.
39
Write an 8051 program to get data from a single bit of P1.0 (connected
to DIP SW) and send it to P2.7 (connected to LED) continuously while
an interrupt will do the following:
A square wave is connected to the INT0 (pin 3.2) and any time a H-toL pulse comes in a single LED is turned on. The rate of "On" and "Off" is
the rate of the square wave. In this activity you can also use INT1.
Learning outcomes:
Learn to use 8051 external interrupt sources.
Learn to use 8051 timer interrupt sources.
Questions:
Name all of the hardware interrupts in the 8051 and their vector table
addresses.
On reset, INT0 (and INT1) are _________ (edge, level) triggered.
On reset, which interrupt has the highest priority?
True or False. There is only a single interrupt for the serial data
transfer.
40
Each student is required to perform the lab and submit the following
Performa along with the lab report.
1 = Unsatisfactory
Excellent
2 = Fair
3= Satisfactory
Questions
4 = Very good
Rating
5=
Remarks
(1 to
5)
1. To what extent did you learn on the material in the
lab?
2. Are you able to apply knowledge gained in the lab to
similar problems?
3. Are you able to analyze and interpret data recorded
in the lab?
41
Lab. 10
Experiment title:
a) Displaying a message using serial com port on hyper terminal
b) Receiving bytes of data at the serial com and sending to the port
42
Equipment:
Procedure:
Transmitting data:
Write a program to receive bytes of data serially via the serial port and
put them in P1. Set the Baud rate at 9600, 8bit data, and 1 stop bit.
Use timer 1 for baud rate generation.
Learning outcomes:
Learn to use serial com in 8051.
Questions:
The 8051 TxD and RxD signals ________ (are, are not) TTL-compatible.
In this lab, what is the role of the MAX233 (MAX232) chip?
With XTAL=11.0592 MHz, what is the maximum baud rate for the
8051?
Show how to achieve the maximum baud rate in Question 3.
What is the role of TI and RI?
True or false. The 8051 can transfer data in full-duplex.
For full duplex, what are the absolute minimum signals needed
between the 8051 Trainer and the x86 PC? Give their names.
43
Each student is required to perform the lab and submit the following
Performa along with the lab report.
1 = Unsatisfactory
Excellent
2 = Fair
3= Satisfactory
Questions
4 = Very good
Rating
5=
Remarks
(1 to
5)
1. To what extent did you learn on the material in the
lab?
2. Are you able to apply knowledge gained in the lab to
similar problems?
3. Are you able to analyze and interpret data recorded
in the lab?
Lab. 11
Experiment title:
8051 timer and serial com port interrupt programming
Equipment:
8051 trainer
8051 KEIL Compiler
Procedure:
Write an 8051 program to get data from a single bit of P1.0 (connected
to DIP SW) and send it to P2.7 (connected to LED) continuously while
an interrupt will do the following: One of the timers will toggle the PX.Y
bit every 100 microseconds.
Write an 8051 program to get data from a single bit of P1.0 (connected
to DIP SW) and send it to P2.7 (connected to LED) continuously while
an interrupt will do the following: A serial interrupt service routine will
receive data from a PC and display it on one of the ports. (Either
connect LEDs to this port to examine the data coming in or display the
received data on an LCD).
45
Learning outcomes:
To be able to use serial interrupts in 8051
Questions:
Name all the Timer interrupts in the 8051 and their vector table
addresses.
In timer mode 1, indicate when TF0 causes the interrupt.
In timer mode 2, indicate when TF0 causes the interrupt.
True or False. There is only a single interrupt for the both Timer 0 and
1.
46
Each student is required to perform the lab and submit the following
Performa along with the lab report.
1 = Unsatisfactory
Excellent
2 = Fair
3= Satisfactory
Questions
4 = Very good
Rating
5=
Remarks
(1 to
5)
1. To what extent did you learn on the material in the
lab?
2. Are you able to apply knowledge gained in the lab to
similar problems?
3. Are you able to analyze and interpret data recorded
in the lab?
Lab. 12
Experiment title:
Implementing switch de-bounce using Finite State Machine
Bouncing on
press
pressed
The actual switch press has four possible
states
If switch
If switch not
pressed
after
The desired output of the switch status variable should have two states (after
debouncing)
after debounce
debounce period
Switch
period
pressed
Pressed state
If switch pressed
after debounce
period
Switch
not
pressed
Bouncing on
release
Not pressed
state
If switch 48
not
pressed after
debounce period
Equipment:
KEIL compiler
8051 trainer
Procedure:
Create a new project Lab12 in folder Lab12.
Complete the main.c file yourself. Inside the main() function write the code such that if
button is pressed then LED flashes at 1 Hz, and if it is not pressed then LED flashes at 2 Hz.
Implement a periodic task for reading button input as a state machine using switch-case
construct. Do not use for() or while() loops inside tasks to avoid blocking code.
Learning outcomes:
To design a finite state machine.
49
Questions:
What are the three states of a push button?
Write three benefits of Timed Cyclic Executive software architecture over a simple
super-loop?
What are hazards of using for() loop or while() loop inside a periodic task()?
Each student is required to perform the lab and submit the following
Performa along with the lab report.
1 = Unsatisfactory
Excellent
2 = Fair
3= Satisfactory
Questions
4 = Very good
Rating
5=
Remarks
(1 to
5)
1. To what extent did you learn on the material in the
lab?
2. Are you able to apply knowledge gained in the lab to
similar problems?
3. Are you able to analyze and interpret data recorded
in the lab?
50
Lab. 13
Experiment title:
LCD interfacing with 8051
51
52
Equipment:
KEIL compiler
LCD (2X16)
8051 trainer
Procedure:
Connect the LCD to your 8051 trainer as shown in section 12.1 of the
textbook.
53
Then compile and run the LCD driver program from the book or as
provided by the instructor.
Now, modify the above program to display you first name and last
name, all on the same line
Repeat Activity 1 while also putting the year you graduated from high
school on the second line. When you run your program, the LCD should
show (for example):
Khurram Ahmed
Graduated in 2012
Write an LCD program to display your last name on the first line and
the current year on the second line. Both should be in the middle of the
line.
Learning outcomes:
To understand the operation modes of an LCD.
To interface and program an LCD.
Questions:
How does the LCD distinguish data from instruction codes when
receiving information at its data pin?
To send the instruction command code 01 to clear the display, we
must make RS = ___.
To send letter 'A' to be displayed on the LCD, we must make RS =
____.
What is the purpose of the E line? Is it an input or an output as far as
the LCD is concerned?
When is the information (command code or data) on the LCD pin
latched into the LCD?
Each student is required to perform the lab and submit the following
Performa along with the lab report.
1 = Unsatisfactory
Excellent
2 = Fair
Questions
3= Satisfactory
4 = Very good
Rating
5=
Remarks
54
(1 to
5)
1. To what extent did you learn on the material in the
lab?
2. Are you able to apply knowledge gained in the lab to
similar problems?
3. Are you able to analyze and interpret data recorded
in the lab?
Lab. 14
Experiment title:
Interfacing a keypad to an 8051
Equipment:
8051 trainer
8051 Keil Compiler
4x4 keyboard or any N x M matrix keyboard
8 of 6.8K ohms resistors
Procedure:
After you have mapped your keypad set, connect the keypad to the
8051 as shown in Chapter 12 of the textbook.
Write and run a program that scans your keyboard and displays any
character pressed by the user on the LCD.
56
Learning outcomes:
To interface a 4x4 keyboard (keypad) to the 8051 trainer.
Questions:
What is the purpose of generating the truth table for a given
keyboard?
57
2 = Fair
3= Satisfactory
Questions
4 = Very good
Rating
5=
Remarks
(1 to
5)
1. To what extent did you learn on the material in the
lab?
2. Are you able to apply knowledge gained in the lab to
similar problems?
3. Are you able to analyze and interpret data recorded
in the lab?
58
Lab. 15
Experiment title:
Interfacing ADC804 to 8051
Equipment:
8051 KEIL Compiler
8051 Trainer
59
ADC804
Potentiometer (10k)
TTL square wave and TTL square wave clock source
Procedure:
Connect a channel to potentiometer and LEDs of trainer to P1 pins.
60
Learning outcomes:
To interface an ADC804 to the 8051
Questions:
Indicate the direction of pin RD, WR and INTR from the point of view of
the
ADC804.
Give the steps for converting data and getting the data out of the
ADC804. State the status of the INTR pin in each step.
Give the role of signals INTR in selecting the ADC channel.
In the ADC804 assume that Vref is connected to 2.56 V. Find the
following.
61
a) step size
b) maximum range for Vin
c) D7 - D0 values if Vin = 1.2 V
d) Vin if D7 - D0 = 11111111
e) Vin if D7 - D0 = 10011100
In the ADC804 assume that Vref is connected to 2.7V. Find the
following.
a) step size
b) maximum range for Vin
c) D7 - D0 values if Vin = 1 V
d) Vin if D7 - D0 = 11111111
e) Vin if D7 D0 = 11011101
Each student is required to perform the lab and submit the following
Performa along with the lab report.
1 = Unsatisfactory
Excellent
2 = Fair
3= Satisfactory
Questions
4 = Very good
Rating
5=
Remarks
(1 to
5)
1. To what extent did you learn on the material in the
lab?
62
Lab. 16
Experiment title:
Interfacing a stepper motor to an 8051
Learn to calculate the required step size for the stepper motor.
Learn different bit patterns applied to the stepper motor for operation
See the pin configuration and the tables for the stepper motor.
Study from any book
63
Using your 8051 trainer, build the circuit shown in Chapter 15 of the
textbook.
Equipment:
8051 KEIL Compiler
8051 Trainer
Stepper motor
Procedure:
Circuit connections:
Learning outcomes:
To interface a stepper motor to the 8051.
To write a program to control the angle and direction of stepper motor rotation by the user.
Questions:
What is a step angle? Define steps per revolution.
If a given stepper motor has a step angle of 5 degrees, find the
number of steps per rotation.
Give the four sequences for counter clockwise if it starts with
10011001 (binary).
65
Each student is required to perform the lab and submit the following
Performa along with the lab report.
1 = Unsatisfactory
Excellent
2 = Fair
3= Satisfactory
Questions
4 = Very good
Rating
5=
Remarks
(1 to
5)
1. To what extent did you learn on the material in the
lab?
2. Are you able to apply knowledge gained in the lab to
similar problems?
3. Are you able to analyze and interpret data recorded
in the lab?
67