You are on page 1of 6

PRACTICAL WORK 3 :

A. PIC Programming in C & Simulating the program.


B. Hardware Application Using PIC18F4550 Target Board

OBJECTIVES:

At the end of the practical session, student should be able to:

1. Use MPLAB and to write program in c language for PIC Microcontroller.


2. Use Proteus to simulate C language for PIC Microcontroller.
3. Using hardware Application PIC18F4550

EQUIPMENT REQUIRED:

1. Personal computer (PC)


2. MPLAB software & XC8 Compiler
3. PIC Development Board (PIC-STK-V2)
4. Basic I/O Experiment Board (PIC-MOD-01)

A. PIC PROGRAMMING IN C & SIMULATING THE PROGRAM PROTEUS SOFTWARE.

PROCEDURE

1. Create a New Project File with the following setting


Device: PIC18F4550
Active Toolsuite: XC8
Project Name: DEC5052LAB3
Project Directory <your own choice>

2. Open a new file and write the Program 3a below. Save the program as“ Program3a.c”. The test program is to
toggle bit 0 of port D (RD0) continuously.

#include<xc.h>
#include “pic18f4550.h”
void msdelay( unsigned int);
void main (void)
{
TRISD = 0x00; // Port direction instruction (make Port D an output)
while (1) // instruction for infinity looping
{
PORTD = 0x01;
msdelay(100);
PORTD=0x00;
msdelay(200);
}
}

1
void msdelay( unsigned int itime)
{
unsigned int i;
unsigned char j;

for(i=0;i<itime;i++)
for (j=0;j<100;j++);
}

3. Simulate your program using the ISIS Proteus Schematic Circuit diagram ( Figure 3-A) .

Observe the LED display.

2
Hardware Application
Please refer to PIC Advance Training System User Manual (page 25 to 35) for hardware setup.

Activity 1

Write and assemble a program to make LED’s work as a running light (knight rider pattern) Save the source file as
“ program3b.c. Apply the program in Activity 1 using PIC Development Board (PIC-STK-V2) and Basic I/O
Experiment Board (PIC-MOD-01)

Observation and Discussion

3
Activity 2 - Write and run the program given below. The program is to test Port D (RD0, RD1 as input and
RB0,RB1 as Output) using SW1, SW2 and LED1,LED2 display.

#include<xc.h>
#include “pic18f4550.h”
#define SW1 PORTDbits.RD0
#define SW2 PORTDbits.RD1
#define LED1 PORTBbits.RB0
#define LED2 PORTBbits.RB1
void main(void)
{
TRISDbits.TRISD0 = 1;
TRISDbits.TRISD1 = 1;
TRISBbits.TRISB0 = 0;
TRISBbits.TRISB1 = 0;

while(1)
{
if(SW1==0)
LED1=1;
if(SW2==0)
LED2=1;
}
}

4. Save the source file as “ program3c.c ”. Simulate your program using the ISIS Proteus Schematic Circuit
diagram (Figure 3-B). Apply the program to PIC Development Board (PIC-STK-V2) and Basic I/O
Experiment Board (PIC-MOD-01)

Observation and Discussion

4
FIGURE 3-B

Discussion

5
Conclusion

You might also like