setup module01 ex00
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
- avrdude 6.3 doc : https://download-mirror.savannah.gnu.org/releases/avrdude/avrdude-doc-6.3.pdf
|
||||
- embedded systems : https://en.wikibooks.org/wiki/Embedded_Systems/Atmel_AVR
|
||||
|
||||
## ex00
|
||||
## m00ex00
|
||||
|
||||
avrdude output without flashing :
|
||||
|
||||
|
||||
43
module01/ex00/Makefile
Normal file
43
module01/ex00/Makefile
Normal file
@@ -0,0 +1,43 @@
|
||||
# frequency of the CPU (in Hz)
|
||||
F_CPU = 16000000UL
|
||||
TARGET = main
|
||||
CC = avr-gcc
|
||||
|
||||
AVRGCC_MCU_TYPE = atmega328p
|
||||
AVRDUDE_MCU_TYPE = m328p
|
||||
BAUD_RATE = 115200
|
||||
SERIAL_PORT = /dev/ttyUSB0
|
||||
PROGRAMMER_ID = arduino
|
||||
DUMP_ORI = ../../ressources/dump_atmega328p_ori.hex
|
||||
|
||||
|
||||
all: hex flash
|
||||
|
||||
|
||||
hex: $(TARGET).hex
|
||||
|
||||
|
||||
# https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html
|
||||
$(TARGET).bin: $(TARGET).c
|
||||
$(CC) -mmcu=$(AVRGCC_MCU_TYPE) -D F_CPU=$(F_CPU) $(TARGET).c -Os -o $(TARGET).bin
|
||||
|
||||
|
||||
# https://linux.die.net/man/1/avr-objcopy
|
||||
$(TARGET).hex: $(TARGET).bin
|
||||
avr-objcopy -O ihex $(TARGET).bin $(TARGET).hex
|
||||
|
||||
|
||||
# AVR Downloader/UploaDEr https://avrdudes.github.io/avrdude (v6.3 https://download-mirror.savannah.gnu.org/releases/avrdude/avrdude-doc-6.3.pdf)
|
||||
flash:
|
||||
avrdude -p $(AVRDUDE_MCU_TYPE) -c $(PROGRAMMER_ID) -b $(BAUD_RATE) -P $(SERIAL_PORT) -U flash:w:$(TARGET).hex
|
||||
|
||||
|
||||
restore:
|
||||
avrdude -p $(AVRDUDE_MCU_TYPE) -c $(PROGRAMMER_ID) -b $(BAUD_RATE) -P $(SERIAL_PORT) -U flash:w:$(DUMP_ORI)
|
||||
|
||||
|
||||
clean:
|
||||
rm -f main.hex main.bin
|
||||
|
||||
|
||||
.PHONY : all clean hex flash restore
|
||||
26
module01/ex00/main.c
Normal file
26
module01/ex00/main.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
#define SET(REGISTER, BIT) REGISTER |= 1 << BIT
|
||||
#define CLEAR(REGISTER, BIT) REGISTER &= ~(1 << BIT)
|
||||
#define TEST(REGISTER, BIT) REGISTER & 1 << BIT
|
||||
#define TOGGLE(REGISTER, BIT) REGISTER ^= 1 << BIT
|
||||
|
||||
#define TEST_PIN(PORT, BIT) PIN ## PORT & 1 << BIT
|
||||
#define TOGGLE_PIN(PORT, BIT) PIN ## PORT |= 1 << BIT
|
||||
#define MODE_INPUT(PORT, BIT) CLEAR(DDR ## PORT, BIT)
|
||||
#define MODE_OUTPUT(PORT, BIT) SET(DDR ## PORT, BIT)
|
||||
#define IS_PIN_SET(PORT, BIT) (TEST_PIN(PORT, BIT)) == 0
|
||||
#define IS_PIN_CLEAR(PORT, BIT) (TEST_PIN(PORT, BIT)) == 1
|
||||
|
||||
#define D1 0
|
||||
#define D2 1
|
||||
#define D3 2
|
||||
#define D4 4
|
||||
#define SW1 2
|
||||
#define SW2 4
|
||||
|
||||
int main() {
|
||||
MODE_OUTPUT(B, D1);
|
||||
SET(PORTB, D1);
|
||||
}
|
||||
BIN
ressources/fr.subject_42chips_module01.pdf
Normal file
BIN
ressources/fr.subject_42chips_module01.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user