#include <htc.h>
__CONFIG (FOSC_HS & CP_OFF & WDTE_OFF & PWRTE_ON );
#ifndef _XTAL_FREQ
// Unless already defined assume 4MHz system frequency
// This definition is required to calibrate __delay_us() and __delay_ms()
#define _XTAL_FREQ 4000000
#endif
void init(void)
{
// port directions: 1=input, 0=output
TRISB = 0b00000100; //set's portb to outputs all but RB2 and it's a input
RB0 = 0; //starts RB0 off
}
void main(void) //main code atfer here
{
init(); //runs startup code
while (1){ //loop
if(RB2=0){ // check switch
__delay_ms(50); //delay to let switch debounce
if(RB2=0)
RB0 = 1; //If switch is Low led is on
else
RB0 =0; // Switch High led is off
}
}
}