0% found this document useful (0 votes)
24 views

Embedded Systems Assignment

The document is an assignment from Bahria University for an Embedded Systems course. It contains 3 questions asking the student to: 1) Write code in Assembly and C to interface with 8 LEDs using port 1, including operations like rotation and turning specific LEDs on/off. 2) Draw the block diagram of a seven segment display and write code in C and Assembly to display digits on it. 3) Draw the block diagram of two seven segment displays and write a program in Assembly and C to display digits from 0-9 on both displays.

Uploaded by

Zain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Embedded Systems Assignment

The document is an assignment from Bahria University for an Embedded Systems course. It contains 3 questions asking the student to: 1) Write code in Assembly and C to interface with 8 LEDs using port 1, including operations like rotation and turning specific LEDs on/off. 2) Draw the block diagram of a seven segment display and write code in C and Assembly to display digits on it. 3) Draw the block diagram of two seven segment displays and write a program in Assembly and C to display digits from 0-9 on both displays.

Uploaded by

Zain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

BAHRIA UNIVERSITY,

(Karachi Campus)
Department of Software Engineering
ASSIGNMENT # 01 – Fall 2023

COURSE TITLE: Embedded Systems COURSE CODE: CEN-439


CLASS: BSE-5(A) SHIFT: Morning
INSTRUCTOR: Dr. Qamaruddin Memon DATE: 22nd OCT 2023
MAX MARKS: 5 NAME: SHAHOOD REHAN
REG. NO: 79310 ENROLL: 02-131212-053

Question No#1: Write a code of LED interface in Assembly and C through


different P1, P2, P3 Block diagram of 8 LEDs:
mov A, #055h
1. Perform Rotation operation
2. Perform four on and off
3. Two on and six off
4. Write a c code for the above program.

Solution:
ORG 00H ; Start of program MOV R2, #50
MOV A, #55H ; DELAY_LOOP:
MOV P1, A ; DJNZ R2, DELAY_LOOP
; Perform Rotate Operation (Right ; Four LEDs ON and OFF
Shift) MOV A, #0F0H ; Binary value for
RR A ; Right rotate A through 11110000b (4 LEDs ON)
carry MOV P1, A ; Output A to Port 1
MOV P1, A ; Output A to Port 1 (P1)
(P1) ; Delay for visualization
; Delay for visualization MOV R2, #50

SHAHOOD REHAN 1
BAHRIA UNIVERSITY,
(Karachi Campus)
Department of Software Engineering
ASSIGNMENT # 01 – Fall 2023

DELAY_LOOP2: ; Delay for visualization


DJNZ R2, DELAY_LOOP2 MOV R2, #50
MOV A, #0F0H ; Binary value for DELAY_LOOP4:
11110000b (4 LEDs OFF) DJNZ R2, DELAY_LOOP4
MOV P1, A ; Output A to Port 1 MOV A, #0C3H ; Binary value for
(P1) 11000011b (6 LEDs OFF)
; Delay for visualization MOV P1, A ; Output A to Port 1
MOV R2, #50 (P1)
DELAY_LOOP3: ; Delay for visualization
DJNZ R2, DELAY_LOOP3 MOV R2, #50
; Two LEDs ON and Six OFF DELAY_LOOP5:
MOV A, #03CH ; Binary value for DJNZ R2, DELAY_LOOP5
00111100b (2 LEDs ON) END ; End of program
MOV P1, A ; Output A to Port 1
(P1)

1. Blink alternate LEDs at P3 using software delay


2. Blink P0 LEDs in cyclic fashion using software delay
3. Count the number of times a switch at P1.1 is pressed and display the count in P2If
you have any doubt please
comment below.

Solution:

1. Blink alternate LEDs at P3 using software delay.


ORG 00H ; Start of program SJMP MAIN ; Repeat
MAIN: DELAY:
MOV A, #55H ; Initial value ; Implement a delay loop
for alternate LEDs (01010101b) here
MOV P3, A ; Output to P3 ; Adjust the loop count to
ACALL DELAY ; Call delay control the delay
subroutine MOV R1, #0FFH
CPL A ; Complement A DELAY_LOOP:
(Toggle LEDs) DJNZ R1, DELAY_LOOP
MOV P3, A ; Output to P3 RET
ACALL DELAY ; Call delay END ; End of program
subroutine

SHAHOOD REHAN 2
BAHRIA UNIVERSITY,
(Karachi Campus)
Department of Software Engineering
ASSIGNMENT # 01 – Fall 2023

2. Blink P0 LEDs in cyclic fashion using software delay.

Solution:
ORG 00H ; Start of program SJMP MAIN ; Repeat
MAIN: DELAY:
MOV A, #01H ; Initial value ; Implement a delay loop here
for cyclic LEDs (00000001b) ; Adjust the loop count to
MOV P0, A ; Output to P0 control the delay
ACALL DELAY ; Call delay MOV R1, #0FFH
subroutine DELAY_LOOP:
RLC A ; Rotate left DJNZ R1, DELAY_LOOP
through carry (cyclic shift) RET
MOV P0, A ; Output to P0 END ; End of program
ACALL DELAY ; Call delay
subroutine

3. Count the number of times a switch at P1.1 is pressed and display the
count in P2If you have any doubt please comment below.

Solution:
ORG 00H ; Start of program XRL A, R2 ; Check for changes
COUNT EQU 30H ; Memory location in P1.1
for the count JZ NO_CHANGE
MAIN: INC COUNT ; Increment count
MOV P1, #02H ; Configure P1.1 when P1.1 is pressed
as an input NO_CHANGE:
MOV A, P1 ; Read P1 into A MOV R2, A ; Update the state
MOV R2, A ; Store the of P1.1
current state of P1.1 MOV P2, A ; Display the count
CLR A ; Clear A on P2
MOV COUNT, A ; Clear the count SJMP CHECK_SWITCH ; Repeat
CHECK_SWITCH: END ; End of program
MOV A, P1 ; Read P1 into A

SHAHOOD REHAN 3
BAHRIA UNIVERSITY,
(Karachi Campus)
Department of Software Engineering
ASSIGNMENT # 01 – Fall 2023

Question No#2: Draw the Block diagram of seven segment display and write its
code in C and Assembly:

Solution:

C Code:

#include <reg52.h>
#define SEGMENT_PORT P2 // while (1) {
Assuming P2 is connected to SEGMENT_PORT =
the seven-segment display SevenSegDigits[digit];
const unsigned char delay();
SevenSegDigits[] = { digit = (digit + 1)
0xC0, % 10;
0xF9, }
0xA4, }
0xB0, void delay() {
0x99, unsigned int i, j;
0x92, for (i = 0; i < 1000;
0x82, i++) {
0xF8, for (j = 0; j < 100;
0x80, j++) {
0x90
}; }
}
void main() { }
unsigned char digit = 0;

Assembly Code (for 8051 microcontroller):


DELAY_LOOP:
ORG 00H DJNZ R1, DELAY_LOOP
MAIN: RET
MOV R0, #00H
LOOP: END
MOV A, R0
ADD A, #48
MOV P2, A
ACALL DELAY
INC R0
CJNE R0, #10, LOOP
SJMP MAIN

DELAY:
MOV R1, #0FFH

SHAHOOD REHAN 4
BAHRIA UNIVERSITY,
(Karachi Campus)
Department of Software Engineering
ASSIGNMENT # 01 – Fall 2023

Question No#3: Draw block diagram of two seven segment display.


Write a program in Assembly and C to display a digit from 0 to 9 in both seven
segment display.

Solution:
C Code:
#include <reg52.h> 0x90
sbit Display1 = P2^0; // Common };
pin for the first display void main() {
sbit Display2 = P2^1; // Common unsigned char digit = 0;
pin for the second display while (1) {
const unsigned char Display1 = 0;
SevenSegDigits[] = { Display2 = 1;
0xC0, P0 =
0xF9, SevenSegDigits[digit];
0xA4, delay();
0xB0,
0x99, Display1 = 1;
0x92, Display2 = 0;
0x82, P0 =
0xF8, SevenSegDigits[digit];
0x80,

SHAHOOD REHAN 5
BAHRIA UNIVERSITY,
(Karachi Campus)
Department of Software Engineering
ASSIGNMENT # 01 – Fall 2023

delay(); // Implement a unsigned int i, j;


delay function for (i = 0; i < 1000; i++) {
for (j = 0; j < 100; j++)
digit = (digit + 1) % 10; {
} // Delay loop
} }
}
void delay() { }
Assembly Code:
ORG 00H ;
MAIN:
MOV R0, #00H ;
MOV P2, #03H ;
LOOP:
MOV A, R0 ;
ADD A, #48 ;
CJNE P2, #01H, DIS1 ;
MOV P0, A ;
SJMP NEXT
DIS1:
MOV P0, A ;
NEXT:
ACALL DELAY ;
INC R0 ;
CJNE R0, #10, LOOP ;
SJMP MAIN

DELAY:
; Implement a delay subroutine
; Adjust the loop count to
control the delay
MOV R1, #0FFH
DELAY_LOOP:
DJNZ R1, DELAY_LOOP
RET

END ; End of program

SHAHOOD REHAN 6
BAHRIA UNIVERSITY,
(Karachi Campus)
Department of Software Engineering
ASSIGNMENT # 01 – Fall 2023

Question No#4: Write a program to display a well come to Bahria in LCD


display.

Solution:
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,10,9,8,7);
void setup()
{
lcd.begin(16,2);
}
void loop()
{
lcd.setCursor(0,0);
lcd.print("Welcome To");
lcd.setCursor(0,1);
lcd.print("Bahria"); }
}

SHAHOOD REHAN 7

You might also like