aboutsummaryrefslogtreecommitdiff
path: root/examples/BlinkInAVRC/blink.c
diff options
context:
space:
mode:
authorSudar <sudar@sudarmuthu.com>2013-06-15 19:42:13 +0530
committerSudar <sudar@sudarmuthu.com>2013-06-15 19:42:13 +0530
commit0149f34daf9d39e002993b604ae575ceb0eea01e (patch)
tree07f5125d372a7d4e8758dacb7fa82050474e7dda /examples/BlinkInAVRC/blink.c
parent0028fabc64c63f889fc0a9e1eae7943bb18e1357 (diff)
Add an example to show how to compile AVR C files
Diffstat (limited to 'examples/BlinkInAVRC/blink.c')
-rw-r--r--examples/BlinkInAVRC/blink.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/BlinkInAVRC/blink.c b/examples/BlinkInAVRC/blink.c
new file mode 100644
index 0000000..d8b7c8f
--- /dev/null
+++ b/examples/BlinkInAVRC/blink.c
@@ -0,0 +1,38 @@
+/*
+ * © Anil Kumar Pugalia, 2010. Email: email@sarika-pugs.com
+ *
+ * ATmega48/88/168, ATmega16/32
+ *
+ * Example Blink. Toggles all IO pins at 1Hz
+ */
+
+#include <avr/io.h>
+#include <util/delay.h>
+
+void init_io(void)
+{
+ // 1 = output, 0 = input
+ DDRB = 0b11111111; // All outputs
+ DDRC = 0b11111111; // All outputs
+ DDRD = 0b11111110; // PORTD (RX on PD0). Just for demo
+}
+
+int main(void)
+{
+ init_io();
+
+ while (1)
+ {
+ PORTC = 0xFF;
+ PORTB = 0xFF;
+ PORTD = 0xFF;
+ _delay_ms(500);
+
+ PORTC = 0x00;
+ PORTB = 0x00;
+ PORTD = 0x00;
+ _delay_ms(500);
+ }
+
+ return 0;
+}