Embedded System Lab Manual
Embedded System Lab Manual
Embedded System Lab Manual
Dec 2024
Lab Manual
Embedded Systems
Design Lab
1
Name: Embedded Systems Design Lab L
Subject Code: 140704/200704 T
P
Course Objectives
The objective of this course is to provide students with hands-on experience in
designing, implementing, and testing embedded systems using microcontrollers.
List of Experiments
1. Write an assembly language program to transfer a block of data bytes from
source memory to destination memory and demonstrate on 8051
microcontroller board.
2. Write an assembly language program to perform Addition/subtraction of a
given number and demonstrate on 8051 microcontroller board.
3. Write an assembly language program to demonstrate conditional bit jump,
conditional byte jump, unconditional jump, call and return instructions on
8051 microcontroller board.
4. Write an assembly language program to demonstrate the basic interface
between an LCD display and 4 x 4matrix key board and demonstrate on
8051 microcontroller board.
5. Write an assembly language program to implement a basic temperature
sensor using an ADC output is displayed on a 2x16 LCD and demonstrate on
8051 microcontroller board.
6. Write an assembly language program to implement the basic wave form
generation using DAC, output is displayed on a CRO and demonstrate on
8051 microcontroller board.
7. Write an Arduino IDE program for Blinking an LED with a delay of 2
seconds and demonstrate on 8051 microcontroller Ardunio board.
8. Write an Arduino IDE program for to demonstrate automatic traffic light
control using Ardunio board. Turn ON Red LED for 4 seconds, Green LED
for 5 seconds, Yellow for 2seconds.
9. Write an Arduino IDE program for Blinking an 5 LEDs with a delay of 2
seconds in a sequence.
10.Write an Arduino IDE program for connecting a servo motor to Arduino
board and rotate in clockwise and anti-clockwise direction using switches.
2
Course Outcomes:
After successful completion of the course, students will be able to:
CO1. Develop 8051 assembly language programming skills for the various
arithmetic and logical operations.
CO2. Demonstrate interfacing of 8051 microcontroller board with various
interfacing devices.
CO3. Design Arduino board based automated electronic systems.
3
8051 Microcontroller Programming:
4
Department of Electronics Engineering ,
19. IMP: make sure go to options🡪 Advance options🡪 Hwdr Config.-->”Use
DTR to control RST ” box is unchekcked.
20. Now, Make sure that jumper settings are as per 4-bit and 8-bit operation.
(Refer Dyna51 User Manual).
21. Press Start.
22. At bottom of the Flash Magic window “Finished ” will be displayed.
5
Department of Electronics Engineering ,
EXPERIMENT NO.: 1
AIM: Write an assembly language program to transfer a block of data bytes from
source memory to destination memory and demonstrate on 8051 microcontroller
board.
APPRATUS:
1. 8051 micro controller kit.
2. PC for connecting the DYNA51 kit.
3. Keil-U-Vision software for compilation of program.
PROGRAM:
MOV R0,#50H // Initialize the source memory pointer
MOV R1,#60H // Initialize the destination memory pointer
MOV R2,#05H // Initialize Iteration counter
BACK: MOV A,@R0 // Get the data from source memory pointer and Load
// into Accumulator
XCH A,@R1 // Exchange data between Accumulator and
// destination memory pointer
MOV @R0,A // Store the data into source memory pointer
INC R0 // Increment the source memory pointer
INC R1 // Increment the destination memory pointer
Before execution:
D:0x50H: 01 02 03 04 05 00
D:0X60H: 06 07 08 09 10 00
6
Department of Electronics Engineering ,
After execution:
D:0x50H: 06 07 08 09 10 00
D:0X60H: 01 02 03 04 05 00
7
Department of Electronics Engineering ,
EXPERIMENT NO.: 2
APPRATUS:
4. 8051 micro controller kit.
5. PC for connecting the DYNA51 kit.
6. Keil-U-Vision software for compilation of program.
Program :
Org 0000h
mov a,#10h
mov b,#5h
add a,b
mov r1,a
clr a
mov b,#00h
mov a,#20h
mov b,#10h
subb a,b
mov r2,a clr
a
mov b,#00h
mov a,#2h
mov b,#2h
mul ab mov
r3,a clr a
mov b, #00h
mov a,#21h
mov b,#2h
div ab
mov r4,a
mov r5,b
end
8
Department of Electronics Engineering ,
EXPERIMENT NO.: 3
APPRATUS:
7. 8051 micro controller kit.
8. PC for connecting the DYNA51 kit.
9. Keil-U-Vision software for compilation of program.
10.LCD PIO CARD for DYNA51.
Theory: This program keeps checking P1.0 for low signal. Once a low signal
arrives, program checks for AAh at PORT 0. If the data is AAh a counter will
start.
PROGRAM:
ORG 00H
/*INITIALIZING THE COUNTER AND PORTS*/
MAIN: MOV P0, #0FFH
MOV P1, #0FFH
MOV P2, #00H
MOV R0, #00H
/*WAITING FOR THE ARRIVAL OF LOW SIGNAL AT PORT 1.0*/
WAIT: JB P1.0, WAIT // CONDITIONAL BIT JUMP
ACALL VERIFY_DATA // CONDITIONAL CALL
SJMP WAIT // UNCONDITIONAL JUMP
//CHECKING THE DATA AT P0 FOR 0AAh
VERIFY_DATA:MOV A, P0
CJNE A, #0AAH, RETURN // CONDITIONAL BYTE JUMP
9
Department of Electronics Engineering ,
INC R0
MOV P2, R0
ACALL DELAY // UNCONDITIONAL CALL
RETURN:RET // RETURN
/*JUST A DELAY SUBROUTINE */
DELAY:NOP
MOV R2,#25
10
Department of Electronics Engineering ,
EXPERIMENT NO: 4
APPRATUS:
11.8051 micro controller kit.
12. PC for connecting the DYNA51 kit.
13. Keil-U-Vision software for compilation of program.
14.LCD PIO CARD for DYNA51.
Program:
ORG 00H
MOV DPTR, #LCDString ; Load the address of the LCD string
CALL LCD_Init ; Initialize the LCD
CALL Keypad_Init ; Initialize the keypad
MAIN:
CALL Read_Keypad ; Read the keypad
MOV A, R0 ; Store the pressed key in A
Display_LCD:
MOV A, @DPTR ; Load the character from the string
CJNE A, #00H, Display_Char
; End of the string, loop back to read keypad
SJMP MAIN
11
Department of Electronics Engineering ,
Display_Char:
CALL Send_Data ; Send character to LCD
INC DPTR ; Move to the next character in the string
SJMP MAIN
END
12
Department of Electronics Engineering ,
EXPERIMENT NO: 5
APPRATUS:
15.8051 micro controller kit.
16. PC for connecting the DYNA51 kit.
17. Keil-U-Vision software for compilation of program.
18.LCD PIO CARD for DYNA51.
Theory: Read an analog voltage at the input of ADC given as the knob position
using 8051 microcontrollers. An Analog to Digital Converter (ADC) is a very
useful feature that converts an analog voltage on a pin to a digital number.
The binary counter is initially reset to 0000; the output of integrator reset to 0V
and the input to the ramp generator or integrator is switched to the unknown
analog input voltage VA. The analog input voltage VA is integrated by the
inverting integrator and generates a negative ramp output. The output of
comparator is positive and the clock is passed through the AND gate. This results
in counting up of the binary counter.
OPERATING PROCEDURE FOR ADC CARDS:
3. Connect ADC card to 26 pin frc connector of Dyna-51EB.
4. Connect +12V ,-12V and GND supply lines to the ADC card.
5. Connect 16X2 LCD card (J1) to PORT 3 of Dyna-51EB in 4 bit
mode.
6. Download the program adc.hex (given in the CD) through flash magic.
Apply the analog input at the phono jack
Program
ORG 0000H
L
J
M
P
M
A
I
13
Department of Electronics Engineering ,
N 0
0
O 3
R 0
G H
MAIN: NOP
EN EQU P2.0
RS EQU P2.2
14
Department of Electronics Engineering ,
// RW EQU P1.1
DAT EQU P2
LCALL LCD_INT
LCALL CLEAR
LCALL LINE1
MOV DPTR, #MYDATA
LCALL LOOP
LCALL LINE2
MOV DPTR, #MYDAT2
LCALL LOOP
LCALL LINE5
lcall dispH
again: lcall adconvert
LCALL LINE3
lcall adisph
LCALL LINE4
lcall adispl
SJMP again
;==================================================================
=======
W_NIB: PUSH ACC ;Save A for low nibble
ORL DAT,#0F0h ;Bits 4..7 <- 1
ORL A,#0Fh ;Don't affect bits 0-3
ANL DAT,A ;High nibble to display
SETB EN
CLR EN
POP ACC ;Prepare to send
SWAP A ;...second nibble
ORL DAT,#0F0h ; Bits 4...7 <- 1
ORL A,#0Fh ; Don't affect bits 0...3
ANL DAT,A ;Low nibble to display
SETB EN
CLR EN
RET
;==================================================================
=======
LCD_INT: CLR RS
// CLR RW
CLR EN
SETB EN
MOV DAT,#028h
CLR EN
LCALL SDELAY
MOV A,#28h
LCALL COM
MOV A,#0Ch
LCALL COM
MOV A,#06h
15
Department of Electronics Engineering ,
LCALL COM
LCALL CLEAR
MOV A,#080H
LCALL COM
RET
;==================================================================
=======
CLEAR: CLR RS
MOV A,#01h
LCALL COM
RET
;==================================================================
=======
DATAW: SETB RS
// CLR RW
LCALL W_NIB
LCALL LDELAY
RET
;==================================================================
=======
SDELAY: MOV R6,#1
HERE2: MOV R7,#255
HERE: DJNZ R7,HERE
DJNZ R6,HERE2
RET
;==================================================================
=======
LDELAY: MOV R6,#1
HER2: MOV R7,#255
HER: DJNZ R7,HER
DJNZ R6,HER2
RET
;==================================================================
=======
COM: CLR RS
// CLR RW
LCALL W_NIB
LCALL SDELAY
RET
;==================================================================
=======
LINE1: MOV A,#80H
LCALL COM
RET
LINE2: MOV A,#0C0H
LCALL COM
RET
LINE3: MOV A,#0c9H
LCALL COM
16
Department of Electronics Engineering ,
RET
LINE4: MOV A,#0cah
LCALL com
RET
LINE5: MOV A,#0cbh
LCALL com
RET
;==================================================================
=======
LOOP: CLR A
MOVC A,@A+DPTR
JZ GO_B2
LCALL DATAW
LCALL SDELAY
INC DPTR
SJMP LOOP
GO_B2: RET
ADisph:
M
O
V
ADispl: a
,
r
3
L
C
A
L
L
D
A
T
A
W
L
C
A
L
L
S
D
E
L
A
Y
17
Department of Electronics Engineering ,
ret A
T
M A
O W
V
L
a C
, A
r L
4 L
L S
C D
A E
L L
L A
Y
D ret
;==================================================================
=======
MYDATA: DB " PIO-ADC-01 ",0
MYDAT2: DB " ADC i/p= ",0
dispH:
MOV a,#48H ;ascii for H
LCALL DATAW
LCALL SDELAY
ret
;==================================================================
====
adconvert:
;
START EQ P1.0 ; Pin 6 Start
EOC U P1.3 ; Pin 7 EOC
EQ
U
OE EQ P1.1 ; Pin 9 Output
U Enable
ALE EQ P1.2 ; Pin 22 ALE
U
adata P0 ; Data Lines
EQU
18
Department of Electronics Engineering ,
; Read one byte of data from adc.
; Performs a analog conversion cycle.
; address of channel in register "ADDRESS",
; Returns data in BUFFER
; Destroys A.
MOV adata,#0FFH ; Data lines for input
SETB OE ; Disable output
SETB ALE ; Latch the address
NOP
nop
nop
NOP
SETB START ; Start the conversion
NOP
NOP
NOP
CLR START
NOP
NOP
EOCLOOP:
JNB EOC, EOCLOOP; Do until EOC high CLR
OE ; Output Enable
MOV a,adata ; Get data in buffer
SETB OE
CLR ALE
Result:
The Digital data corresponding to the analog input is shown in the LCD.
Viva Questions:
1. Why 8051 is called 8 bit microcontroller?
2. How much on chip ram is available on 8051?
3. What is special Function Registers (SFR)?
4. Which bit of the flag register is set when output overflows to the sign bit?
5. Explain whether Port 0 of 8051 cab be used as input output port?
19
Department of Electronics Engineering ,
EXPERIMENT NO: 6
AIM: - Write an assembly language program to implement the basic wave form
generation using DAC, output is displayed on a CRO and demonstrate on 8051
microcontroller board.
APPRATUS:
1. 8051 micro controller kit.
2. PC for connecting the DYNA51 kit.
3. Keil-U-Vision software for compilation of program.
4. DAC PIO CARD for DYNA51.
20
Department of Electronics Engineering ,
INC R0 ; Increment the data for the next value
CJNE R0, #255, GENERATE_WAVEFORM ; Loop until the waveform
completes a cycle
SJMP MAIN ; Repeat the process
END
ORG 0H
21
Department of Electronics Engineering ,
RET
Delay:
; Implement a delay to control the frequency
; You may need to adjust the delay to achieve the desired waveform
frequency
MOV R2, #DELAY_COUNT
DELAY_LOOP:
DJNZ R2, DELAY_LOOP
RET
END
22
Department of Electronics Engineering ,
EXPERIMENT NO: 7
AIM: - Write an Arduino IDE program for Blinking an LED with a delay of 2
seconds and demonstrate on 8051 microcontroller Ardunio board.
Materials:
● Arduino board (e.g., Arduino Uno)
● LED
● Resistor (220-330 ohms)
● Breadboard
● Jumper wires
Procedure:
1. Hardware Setup:
● Connect the cathode (shorter leg) of the LED to a current-limiting resistor
(220-330 ohms).
● Connect the other end of the resistor to a digital pin (e.g., Pin 13) on the
Arduino board.
● Connect the anode (longer leg) of the LED to the GND (ground) pin on
the Arduino board.
● Ensure the hardware connections are secure.
2. Arduino IDE Programming:
● Open the Arduino IDE on your computer.
● Write the following code:
const int ledPin = 13; // Pin 13 is the default built-in LED pin
void setup()
{ pinMode(ledPin,
OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH); // Turn the LED on
delay(2000); // Wait for 2 seconds
23
Department of Electronics Engineering ,
digitalWrite(ledPin, LOW); // Turn the LED off
24
Department of Electronics Engineering ,
delay(2000); // Wait for 2 seconds
}
3. Upload the Code:
Connect your Arduino board to your computer using a USB cable.
Select the correct board and port from the "Tools" menu in the Arduino IDE.
Click the "Upload" button to upload the code to the Arduino board.
4. Observation:
You should see the LED on your Arduino board blinking with a 2-second delay.
Conclusion:
You have successfully programmed an Arduino board to blink an LED with a 2-
second delay, demonstrating the basic functionality of an Arduino
microcontroller.
25
Department of Electronics Engineering ,
EXPERIMENT NO: 8
Procedure:
3. Hardware Setup:
● Connect the cathode (shorter leg) of the LED to a current-limiting resistor
(220-330 ohms).
● Connect the other end of the resistor to a digital pin (e.g., Pin 13) on the
Arduino board.
● Connect the anode (longer leg) of the LED to the GND (ground) pin on
the Arduino board.
● Ensure the hardware connections are secure.
4. Arduino IDE Programming:
● Open the Arduino IDE on your computer.
● Write the following code:
void setup() {
// Set the LED pins as outputs
pinMode(redLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
26
Department of Electronics Engineering ,
pinMode(greenLED, OUTPUT);
}
void loop() {
// Red light digitalWrite(redLED,
HIGH);
digitalWrite(yellowLED, LOW);
digitalWrite(greenLED, LOW);
delay(4000); // 4 seconds
// Green light
You should see the Red LED for 4 seconds, Green LED for 5 seconds, Yellow
for 2seconds.
Conclusion:
You have successfully programmed an Arduino board to blink Red LED for 4
seconds, Green LED for 5 seconds, Yellow for 2seconds.
27
Department of Electronics Engineering ,
EXPERIMENT NO: 9
AIM: - Write an Arduino IDE program for Blinking an 5 LEDs with a delay of
2 seconds in a sequence.
Materials:
● Arduino board (e.g., Arduino Uno)
● LED
● Resistor (220-330 ohms)
● Breadboard
● Jumper wires
Procedure:
5. Hardware Setup:
● Connect the cathode (shorter leg) of the LED to a current-limiting resistor
(220-330 ohms).
● Connect the other end of the resistor to a digital pin (e.g., Pin 13) on the
Arduino board.
● Connect the anode (longer leg) of the LED to the GND (ground) pin on
the Arduino board.
● Ensure the hardware connections are secure.
6. Arduino IDE Programming:
● Open the Arduino IDE on your computer.
● Write the following code:
void setup() {
// Set the LED pins as outputs
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
28
Department of Electronics Engineering ,
void loop() {
for (int i = 0; i < numLeds; i++)
{ digitalWrite(ledPins[i], HIGH); // Turn the LED
on delay(2000); // Wait for 2 seconds
digitalWrite(ledPins[i], LOW); // Turn the LED off
}
}
3. Upload the Code:
Connect your Arduino board to your computer using a USB cable.
Select the correct board and port from the "Tools" menu in the Arduino IDE.
Click the "Upload" button to upload the code to the Arduino board.
4. Observation:
29
Department of Electronics Engineering ,
EXPERIMENT NO: 10
AIM: - Write an Arduino IDE program for connecting a servo motor to Arduino
board and rotate in clockwise and anti-clockwise direction using switches.
Materials:
● Arduino board (e.g., Arduino Uno)
● LED
● Resistor (220-330 ohms)
● Breadboard
● Jumper wires
Procedure:
7. Hardware Setup:
● Connect the cathode (shorter leg) of the LED to a current-limiting resistor
(220-330 ohms).
● Connect the other end of the resistor to a digital pin (e.g., Pin 13) on the
Arduino board.
● Connect the anode (longer leg) of the LED to the GND (ground) pin on
the Arduino board.
● Ensure the hardware connections are secure.
8. Arduino IDE Programming:
● Open the Arduino IDE on your computer.
● Write the following code:
void setup() {
30
Department of Electronics Engineering ,
// Set the LED pins as outputs
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT);
}
void loop() {
for (int i = 0; i < numLeds; i++)
{ digitalWrite(ledPins[i], HIGH); // Turn the LED
on delay(2000); // Wait for 2 seconds
digitalWrite(ledPins[i], LOW); // Turn the LED off
}
}
31
Department of Electronics Engineering ,