Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Sunday, January 1, 2023

BAHRIA UNIVERSITY ISLAMABAD


CAMPUS DEPARTMENT OF ELECTRICAL
ENGINEERING

ESD
“ASSIGNMENT 2”

STUDENT INFORMATION:
Sr Name Section ID E-Mail
No.
1. Muhammad 5D 01-133202-078 01-133202-
Mohsin a078@student.bahria.edu.pk
Murtaza

INSTRUCTOR:
Sr Name E-Mail
No.
1. Sohail Shehzad sohailshehzad.buic@bahria.edu.pk
Sunday, January 1, 2023

Question no 1: Produce/write an assembly code where 12 memory locations are defined. Take two
operands and store them in first two locations. Apply 2 arithmetic, 2 logical, 3 compare and 3 rotate
instructions and store their results in file registers respectively. Also show the contents of Status register and
specify the changes due to operations.

SOLUTION:

My Enr Number: 078 Hexa: 4E

CODE:
#INCLUDE<P18F452.INC>
CONFIG WDT=OFF

LOC1 EQU 40H


LOC2 EQU 41H
LOC3 EQU 42H
LOC4 EQU 43H
LOC5 EQU 44H
LOC6 EQU 45H
LOC7 EQU 46H
LOC8 EQU 47H
LOC9 EQU 48H
LOC10 EQU 49H
LOC11 EQU 4AH
LOC12 EQU 4BH
LOC13 EQU 4CH ;DUMMY ADDRESS

ORG 00H
MOVLW 0x00
CLRF LOC8
CLRF LOC9
CLRF LOC10
MOVWF TRISB
MOVLW 0xFF
MOVWF LOC1
MOVLW 0X4E
MOVWF LOC2
MOVFF LOC1,LOC13
ADDWF LOC13,F
MOVFF LOC13,LOC3
MOVFF LOC1,LOC13
SUBWF LOC13,F
MOVFF LOC13,LOC4
MOVFF LOC1,LOC13
XORWF LOC13,F
MOVFF LOC13,LOC5
MOVFF LOC1,LOC13
IORWF LOC13,F
MOVFF LOC13,LOC6
MOVFF LOC4,LOC13
CPFSGT LOC13
MOVFF LOC13,LOC7
MOVFF LOC5,LOC13
CPFSEQ LOC13
MOVFF LOC6,LOC8
Sunday, January 1, 2023
MOVFF LOC3,LOC13
CPFSLT LOC13
MOVFF LOC13,LOC9
MOVFF LOC4,LOC13
RRNCF LOC13,F
MOVFF LOC13,LOC10
MOVFF LOC4,LOC13
RLNCF LOC13,F
MOVFF LOC13,LOC11
MOVFF LOC5,LOC13
SWAPF LOC13,F
MOVFF LOC13,LOC12
END

SCREENSHOTS:
Sunday, January 1, 2023

Question no 2: Produce/write a C18 program to convert packed BCD to 0x35 to ASCII and display
results using PORTB and PORTC. Also, write a C18 program to convert ASCII digits of ‘5’ and ‘6’ then
display on PORTC.

SOLUTION:
CODE:
#include<P18F452.h>

void main (void)


{
unsigned char x,y,z;
unsigned char mmm=0x35
TRISB=0;
TRISC=0;
x=mmm;0x0F
PORTB= X/0X30;
y=mmm&0x50
y=y>>4;
PORTC=y|0x30;

}
Sunday, January 1, 2023

Question no 3: Produce/write a C18 program to send out the 55H serially one bit at a time via RC0.
The LSB should go out first. Also, write a C18 program to bring in a byte of data serially one bit a time
via RC1 pin. The MSB should come in first.

SOLUTION:
CODE:
#include<P18F452.h>

void main (void)


{
unsigned char x;
unsigned char mmm=0;
TRISCbbits.TRISC=1;
For(x=0;x<8:x++)
(
x=mmm;0x0F
PORTB= X/0X30;
y=mmm&0x50
y=y>>4;

}
PORTC.PC1=reg;
}
Sunday, January 1, 2023

You might also like