From 93e5335332743131cb429776d84e0745f2a83495 Mon Sep 17 00:00:00 2001 From: Tom Barthe Date: Fri, 27 Nov 2020 04:49:27 +0100 Subject: [PATCH] Ajout d'un exemple C de clignotement d'une LED --- Makefile | 26 ++++++++++++++++++++++++++ led.c | 20 ++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 Makefile create mode 100644 led.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ddb2760 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +CC = avr-gcc +OBJCOPY = avr-objcopy +AVRDUDE = avrdude +CFLAGS = -Os -DF_CPU=16000000UL -mmcu=atmega328p +SERIAL = /dev/ttyACM0 +TARGET = led + +.PHONY: all clean flash + +all: $(TARGET).hex + +flash: $(TARGET).hex + $(AVRDUDE) -F -V -c arduino -p ATMEGA328P -P $(SERIAL) -b 115200 \ + -U flash:w:$< + +$(TARGET).hex: $(TARGET) + $(OBJCOPY) -O ihex -R .eeprom $< $@ + +$(TARGET): $(TARGET).o + $(CC) $(CFLAGS) -o $@ $< + +$(TARGET).o: $(TARGET).c + $(CC) $(CFLAGS) -c -o $@ $< + +clean: + rm -f $(TARGET) $(TARGET).hex $(TARGET).o diff --git a/led.c b/led.c new file mode 100644 index 0000000..9d2f67f --- /dev/null +++ b/led.c @@ -0,0 +1,20 @@ +#include +#include + + + +int main(void) { + DDRC = 0x01; // initialize port C + + while (1) { + // LED on + PORTC = 0b00000001; // PC0 = High = Vcc + _delay_ms(500); // wait 500 milliseconds + + // LED off + PORTC = 0b00000000; // PC0 = Low = 0v + _delay_ms(500); // wait 500 milliseconds + } + + return 0; +}