/** \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 

    // Variable Type:
    // +unsigned
    // +signed
    // char,    int, short, long, long long, float, double, void*
    // char   8, 
    // int 32 on PC, but 16 here
    // short 16 in PC
    // long 32 bits
    // long long 64 bits
    // 8 bits for each register

    uint8_t prev = PINC & _BV(3);
    uint8_t curr = PINC & _BV(3);
    while (1) {
        curr = PINC & _BV(3);
        // prev =
        // High: _BV(3)
        // Low:  0
        if (prev && !curr) {
            //...Change the LED
            /*
            ^ XOR ==> Exclusive-OR
            Truth Table
            A B   Output
            -----------
            0 1   1
            1 1   0
            */
            PORTE = PORTE ^ _BV(3);
        }
        prev = curr;
    }
}