You are on page 1of 3

EXPERIMENT 2: LED INTERFACING WITH PIC16F877A MICROCONTROLLER

AIM:
To interface 8 LED's with any 8 bit port of the PIC16F877A microcontroller and to write a CCS
C compliant program to periodically turn on and off the LED's.

EQUIPMENTS REQUIRED:
1. PIC16F877A DEVELOPMENT BOARD
2. SERIAL CABLE (RS232)
3. 5 V ADAPTER
4. CONNECTING WIRES

SOFTWARE USED:
1. CCS C COMPILER
2. PIC ISP DOWNLOADER
3. WINXTALK

PROCEDURE:
1. Compile the above program using PIC C Compiler to generate the hex file.
2. Download the hex file to the target using PIC ISP.
3. Execute the program.
4. LED's are toggled.
CODE:
#include<16f877a.h>
#use delay(clock = 20000000)
#use rs232(baud = 9600, xmit = PIN_C6, rcv = PIN_C7)
char led[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}, i, j;
void main()
{
set_tris_d(0x00);
output_d(0x00);
while(1)
{
for(i=0;i<5;i++)
{
output_d(0xff);
delay_ms(500);
output_d(0x00);
delay_ms(500);
}
delay_ms(500);
for(j=0;j<8;j++)
{
output_d(led[j]);
delay_ms(500);
}
delay_ms(500);
}
}
RESULT:
The LED's connected to the port D of the PIC microcontroller were toggled.

You might also like