Atmega32 Super Blinky Part V: Getting started with the Atmega32


This is the C code used in the above video:

// SuperBlinky.c
//
//Iterative multiplication and division of a binary number by 2
//Display of result on PORTB
//
//Created: January 17, 2013  11:31AM EST
//Author: Holger Marten
 
 
                               
#include <avr/io.h>                        //Include standard input output library
#define F_CPU 1000000UL          //Let libraries know that CPU runs at 1000000 cycles/second
#include <util/delay.h>                 //Include library that has delay functions
int main (void)
{
                int i = 0;                //Set initial value that will be displayed on port B             
               
                DDRB = 0xFF;     // set all pins on PORTB for output
                while(1) {
                                for(i = 1; i < 128; i = i*2)  //Loop that keeps on multiplying by                                                                                     //2 and storing value in i
                                {
                                                PORTB = i;                           //Assign value in i to PORTB       
                                                //_delay_loop_2(30000);
                                }
                                for(i = 128; i > 1; i -= i/2) //Loop that keeps on dividing by 2 and                                                                                  //storing value in i
                                {
                                                PORTB = i;                           //Assign value in i to PORTB
                                                //_delay_loop_2(30000);
                                }
                }
                return 1;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s