Skip to content

Instantly share code, notes, and snippets.

@naotaco
Created October 1, 2016 14:20
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 naotaco/f5a436dfefd35a407ca58b724ff33985 to your computer and use it in GitHub Desktop.
Save naotaco/f5a436dfefd35a407ca58b724ff33985 to your computer and use it in GitHub Desktop.
LED blink code for AVR
#include <avr/io.h>
#define F_CPU 8000000UL //8MHz
#include <util/delay.h>
int main(void){
DDRC = 0x02; // C1 to output
CLKPR = (1 << CLKPCE); // Enable clock change
CLKPR = 0; // 0 to 1-div clock (max speed = 8MHz)
for(;;){
if (PORTC & 0x02){
PORTC &= ~0x02;
}else{
PORTC |= 0x02;
}
_delay_ms(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment