Embedded Systems Assignment
Embedded Systems Assignment
(Karachi Campus)
Department of Software Engineering
ASSIGNMENT # 01 – Fall 2023
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
Solution:
SHAHOOD REHAN 2
BAHRIA UNIVERSITY,
(Karachi Campus)
Department of Software Engineering
ASSIGNMENT # 01 – Fall 2023
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;
DELAY:
MOV R1, #0FFH
SHAHOOD REHAN 4
BAHRIA UNIVERSITY,
(Karachi Campus)
Department of Software Engineering
ASSIGNMENT # 01 – Fall 2023
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 delay subroutine
; Adjust the loop count to
control the delay
MOV R1, #0FFH
DELAY_LOOP:
DJNZ R1, DELAY_LOOP
RET
SHAHOOD REHAN 6
BAHRIA UNIVERSITY,
(Karachi Campus)
Department of Software Engineering
ASSIGNMENT # 01 – Fall 2023
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