You are on page 1of 17

INTRODUCTION TO MICROCHIP STUDIO

 How to create, run and get an output in Microchip Studio

Step 1: Launch Microchip Studio

Open Microchip Studio from your desktop or Start menu.

Step 2: Create a New Project

1. Click on "File" in the top menu bar.


2. Select "New" and then "Project..."
Step 3: Choose Project Template

1. In the "New Project" dialog, you'll see a list of project templates. Choose the appropriate template for
your project. You can select either C/C++ or Assembler.
2. Rename the file and select location as per your preference.
3. Click “OK”.

Step 4: Select Device

1. In the "Device selection" dialog, choose ATmega32 from the list.


2. Click "OK."
Step 5: Write Your Code

1. Double-click on the main source file (e.g., main.c or main.cpp or main.asm) under your project.
2. Write your code in the editor.
3. Add breakpoint wherever you want to see the output.

Step 6: Select Simulator from Selected Debugger

1. Click on None on and choose Simulator from Selected debugger/programmer


Step 7: Build the Project

1. Click on "Build" in the top menu bar or press "F7" to build your project. This compiles your code
and checks for errors.
2. Check the Output window for build messages. Make sure there are no compilation errors.

Step 8: Debug Your Project

1. To debug your project, click on "Debug" in the top menu bar and select "Start Debugging and
Break." This will launch the debugger and allow you to step through your code.
Step 9: Check the Output

1. Open the I/O panel.


2. Select the PORT where the output will be displayed as per your code.
3. Verify the output.
EXPERIMENT 1
Aim: Addition of two decimal numbers.

Software Used: Microchip Studio for AVR and SAM devices

Theory: To perform the addition of two decimal numbers in Microchip Studio software using assembly
language, you will typically need to work with a microcontroller that supports assembly programming, such
as those in the AVR family. Assembly language programming allows us to write low-level code that can be
executed by a microcontroller or microprocessor. In this experiment, we will focus on adding two numbers
using assembly language in Microchip Studio.
To add two decimal numbers in Microchip Studio software using assembly language, you should first define
variables to store the numbers and load them into registers. Then, use assembly instructions like ADD to
perform the addition. The exact syntax and instructions may vary based on your microcontroller and
assembly language variant.

Code:

Output:
EXPERIMENT 2
Aim: Subtraction of two decimal numbers.

Software Used: Microchip Studio for AVR and SAM devices

Theory: To perform the subtraction of two decimal numbers in Microchip Studio software using assembly
language, you will typically need to work with a microcontroller that supports assembly programming, such
as those in the AVR family. Assembly language programming allows us to write low-level code that can be
executed by a microcontroller or microprocessor. In this experiment, we will focus on subtracting two
numbers using assembly language in Microchip Studio.
To subtract two decimal numbers in Microchip Studio software using assembly language, you should first
define variables to store the numbers and load them into registers. Then, use assembly instructions like
SUB to perform the addition. The exact syntax and instructions may vary based on your microcontroller and
assembly language variant.

Code:

Output:
EXPERIMENT 3
Aim: Multiplication of two decimal numbers.

Software Used: Microchip Studio for AVR and SAM devices

Theory: Assembly language programming enables us to write low-level code that can be executed by
microcontrollers or processors. In this experiment, the focus will be on multiplying two numbers using
assembly language in Microchip Studio. To perform multiplication of two decimal numbers in Microchip
Studio software using assembly language, first load the two decimal numbers into registers, ensuring that
they are in a suitable format for multiplication. Then, use the multiplication instruction specific to the
microcontroller you are using, typically something like "MUL" or "MULT".

Code:

Output:
EXPERIMENT 4
Aim: Addition of two hexadecimal numbers.

Software Used: Microchip Studio for AVR and SAM devices

Theory: To perform the addition of two decimal numbers in Microchip Studio software using assembly
language, you will typically need to work with a microcontroller that supports assembly programming, such
as those in the AVR family. Assembly language programming allows us to write low-level code that can be
executed by a microcontroller or microprocessor. In this experiment, we will focus on adding two
hexadecimal numbers using assembly language in Microchip Studio.
To add two hexadecimal numbers in Microchip Studio software using assembly language, you should first
define variables to store the numbers and load them into registers. Then, use assembly instructions like
ADD to perform the addition. The exact syntax and instructions may vary based on your microcontroller
and assembly language variant.

Code:

Output:
EXPERIMENT 5
Aim: Addition of 3 decimal numbers.

Software Used: Microchip Studio for AVR and SAM devices

Theory: To perform the addition of three decimal numbers in Microchip Studio software using assembly
language, you will typically need to work with a microcontroller that supports assembly programming, such
as those in the AVR family. Assembly language programming allows us to write low-level code that can be
executed by a microcontroller or microprocessor. In this experiment, we will focus on adding three decimal
numbers using assembly language in Microchip Studio.
To add three decimal numbers in Microchip Studio software using assembly language, you should first
define variables to store the numbers and load them into registers. Then, use assembly instructions like
ADD to perform the addition. The exact syntax and instructions may vary based on your microcontroller
and assembly language variant.

Code:

Output:
EXPERIMENT 6
Aim: Addition of 4 numbers including binary and hexadecimal numbers.

Software Used: Microchip Studio for AVR and SAM devices

Theory: In Microchip Studio software, you can perform the addition of four numbers, including binary and
hexadecimal numbers, using assembly language. First, define variables to store the values of these
numbers in the appropriate number system format through LDI instruction, such as binary and
hexadecimal. Then, use assembly language instructions like ADD to add these variables together, taking
into account the specific format of each number. Ensure you correctly handle carry bits for binary addition.
Finally, store the result in a suitable variable through STS instruction and display it as needed. Make use of
appropriate instructions for binary and hexadecimal manipulation, and remember to consider data types
and memory allocation in your assembly code to successfully perform the addition operation.

Code:

Output:
EXPERIMENT 7
Aim: Toggling Of LED

Software Used: Microchip Studio for AVR and SAM devices

Theory: To toggle an LED in Microchip Studio software using the C++ language, you can follow these simple
steps. First, set up your Microchip Studio project and ensure that you have the necessary hardware
connections to control the LED. Then, within your C++ code, you'll need to configure the GPIO pin
connected to the LED as an output. This can typically be done using GPIO configuration registers provided
by your microcontroller's datasheet. Once the pin is configured as an output, you can write logic to toggle
the state of the pin. You can do this by writing a '1' to the pin to turn the LED on and a '0' to turn it off, or
by using XOR operations to toggle the current state. Finally, make sure to include necessary delay loops or
timers to control the timing of LED toggling if needed. Compile and upload your code to the
microcontroller, and you should be able to toggle the LED in Microchip Studio using C++.

Code:

Output:
EXPERIMENT 8
Aim: Toggle I/O register of PORT B continuously forever

Software Used: Microchip Studio for AVR and SAM devices

Theory: In Microchip Studio software, you can create a simple procedure to continuously toggle the I/O
register of PORT B using assembly language. First, you need to define the PORT B address and configure it
as an output port. Then, enter a loop where you set the PORT B register to all high bits, wait for a short
delay, and then set it to all low bits, again followed by a delay. This sequence will toggle the I/O register of
PORT B continuously forever, creating a blinking effect on the corresponding output pins. Make sure to
include appropriate initialization and setup code for your specific microcontroller model and clock
configuration.

Code:

Output:
EXPERIMENT 9
Aim: Addition of numbers 1 to 10 via decrementing.

Software Used: Microchip Studio for AVR and SAM devices

Theory: In Microchip Studio software, you can perform the addition of numbers from 1 to 10 using
assembly language by employing a decrementing loop. Begin by initializing a register to hold the result and
another to hold the current number, setting the result to zero initially. Then, create a loop that decrements
the current number register from 10 down to 1. Within the loop, add the value in the current number
register to the result register and repeat until the current number reaches 1. After the loop concludes, the
result register will hold the sum of numbers from 1 to 10, which you can retrieve and utilize as needed in
your assembly program.
The program begins at address 0 and includes the necessary microcontroller definitions. It loads the low
and high bytes of the data address (Mydata) into the Z register. Then, initialize two registers, R16 and R17,
with the values 10 and 0, respectively.
Inside the loop labeled "LI," load a value from the program memory (Mydata) pointed to by Z and add it to
the content of register R17 using the ADC (Add with Carry) instruction. The loop then decrements the value
in R16 and checks if it's not equal to zero using BRNE (Branch if Not Equal) to decide whether to continue
the loop. Once the loop completes, store the result in R17 into the memory address 0x0140.
The Mydata section contains the numbers 1 to 10 in hexadecimal format. Finally, the program sends the
result in R17 to PORTB for output. This program effectively adds the numbers 1 to 10 and outputs the
result to the specified port.

Code:

Output:
EXPERIMENT 10
Aim: Addition of numbers 1 to 10 via incrementing.

Software Used: Microchip Studio for AVR and SAM devices

Theory: In Microchip Studio software, you can perform the addition of numbers from 1 to 10 using
assembly language by employing a incrementing loop. Begin by initializing a register to hold the result and
another to hold the current number, setting the result to zero initially. Then, create a loop that increment
the current number register from 1 down to 10. Within the loop, add the value in the current number
register to the result register and repeat until the current number reaches 10. After the loop concludes, the
result register will hold the sum of numbers from 1 to 10, which you can retrieve and utilize as needed in
your assembly program.
This assembly language procedure in Microchip Studio software performs the addition of numbers from 1
to 10 by incrementing. It starts at address 0 and uses the .db directive to define an array called Mydata,
containing the numbers 1 to 10. It initializes registers ZL and ZH to point to the start of Mydata. Registers
R16 and R17 are used to store the loop counter and the sum, respectively. Inside the loop labeled LI, it uses
LPM (Load Program Memory) to load the next number from Mydata, adds it to the sum in R17, and
increments the loop counter in R16. The loop continues until R16 reaches 10. Finally, the result in R17 is
stored at address 0x0140 in memory and output to the PORTB register. This procedure effectively
computes the sum of numbers from 1 to 10 and stores it for further use.

Code:

Output:
EXPERIMENT 11
Aim: State the contents of RAM locations $212 to $216 with given values.

Software Used: Microchip Studio for AVR and SAM devices

Theory: In Microchip Studio software, you can use assembly language to state the contents of RAM
locations $212 to $216. In your assembly code, utilize the LDI (Load Immediate) instruction to load values
into registers and then use the STS (Store Direct to Data Space) instruction to store these values into the
specified RAM locations ($212 to $216). After assembling the code, program your microcontroller with the
generated hex file, and upon execution, the values 0x98, 0x85, 0x3F, 0x63, and 0x12 will be placed in RAM
locations $212 to $216, respectively, achieving the desired outcome.

Code:

Output:
EXPERIMENT 12
Aim: State the contents of R20, R21, and data memory location 0x120 with given values.

Software Used: Microchip Studio for AVR and SAM devices

Theory: To state the contents of registers R20 and R21, as well as data memory location 0x120 in Microchip
Studio software using assembly language, follow this procedure: Use the Load Immediate (LDI) instruction
to load values into R20 and R21. For example, set values "LDI R20, 5" and "LDI R21, 2" for R20 and R21.
Perform addition with the ADD instruction. Finally, use the Store Direct to Data Space (STS) instruction, like
"STS 0x0120, R20," to save the contents of R20, R21, or any desired value in data memory location 0x120.
This sequence of instructions will set the specified values in Microchip Studio software using assembly
language.

Code:

Output:

You might also like