The code below provides the same functionality using bit positions.
#include <xc.h>
void main(void)
{
/* setting pin RE0 as output (LED) */
TRISE &= ~(1 << _TRISE_TRISE0_POSITION);
/* setting pin RE2 as input (button) */
TRISE |= (1 << _TRISE_TRISE2_POSITION);
/* enable digital input buffer for pin RE2 (button) */
ANSELE &= ~(1 << _ANSELE_ANSELE2_POSITION);
/* enable internal pull-up for pin RE2 (button) */
WPUE |= (1 << _WPUE_WPUE2_POSITION);
/* main program loop */
while(1)
{
/* if button is pressed (pin RE2 high) */
if(PORTE & (1 << _PORTE_RE2_POSITION))
{
/* turn on the LED (pin RE0 high) */
LATE |= (1 << _LATE_LATE0_POSITION);
}
else
{
/* turn off the LED (pin RE0 low) */
LATE &= ~(1 << _LATE_LATE0_POSITION);
}
}
}