Embedded Pw1 Izwan.
Embedded Pw1 Izwan.
(1)
(2))
(3)
(4)
2 OBJECTIVE
3 THEORY
A) MPLAB
B) PROTEUS
ISIS provides the means to enter the design in the first place, the
architecture for real time interactive level simulator. This software
combines mixed mode circuit simulation, micro-processor models and
interactive component models to allow the simulation of complete
micro-controller based designs.
5.1
Open MPLAB X. Click File>New Project or New Project icon.
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. Click C18(V3.36).
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.
Tick all box
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.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
Write the source code below.
// Using bit addressable
#include<p18f4520.h>
void main (void)
{ TRISBbits.TRISB0=0;
//Set PortB as output
while(1)
//Loop forever
{ LATBbits.LATB0=0;
//RB0 get 5V } }
5.15 To compile your sorce code, click Production>Build Main Project or its icon.
5.16 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.17 Double click Proteus 8 Professional icon. Then click new project icon as Figure . Rename New Project
to PW1
5.18 Untitled Proteus 8 Professional Schematic Capture work area will appear as below. Select button P
or Pick parts from libraries icon.
5.19 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.20 Select icon P to select components below:
Microprocessor ICs > PIC18F Family > PIC18F4520 Resistors > 0.6W Metal film >
MINRES330R Optoelectronics > LEDs > LED-RED
5.21 Cons truct circuit shown below. To set power and ground source, select Terminal Mode > Power and
Ground. Click Instruments icon and select DC Voltmeter.
5.22 Double click your PIC18F4520. Edit component window will appear as below. At processor Clock
Frequency, set 64MHZ
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 as Figure 25.
5.23 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 Source Files>Remove From Project.
6.0 TASK
Build C program to perform task below. Design its circuit in Proteus. State your
observations.
b) Make pin RB4 to RB7 HIGH and RB0 to RB3 LOW. Use bit
addressable instruction.
c) Make RE0, RA1, RB2, RC3 and RD4 HIGH. Use bit addressable instruction.
DEC 40053 –EMBEDDED SYSTEM
APPLICATIONS PRACTICAL WORK 1 / 2 /
3/4/5/6
NO Group No. REG. NO. NAME OF STUDENT Programme
S1
S2
S3
S4
#include<p18f4520.h>
void main (void)
{
TRISBbits.TRISB0=0; // RB0 as
O/P
while(1) //Loop forever
{
LATBbits.LATB0=0; //RB0 get
0V
}
}
6.0
a) Make all Port D produce 5V.
// Use byte addressable
#include <p18f4520.h>
void main (void)
{
TRISD = 0; //Set PortB as output
while (1) //Loop forever
{
LATD = 0xFF; //PortB High
}
}
#include <p18f4520.h>
void main (void)
{
TRISBbits.TRISB5=0;
TRISBbits.TRISB6=0;
TRISBbits.TRISB7=0;
TRISBbits.TRISB4=0;
//Set PortB as output
while(1)
//Loop forever
{ LATBbits.LATB7=
1;
LATBbits.LATB4=1;
LATBbits.LATB5=1;
LATBbits.LATB6=1;
//RB0 get 5v
}
}
c) Make RE0, RA1, RB2, RC3
and RD4 HIGH. Use bit
addressableinstruction.
#include<p18f4520.h>
void main (void)
{
TRISEbits.TRISE0 = 0;
TRISAbits.TRISA1 = 0;
TRISBbits.TRISB2 = 0;
TRISCbits.TRISC3 = 0;
TRISDbits.TRISD4 = 0;
while(1)
{
LATEbits.LATE0 = 1;
LATAbits.LATA1 = 1;
LATBbits.LATB2 = 1;
LATCbits.LATC3 = 1;
LATDbits.LATD4 = 1;
}
}
Discussion
Discussion in this practical work MPLAB is downloaded and use to write the 4 program in C language for task 5.15,a,b and c.
Each program perform different function. For task 5.15 the program is written to make 1 led light up using bit addressable at
Port B, RB as output, LATBbits. LATBO=1 command to make the LED connected to RBO light up, while (1) is use to make it loop
forever, TRISBbits.TRISB0=0 is use to connect to the output that is the LED. Next, PROTEUS is downloaded and use to draw and
simulate the 4 circuit for all the task to get the result. PIC18F4520 is use in the circuit. After finished drawing the circuit the
program written at MPLAB is inserted at the PIC to get the intended output according to the task. Lastly simulate the circuit to
get the result.
Conclusio
n
In the end we’re able to do coding and construct the diagram by using MPLABX and proteus software. We also able to draw and
simulate PIC circuit in Proteus and build output hardware circuit using LEDS. Finally, we also learn on how to write program
language in MPLABX