From a0e3f0373ddea97beeb64270db3d5dd91e1bbc0c Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Mon, 28 Jul 2014 22:55:18 +0300 Subject: Initial code --- hello.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 hello.c (limited to 'hello.c') diff --git a/hello.c b/hello.c new file mode 100644 index 0000000..e34ba06 --- /dev/null +++ b/hello.c @@ -0,0 +1,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 +// F_CPU frequency to be defined at command line +#include + +// 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; +} + -- cgit v1.3.1