/** \file main.c
 * \brief Program Template
 * 
 * $Id: avr_auto.c 40 2006-10-28 17:27:51Z robocon2006 $
 */
/**
 * Hong Kong Univerisity Of Science and Technology, Copyright (c) 2005-2007
 * Code for Robocon Electronics Quickstart Course
 */

// These are two very basic definition
// F_CPU specify the CPU Frequency, which is used in <util/delay.h>
#define F_CPU 14745600
// This one will give you access to the SFR
#include <avr/io.h>
#include <util/delay.h>

int main( void )
{
    // Output
    //    High
    //    Low
    // Input
    //    Pull Up
    //    Floating

    // PROG: C3
    // Mode: Pull up high
    DDRC &= ~_BV(3);
    PORTC |= _BV(3);

    // LED : E3 
    // Turn on
    // Mode: Output Low
    // Turn off
    // Mode: Output High
    DDRE |= _BV(3); // Make E3 into output mode 

    while (1) {
        if (PINC & _BV(3)) {
        /*
            PINC: xxxx*xxx
        & _BV(3): 00001000
        ------------------
                  0000*000
          if * == 1: 0x08 => Non-zero => True
          if * == 0: 0x00 =>     Zero => False
        */
            // Not Pressed
            // Voltage expected: 5V
            // LED Off -> LED Pin Output High
            PORTE |= _BV(3);
        } else {
            // Pressed
            // Voltage expected: 0V
            // LED On -> LED Pin Output low
            PORTE &= ~_BV(3);
        }
    }
}