Ajout d'un exemple C de clignotement d'une LED
This commit is contained in:
parent
75826a41aa
commit
93e5335332
2 changed files with 46 additions and 0 deletions
26
Makefile
Normal file
26
Makefile
Normal file
|
@ -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
Normal file
20
led.c
Normal file
|
@ -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…
Reference in a new issue