Ajout d'un exemple C de clignotement d'une LED.

jeltz 4 years ago
parent 75826a41aa
commit 97affb2557
Signed by: jeltz
GPG Key ID: 800882B66C0C3326

@ -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

20
led.c

@ -0,0 +1,20 @@
#include <avr/io.h>
#include <util/delay.h>
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;
}
Loading…
Cancel
Save