/** \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 state = 1;
while (1) {
switch (state) {
case 1:
// Button Down: Pin -> 0V
// Button Up: Pin -> 5V
if (~PINC & _BV(3)) {
state = 2;
PORTE |= _BV(3);
}
break;
case 2:
if (PINC & _BV(3)) {
state = 3;
}
break;
case 3:
if (~PINC & _BV(3)) {
state = 4;
PORTE &= ~_BV(3);
}
break;
case 4:
if (PINC & _BV(3)) {
state = 1;
}
break;
}
}
}