summaryrefslogtreecommitdiff
path: root/hello.c
diff options
context:
space:
mode:
authorYuval Adam <yuv.adm@gmail.com>2014-07-28 22:55:18 +0300
committerYuval Adam <yuv.adm@gmail.com>2014-07-28 22:55:18 +0300
commita0e3f0373ddea97beeb64270db3d5dd91e1bbc0c (patch)
treea152dabd49ffb8b4ae99b2ea821d5c050542dbd4 /hello.c
Initial code
Diffstat (limited to 'hello.c')
-rw-r--r--hello.c48
1 files changed, 48 insertions, 0 deletions
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 <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;
+}
+