blob: e34ba06aa18059b437dd6a2a9a075f1bf6ece559 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
/**
*
* Blinking LED ATTiny85 "hello world"
*
* Following the tutorial at:
* http://www.instructables.com/id/Honey-I-Shrunk-the-Arduino-Moving-from-Arduino-t/?ALLSTEPS
*
*/
#include <avr/io.h>
// F_CPU frequency to be defined at command line
#include <util/delay.h>
// LED is on pin 2, PB3
#define LED PB3
#define DELAY_MS 500
int main () {
uint8_t high = 0;
uint16_t ms = 0;
// setup LED pin for output in port B's direction register
DDRB |= (1 << LED);
// set LED pin LOW
PORTB &= ~(1 << LED);
while (1) {
high = !high;
if (high) {
// set LED pin HIGH
PORTB |= (1 << LED);
} else {
// set LED pin LOW
PORTB &= ~(1 << LED);
}
// delay for 500 ms
for (ms = DELAY_MS; ms > 0; ms -= 10) {
_delay_ms(10);
}
}
return 0;
}
|