Skip to content

Instantly share code, notes, and snippets.

@danasf
Created July 8, 2014 21:08
Show Gist options
  • Select an option

  • Save danasf/8fa4ad175a3a96871481 to your computer and use it in GitHub Desktop.

Select an option

Save danasf/8fa4ad175a3a96871481 to your computer and use it in GitHub Desktop.
/* blink lights on ATTiny with AVR-C */
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
#define LED4 PB4
#define LED3 PB3
#define LED2 PB2
#define LED1 PB1
int main(void) {
int8_t i;
/* Set Pin PB4,PB3 to output */
DDRB |= (1 << LED1)|(1 << LED2)|(1 << LED3)|(1 << LED4);
PORTB &= ~(1 << LED1); // LOW
PORTB &= ~(1 << LED2); // LOW
PORTB &= ~(1 << LED3); // LOW
PORTB &= ~(1 << LED4); // LOW
while(1) {
PORTB |= (1 << LED1); // HIGH
PORTB &= ~(1 << LED2); // LOW
PORTB |= (1 << LED3); // HIGH
PORTB &= ~(1 << LED4); // LOW
_delay_ms(500);
PORTB &= ~(1 << LED1); // LOW
PORTB |= (1 << LED2); // HIGH
PORTB &= ~(1 << LED3); // LOW
PORTB |= (1 << LED4); // HIGH
_delay_ms(500);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment