Permalink
Browse files

Wrote basic example of flashing the Red LED on a Nanode from the comm…

…and-line.
  • Loading branch information...
0 parents commit 87fd9cdf135fc6f83618397d11020184894da41f @njh committed Mar 7, 2012
Showing with 72 additions and 0 deletions.
  1. +39 −0 Makefile
  2. +33 −0 nanode-flash-led.c
@@ -0,0 +1,39 @@
+
+# Set this to the serial port that your Nanode is connected to
+# (on Mac OS X use 'ls /dev/tty.usbserial*' to get the name)
+SERIAL_PORT = /dev/tty.usbserial-A700fbtR
+
+# Nanode settings
+AVR_MCU = atmega328p
+AVR_MCU_SPEED = 16000000UL
+AVRDUDE_OPTIONS = -P $(SERIAL_PORT) -c arduino -b 57600 -p $(AVR_MCU)
+
+# AVR Compiler definitions
+CC = avr-gcc
+LD = avr-gcc
+ELF_SIZE = avr-size
+OBJCOPY = avr-objcopy
+CFLAGS = -mmcu=$(AVR_MCU) -DF_CPU=$(AVR_MCU_SPEED) -Wall -W -Os
+LDFLAGS = -mmcu=$(AVR_MCU) -Wl
+
+
+all: nanode-flash-led.hex
+
+nanode-flash-led.elf: nanode-flash-led.o
+ $(CC) $(LDFLAGS) -o $@ $^
+
+load: nanode-flash-led.hex
+ avrdude $(AVRDUDE_OPTIONS) -e -U flash:w:$<
+
+%.o: %.c
+ $(CC) $(CFLAGS) -o $@ -c $^
+
+%.hex: %.elf
+ $(OBJCOPY) $^ -j .text -j .data -O ihex $@
+ $(ELF_SIZE) $^
+
+clean:
+ rm -f *.o *.elf *.hex
+
+
+.PHONY: all clean
@@ -0,0 +1,33 @@
+/*
+ * Basic pure-C program to flash the red LED on the Nanode
+ *
+ * The Red LED is connected to Pin 6 of Port D:
+ * http://wiki.london.hackspace.org.uk/view/Project:Nanode/docs
+ *
+ */
+
+#include <avr/io.h>
+#include <util/delay.h>
+
+#define NANODE_RED_LED PD6
+
+// Some macros that make the code more readable
+#define OUTPUT_LOW(port,pin) port &= ~(1<<pin)
+#define OUTPUT_HIGH(port,pin) port |= (1<<pin)
+#define SET_INPUT(portdir,pin) portdir &= ~(1<<pin)
+#define SET_OUTPUT(portdir,pin) portdir |= (1<<pin)
+
+
+int main(void)
+{
+ SET_OUTPUT(DDRD, NANODE_RED_LED);
+
+ while (1) {
+ OUTPUT_HIGH(PORTD, NANODE_RED_LED);
+ _delay_ms(1000);
+ OUTPUT_LOW(PORTD, NANODE_RED_LED);
+ _delay_ms(1000);
+ }
+
+ return 0;
+}

0 comments on commit 87fd9cd

Please sign in to comment.