Skip to content

Instantly share code, notes, and snippets.

@bradfordbarr
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradfordbarr/9204591 to your computer and use it in GitHub Desktop.
Save bradfordbarr/9204591 to your computer and use it in GitHub Desktop.
AVR Hello World
/* Borrowed from: http://wiki.hacdc.org/index.php/AVR_Lesson:_Output_Pins_I */
/* Blinker Demo */
#include <avr/io.h> /* Defines pins, ports, etc */
#define F_CPU 8000000UL /* Sets up the chip speed for delay.h */
#include <util/delay.h> /* Functions to waste time */
#define LED PB1 /* Defines pin PB4 for the LED. I
often incorporate a bunch of the circuit
info in the defines, which makes
porting the code to another chip
easier and reminds you of how to
hook it up. */
int main(void){
DDRB = _BV(LED); /* Data Direction Register B:
writing a one to the bit
enables output. */
while(1){ /* the main loop, from which we never return */
PORTB = _BV(LED); /* Turn on the LED bit/pin in PORTB */
_delay_ms(400); /* wait */
PORTB &= ~_BV(LED); /* Turn off the LED bit/pin in PORTB */
_delay_ms(400); /* wait */
}
return(0); /* never reached */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment