PW1 Labsheet Embd System Faiz

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

ELECTRICAL ENGINEERING DEPARTMENT

ACADEMIC SESSION: _2_2022/2023_


DEC40053 – EMBEDDED SYSTEM APPLICATIONS
INTRODUCTION TO MPLABX AND
PRACTICAL WORK 1 :
CIRCUIT SIMULATION
PRACTICAL WORK DATE :
LECTURER’S NAME: NORSALINA BINTI HASSAN
GROUP NO. :
TOTAL
STUDENT ID & NAME : MARKS
(100%)

(1) MUHAMMAD FAIZ DINI BIN MOHD KHAIRUL NIZAM (10DEE21F1022)

(2)

(3)

(4)

(5)

DATE SUBMIT : DATE RETURN :


1 LEARNING OUTCOMES (LO)

1. Construct and simulate real-time embedded system application based on PIC16F/PIC18F


microcontroller effectively

2 OBJECTIVE

1. Write program in C language in MPLABX.


2. Draw and simulate PIC circuit in Proteus.
3. Build output hardware circuit using LEDs

3 THEORY

A) MPLAB

MPLAB X 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. MPLAB X
IDE works seamlessly with the MPLAB development ecosystem of software and tools, many of which
are completely free.

B) PROTEUS

Proteus is a design software developed by Labcenter Electronics for electronic circuit simulation,
schematic capture and PCB design. Its simplicity and user friendly design made it popular among
electronics hobbyists. Proteus is commonly used for digital simulations such as microcontrollers and
microprocessors. It can simulate LED, LDR, USB Communication and many more.

4 EQUIPMENT / TOOLS

1. Personal Computer (PC)


2. MPLAB IDE software
3. Proteus software
5.0 PROCEDURE
At desktop, create a folder named P1. In the P1 folder, create subfolder as below.

5.1 Open MPLAB X. Click File>New Project or New Project icon.


5.2 Step 1>Choose Project. Select Microchip Embedded option in Categories and Standalone Project in
Projects. Click Next.
5.3 Step 2>Select device. Select All Families in Family option. In device option, select suitable PIC18F
microcontroller (PIC18F45K22). Click Next.

5.4 In Select tools option, select the required programmer. If none, select Simulator. Click Next.
5.5 In Select Compiler option, select the suitable compiler (XC8 v2.00). Click Next.
5.6 In Select Project Name and Folder option. In Project Location, click Browse. Select P1 folder you
created before. In Project Name, type PW1. Ignore any other options. Click Finish.

5.7 A folder named PW1.X will appeared in folder P1. This folder will store all files and source code you
created in MPLAB X.
5.8 MPLAB X window will appear as below.
5.9 You can check your MPLAB X setting here.
Dashboard-PW1 (your project name)
Device-PIC18F45K22 (your chosen PIC)
Compiler Toolchain-XC8 (your chosen compiler)

5.10 To create a C programming file, Right click Source File>New>main.c


5.11 At file name, type LED. In extension, option c is default selection. Ignore other option.

5.12 A file named LED.c will appear below Source Files.

5.13 A window named LED.c will appear as below. This is where you will write your source code.
5.14 Check setting for your compiler. Click Project Properties at dashboard or click File>Project
Properties>XC8 Global option. At C Standard, select C90.
5.15 Copy and paste program given in Appendix A into your coding window. Modify the void main (void)
block with the source code below.

5.16 To compile your source code, click Production>Build Main Project or its icon.
5.17 If your program has no error, you will get BUILD SUCCESSFUL statement in output window as
below. If your program has error, you will get BUILD FAILED statement. Double click the error
message and fix your program.

5.18 Double click Proteus 8 Professional icon. Then click ISIS icon as Figure 18.
5.19 Untitled Proteus 8 Professional-Schematic Capture work area will appear as below. Select button P or
Pick parts from libraries icon.
5.20 Pick Device window will appear. This is where you can select your components for simulation. You
can type the components name in Keywords box or you can select in Category option.

5.21 Double click your left mouse to select components below:


• Microprocessor ICs > PIC18F Family > PIC18F45K22
• Resistors > 0.6W Metal film > MINRES330R
• Optoelectronics > LEDs > LED-RED

When all components are selected, click Cancel button to go back to ISIS window.
5.22 Construct circuit shown in Figure 23. To set power and ground source, select Terminal Mode > Power
and Ground. Click Instruments icon and select DC Voltmeter.

To save your circuit, select File > Save Project As. Go to Desktop > P1 Folder > CIRCUIT sub folder.
Save this circuit as LAB1.
5.23 Double click your PIC18F45K22. Edit component window will appear as below. At Processor Clock
Frequency, set 64MHZ.

Load the hex file into Proteus. In MPLAB X, at the output window, copy the statement below and
paste in program file in Proteus.
5.24 To run your circuit, click Debug > Run Simulation or click the Run Simulation button at the bottom
left of your ISIS window. To stop simulation, click Stop The Simulation button.
5.25 Write new programming to do task below. Right click Source File>New>main.c. In File Name option,
type LED2.

Remove LED.c code from Source Files. Right click LED.c name below Source Files>Remove From
Project.

Make sure only LED2.c code remain below Source Files.


5.26 Write the source code below for LED2.c program.

Build your LED2.c code.

5.27 Draw circuit for LED2.c program and simulate them in Proteus.
6 TASK
Build C program to perform task below. Design its circuit in Proteus. State your observations.

a) Make Port D produce 5V. Use bit addressable instructions.

b) Make pin RB7, RB5, RB3 and RB1 ON and other Port B pins OFF. Use byte addressable
instruction.

c) Make RE0, RA1, RB2, RC3 and RD4 HIGH.

7 RESULT
TASK A
TASK B
TASK C

8 DISCUSSION

In this lab, we may programme and create the circuit to carry out the process or carry out the
progression of an operation using the PROTEUS software and the microcontroller (PIC18F45K22).
9 CONCLUSION

We must programme the coding and apply it to the microcontroller based on this practical work.
Additionally, this software integrates interactive component models, a microprocessor model, and
mixed mode circuit simulation to enable the simulation of full micro-controller-based systems.
Appendix A

#include <xc.h>
#define _XTAL_FREQ 64000000L

void setup(void); void


delay(unsigned int x);

void main (void)


{ setup();
//Your program start here

}
//Your program end here

/*
BAHAGIAN INI JANGAN KACAU :)
*/
void setup(void)
{

ANSELA = 0b00000000;
ANSELB = 0b00000000;
ANSELC = 0b00000000;
ANSELD = 0b00000000;
ANSELE = 0b00000000;
VREFCON0 = 0b10110000; // Fixed Voltage Reference is enabled, x4 (4.096V)
ADCON1 = 0b00110000; //0b00110000=4.096V 0b00100000=2.048V 0b00000000=Vdd
ADCON2 = 0b10000011;

LATA = 0x00;
LATB = 0x00;
LATC = 0x00;
LATD = 0x00;
LATE = 0x00;
}

void delay(unsigned int x) {


for(;x>0;x--)__delay_ms(1);
}

static void interrupt ISR(void)


{
}

You might also like