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

Esb File Vinit

Uploaded by

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

Esb File Vinit

Uploaded by

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

PRACTICAL FILE

EMBEDDED SYSTEM DESIGN LAB


(PCC-ECE303-P)
ELECTRONICS AND COMMUNICATION ENGINEERING
GURU JAMBESHWAR UNIVERSITY OF
SCIENCE AND TECHNOLOGY, HISAR

Submitted to: Submitted By:


Dr. Abhimanyu Nain Sulekh
220151520029
B.Tech ECE 5th Sem.

DEPARTMENT OF ELECRICAL AND ELECTRONICS


ENGINEERING
GURU JHAMBESHWAR UNIVERSITY OF SCIENCE AND
TECHNOLOGY HISAR (125001)
DECLARATION

I Vinit, student of B. Tech. (ECE) 3rd Year 5th Semester hereby declares this
Practical File of “EMBEDDED SYSTEM DESIGN” is submitted by me at
“GURU JAMBHESHWAR UNIVERSITY OF SCIENCE AND
TECHNOLOGY”. Under the guidance of Dr. Abhimanyu Nain for the completion
of “EMBEDDED SYSTEM DESIGN LAB”.
INDEX

S.No Page Teacher’s


Experiment Name
. No. Remarks
1. To familiarize with MPLAB Software. 1-6
To write an assembly language program to turn on
2. 7-9
the led at PORTB.
To write an assembly language program to perform
3. 10-12
addition of two numbers.
To write an assembly language program to perform
4. 12-16
subtraction of two numbers.
To write an assembly language program to perform
5. 17-19
multiplication of two numbers.
Experiment 1

AIM: To familiarize with MPLAB Software.


Requirements: PC or Laptop with MPLAB software.
Theory:
MPLAB - Integrated Development Environment (IDE) is an expandable, highly
configurable software program that incorporates powerful tools to help you
discover, configure, develop, debug and qualify embedded designs for most of
Microchip’s microcontrollers and digital signal controllers.
It is called IDE because it provides a single integrated environment to develop
code for embedded microcontrollers. It runs as a 32bit application on MS
Windows. It is easy to use and includes a lot of free software component for fast
application development.
 Components of MPLAB IDE:
 Project Manager
 Debugger
 Editor
 Built in window
 Assembly tool etc.

Procedure:
1. Open MPLAB Software.

4|Page
2. Now open Project Wizard from Project tag and click next.

3. Select device as per choice (but here are working on PIC16F877A) in


project wizard.

5|Page
4. Now select the language toolsuite and click next. (in our case MPASM
ASSEMBLER)

5. Now give the path where we want the project to be saved and giver the file
name.

6|Page
6. Now add linker file and template file for our microcontroller in the next step
and then finish the setup.

7|Page
7. In our software main window, we can edit and can be execute our
instructions in Main Program Code Segment.

8. After writer the code ,Click on Debugger>Select Tool>MPLAB SIM.

9. Now to view the data in an any location file register. i.e. WREG. click View
> Watch > Select the Register > ADD SFR

8|Page
Result: We have successfully familiarized with MPLAB Software.

9|Page
Experiment 2

AIM: To write an assembly language program to turn on the led at PORTB.


Requirements: PC or Laptop with MPLAB software.
Program Code:
STATUS EQU 0x03 ; status register
PORTB EQU 0x06 ; PORTB register

ORG 0x000 ; processor reset vector


nop ; nop required for icd
goto main ; go to beginning of program

main
SETUP
bsf STATUS, 0x05 ; Select Bank 1
bcf TRISB, 0x00 ; Set RB0 as output
bcf STATUS, 0x05 ; Switch back to Bank 0

LOOP
bsf PORTB, 0x00 ; Set RB0 high (turn on LED)

goto LOOP ; Infinite loop

end ; directive 'end of program'

10 | P a g e
Logic and Working:
The functionality of the code revolves around toggling an LED connected to the
RB0 pin of the PIC microcontroller's PORTB. The program starts with a reset
vector at address 0x000, where a "nop" instruction is used to maintain
compatibility with in-circuit debugging. The program then jumps to the main label
to begin execution.

The setup phase first selects Bank 1 by setting the appropriate bit in the STATUS
register, allowing access to the TRISB register for configuring PORTB. The bit
corresponding to RB0 is cleared in TRISB, configuring it as an output pin. The
code then switches back to Bank 0 for regular operations.

In the loop section, the bit associated with RB0 is set high, turning on the LED.
This action is repeated continuously by looping back to the "LOOP" label, creating
an infinite cycle that keeps the LED on. This basic program demonstrates simple
I/O control using bit manipulation.

Procedure:
1. Start the MPLAB Software
2. Open the source file of the last experiment
3. Click Edit on it and write the above program in the Main Program, in the
Code.
4. Click on Debugger > Select tool > MPLAB SIM
5. Click View > Watch > Add WREG, 0x06.
6. Execute and run the program one by one instruction and check the results

11 | P a g e
Output:

Result: We have successfully written an assembly language program to turn on the


led at PORTB.

12 | P a g e
Experiment 3
AIM: To write an assembly language program to perform addition of two
numbers.
Requirements: PC or Laptop with MPLAB software.
Theory:
Hexadecimal Addition of two numbers.
Hexa-Decimal Binary
15h 0001 0101
+17h +0001 0111
2Ch 0010 1100

Program Code:

sum EQU 0x30 ; Define memory location 0x50 as 'sum'

ORG 0x000 ; Set program start at address 0x000 (reset vector)


nop ; No operation (required for in-circuit debugger)
goto main ; Jump to the main program

main
clrw ; Clear the W register (set to 0)
movlw 15h ; Load W register with 15 (0x0F)
movwf 25h ; Move the value from W (15) to register at address 0x25
movlw 17h ; Load W register with 17 (0x11)
addwf 25h ; Add W (17) to the value in register 0x25 (which is 15)
movf 25h, w ; Move the result from 0x25 to the W register
movwf sum ; Move the result (32) into the defined 'sum' location (0x50)
13 | P a g e
here: goto here
END ; End of the program

Logic and Working:

This assembly code performs a basic addition operation using the PIC16F877A
microcontroller. Pointer jumps to the main label to begin the execution of the
primary routine. Initially, the clrw instruction is used to clear the working register
(W), setting it to zero to ensure that no residual data affects subsequent operations.
The program then loads the literal value 0x15 (decimal 21) into the W register
using the movlw 15h instruction and moves this value into the file register at
address 0x25 with the movwf 25h instruction.

Following this, the code loads a new value, 0x17 (decimal 23), into the W register
using movlw 17h. It then performs an addition of this new value with the contents
of the file register at 0x25, which previously held 0x15. The addwf 25h instruction
adds these values together, resulting in 0x2C (decimal 44), and stores the result
back into the file register at 0x25. The program then transfers this result from 0x25
to the W register using the movf 25h, w instruction. Finally, it stores the result in
the memory location labeled sum, defined at address 0x30, by executing the
movwf sum instruction.

After completing the addition and storing the result, the program enters an infinite
loop using the goto here instruction, effectively halting any further progression in
the code execution. This routine demonstrates how basic arithmetic operations can
be carried out using assembly language instructions in the PIC16F877A
microcontroller.

Procedure:
1. Start the MPLAB Software
2. Open the source file of the last experiment
3. Click Edit on it and write the above program in the Main Program, in the
Code.
4. Click on Debugger > Select tool > MPLAB SIM
5. Click View > Watch > Add WREG, 0x025 & 0x030.
6. Execute and run the program one by one instruction and check the results
14 | P a g e
Output:

Result: We have successfully written an assembly language program to perform


the addition of two numbers.

15 | P a g e
Experiment 4
AIM: To write an assembly language program to perform subtraction of two
numbers.
Requirements: PC or Laptop with MPLAB software.
Theory:
Theory:
Hexadecimal Addition of two numbers.
Hexa-Decimal Binary
55h 0101 0101
-28h -0010 1000
D3h 1101 0011
Two's Complement Subtraction Process:

To subtract `28h` from `55h` using the two's complement method:

1. Convert to Binary:
 `55h` in binary: `01010101`
 `28h` in binary: `00101000`

2. Find the Two's Complement of the Subtrahend (28h):


 Invert the bits of `00101000`:
 `11010111`
 Add `1` to the inverted bits:
 `11010111`
- `+ 1`
 `----------`
 `11011000` (This is the two's complement of `28h`, which is `D8h` in
hexadecimal.)

16 | P a g e
3. Add the Minuend (55h) and the Two's Complement of the Subtrahend:
- Now, add `01010101` (55h) and `11011000` (the two's complement of 28h):

01010101
+ 11011000
------------
11101101

4. Interpret the Result


The result `11101101` is indeed `D3h` in hexadecimal, which corresponds to the
binary `11010011` after adjusting for overflow.

Program Code:
diff EQU 0x30 ; Variable to store the result of a calculation

ORG 0x000 ; Processor reset vector


nop ; No operation (required for ICD)
goto main ; Jump to the beginning of the main program

main

SETUP
clrw ; Clear the W register
movlw 55h ; Load W register with the value 55h (85 in decimal)
sublw 28h ; Subtract 28h (40 in decimal) from W register
movwf diff ; Move the result into the variable 'diff'

17 | P a g e
here: goto here ; Infinite loop (do nothing, effectively halting the program)

END ; End of the program

Logic and Working:


In the provided assembly code, the subtraction operation is performed using the
`sublw` instruction, which takes the value in the W register and subtracts it from a
literal value. Initially, the W register is loaded with the hexadecimal value `55h`
(which is 85 in decimal). The instruction `sublw 28h` subtracts `28h` (or 40 in
decimal) from `55h`. The calculation can be represented as `28h - 55h`, yielding a
result of `-45` in decimal. To represent this negative result in an 8-bit format, we
employ two's complement arithmetic.

To convert `45` to its two's complement representation, we first express it in binary


as `00101101`. Next, we invert the bits, resulting in `11010010`, and then add `1`,
giving us `11010011`. This binary value corresponds to `0xD3` in hexadecimal.
Therefore, after executing the subtraction, the final value stored in the variable
`diff` is `0xD3`, which represents the two's complement of `-45`. This process
highlights how negative numbers are represented in assembly language,
emphasizing the importance of understanding binary arithmetic when working with
low-level programming.
Procedure:
1. Start the MPLAB Software
2. Open the source file of the last experiment
3. Click Edit on it and write the above program in the Main Program, in the
Code.
4. Click on Debugger > Select tool > MPLAB SIM
5. Click View > Watch > Add WREG,0x030.
6. Execute and run the program one by one instruction and check the results

Output:
18 | P a g e
Result: We have successfully written an assembly language program to perform
the addition of two numbers.

19 | P a g e
Experiment 5
AIM: To write an assembly language program to perform subtraction of two
numbers.
Requirements: PC or Laptop with MPLAB software.
Theory:
Hexadecimal Addition of two numbers.
Hexa-Decimal Decimal
5h 5
x 10h x 16
50h 80 (1010000)

Hexadecimal Multiplication Steps

1. Convert to Decimal (Optional):


o Although multiplication can be done directly in hexadecimal,
converting to decimal may help in understanding the multiplication
process.
o In decimal, 5h is 5 and 10h is 16.

2. Multiply:
o Perform the multiplication of the two hexadecimal numbers as if they
were decimal numbers.
o If the multiplication involves multiple digits, use the same
multiplication method as in decimal, adding intermediate results as
necessary.

3. Convert the Result Back to Hexadecimal (if necessary):


o If you initially converted to decimal, convert the result back to
hexadecimal.

Program Code:
N EQU 60h ; Variable for loop counter
RL EQU 61h ; Lower byte of a 16-bit register pair
RH EQU 62h ; Higher byte of a 16-bit register pair

20 | P a g e
ORG 0x000 ; Processor reset vector
nop ; No operation (required for ICD)
goto main ; Jump to the beginning of the main program

main
; Initialization and main code
MOVLW 5 ; Load the literal value 5 into W register
MOVWF N ; Store the value 5 in variable N (loop counter)
MOVLW 10 ; Load the literal value 10 into W register
CLRF RL ; Clear RL (set to 0)
CLRF RH ; Clear RH (set to 0)

SETUP
ADDWF RL ; Add W register to RL and store the result in RL
BTFSC STATUS, C ; Check if the carry flag is set
INCF RH ; Increment RH if the carry flag is set
DECFSZ N ; Decrement N and skip next instruction if zero
GOTO SETUP ; Loop back to SETUP if N is not zero

END ; End of the program

Logic and Working:


This assembly code for the PIC16F877A microcontroller demonstrates a simple
multiplication operation using repeated addition, specifically multiplying the
values `5` and `10`. The program begins by configuring the microcontroller and
21 | P a g e
defining several variables for context saving, including the W register, STATUS
register, and PCLATH register. In the `main` section, the program initializes a loop
counter `N` to `5` (the multiplicand) and the two operands `RL` and `RH` to `0`.
The multiplication is executed in the `SETUP` loop, where the W register, loaded
with the value `10`, is added to the lower byte `RL` of a 16-bit register pair. If a
carry occurs during this addition, indicated by the carry flag in the STATUS
register, the higher byte `RH` is incremented to account for the overflow. The loop
continues until `N` decrements to zero, completing the multiplication. Once
finished, the program enters an infinite loop to halt further execution. This code
effectively simulates multiplication by accumulating the sum of `10` added to itself
`5` times, resulting in `50`, represented in the lower byte `RL`. The use of the carry
flag ensures that the multiplication is handled correctly, allowing the storage of
results exceeding a single byte in a 16-bit register pair.

Procedure:
1. Start the MPLAB Software
2. Open the source file of the last experiment
3. Click Edit on it and write the above program in the Main Program, in the
Code.
4. Click on Debugger > Select tool > MPLAB SIM
5. Click View > Watch > Add WREG,0x060,0x061,0x062.
6. Execute and run the program one by one instruction and check the results
Output;

22 | P a g e
Result: We have successfully written an assembly language program to perform
the addition of two numbers.

23 | P a g e

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy