Professional Documents
Culture Documents
Practical Work 3: A. PIC Programming in C & Simulating The Program. B. Hardware Application Using PIC18F4550 Target Board Objectives
Practical Work 3: A. PIC Programming in C & Simulating The Program. B. Hardware Application Using PIC18F4550 Target Board Objectives
OBJECTIVES:
EQUIPMENT REQUIRED:
PROCEDURE
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) .
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)
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)
4
FIGURE 3-B
Discussion
5
Conclusion