In this tutorial we will learn how to ON OFF LED with Switch on PIC18F4520 Starter Board.
The Explore Starter PIC board has two on board LED's which are connected to PORTD.0 & PORTD.1 and two on board Switches which are connected to PORTD.2 & PORTD.3.

Steps

  1. Configure the PORT D0 as output .
  2. Configure the PORT D2 as input.
  3. Read the switch status.
  4. ON/OFF the led as per switch status.

Code

Demo

PIC16f877A LED Switch.gif