/********************************************************************
* FileName:        LEDs following buttons example.c
* Compiler:        MPLAB C18 v.3.06 
*
* This program monitors Button RB0 (ie Port B bit 0)
*   when it is pressed LED RC1 comes on.
*
* Your mission:
*   #1 - Make RB0 turn on a random LED from RC3 to RC0
*   #2 - Make RB1 turn on RC0 on the first press, then RC1 on
*        next press, RC2 on the next, RC3 next, then RC0, . . .
*
* Author               Date        Comment
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// David Fisher         9/9/07


/** Processor Header Files *****************************************/
#include <p18f4520.h> 

/** Define Constants Here ******************************************/


/** Local Function Prototypes **************************************/


// ============================================================
// Configuration Bits 
// ============================================================
#pragma config OSC = INTIO67
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config BOREN = OFF
#pragma config XINST = OFF


/** Declarations *************************************************/


/*****************************************************************
* Function:        void main(void)
*
******************************************************************/
#pragma code

void main(void) {
    ADCON1 = 0x0F;          // Make sure the pins are digital
    TRISBbits.TRISB0 = 1;   // Makes RB0 an input
    TRISC = 0b11111100;     // Makes Port C bits 0 & 1 output
    PORTC = 0x00;           // Start with all of the lights off

    while (1) {
        if (PORTBbits.RB0 == 0)
            PORTCbits.RC1 = 1;
        else
            PORTCbits.RC1 = 0;
    }
}