Aim:
To write a C program to transfer the data in the switch to the LED using I/O Ports in PIC.

Algorithm.
Step 1: Start the program
Step 2: Choose a GPIO pin from any port (RB0)
Step 3: Make RB0 value HIGH
Step 4: Make a delay
Step 5: Make RB0 value LOW
Step 6: Make a delay
Step 7: Repeat the process

Program:
#include<18F8722.h>
#use delay(clock=20000000)
#use rs232(baud=19200,xmit=PIN_C6,rcv=PIN_C7)
#fuses HS,NOWDT,NOBROWNOUT
int sw_val=0x00;
void main()
{
unsigned char value1=0,j,i;
SET_TRIS_D (0xff);
while(1)
{
sw_val = input_d();
value1=0;
for(i=0,j=7;i<8;i++,j--)
{
value1 |= (((sw_val>>i)&0x01)<<j);
}
output_f(value1);
printf("\n\r Switch1 = %x ",value1);
}
}