Skip to content

Instantly share code, notes, and snippets.

@pilinux
Created February 18, 2016 10:27
Show Gist options
  • Save pilinux/29bcc01380f3e920e8c0 to your computer and use it in GitHub Desktop.
Save pilinux/29bcc01380f3e920e8c0 to your computer and use it in GitHub Desktop.
Lab 2 (AVR C)
// Preamble
#include <avr/io.h>
#include <util/delay.h> /* Time delay function */
// Function definitions
#define LED_DDR DDRB
#define LED_PORT PORTB
//main function
int main(void)
{
// Initialization
LED_DDR = 0b00000001; // Set the first pin of Port B as output
// Event loop
while(1) {
LED_PORT = 0b00000001; // Turn on first pin in Port B
_delay_ms(500); // Wait 500 ms
LED_PORT = 0b00000000; // Turn off first pin in Port B
_delay_ms(500); // Wait 500 ms
}
return(0); // This line is never reached
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment