/*
 * GccApplication1.c
 *
 * Created: 1/21/2015 10:39:17 AM
 *  Author: David Frazier and John Ingram
 * 
 * Description:  Use 3 LEDs attached to the PB1, PB2 and PB3 port on an ATMEGA 168 to represent
 *               the binary numbers 0 through 7
 */ 

#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
	
	// Turn on PB1, PB2 and PB3 for output
	DDRB |= _BV(DDB1);
	DDRB |= _BV(DDB2);
	DDRB |= _BV(DDB3);
	
	while(1)
	{
		
		//            3   2   1
		//  Binary 0 off off off
		PORTB = 0x00;
		_delay_ms(50000);

		_delay_ms(20000);
				
		//  Binary 1 off off on
		
		// _BV is a macro that shifts the number 1 to the left
		// same as (1 << PB1)
		// ^= is an XOR that maintains all bits EXCEPT the one that you toggled
		
		PORTB ^= _BV(PB1);
		_delay_ms(20000);
				
		//  Binary 2 off on off
		PORTB ^= _BV(PB2);
		PORTB ^= _BV(PB1);
		_delay_ms(20000);
				
		//  Binary 3 off on on
		PORTB ^= _BV(PB1);
		_delay_ms(20000);
				
		//  Binary 4 on off off
		PORTB ^= _BV(PB3);
		PORTB ^= _BV(PB2);
		PORTB ^= _BV(PB1);
		_delay_ms(20000);
				
		//  Binary 5 on off on
		PORTB ^= _BV(PB1);
		_delay_ms(20000);
				
		//  Binary 6 on on off
		PORTB ^= _BV(PB2);
		PORTB ^= _BV(PB1);
		_delay_ms(20000);
				
		//  Binary 7 on on on 
		PORTB ^= _BV(PB1);
		_delay_ms(20000);        

	
   
    }
}