This commit is contained in:
hugogogo
2025-03-03 20:45:44 +01:00
parent 90c91a198e
commit 6b033a3352
5 changed files with 74 additions and 6 deletions

View File

@@ -8,12 +8,15 @@ 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 -o $(TARGET).bin
@@ -29,12 +32,12 @@ flash:
avrdude -p $(AVRDUDE_MCU_TYPE) -c $(PROGRAMMER_ID) -b $(BAUD_RATE) -P $(SERIAL_PORT) -U flash:w:$(TARGET).hex
dump:
avrdude -p m328p -c arduino -b 115200 -P /dev/ttyUSB0 -U flash:r:dump_atmega328p.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 dump
.PHONY : all clean hex flash restore

View File

@@ -1,3 +1,37 @@
#include <avr/io.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
int main()
{
// DDRx : select direction of the pin
// - 1 = output (pull-up off)
// - 0 = input
// PORTx :
// if DDRx = 1 (output mode) :
// - 1 = HIGH (5V)
// - 0 = LOW (0V)
// if DDRx = 0 (input mode) :
// - 1 = pull-up on
// - 0 = pull-up off
// PINx :
// turn on led 1
SET(DDRB, 0); // make PB0 as OUTPUT
SET(PORTB, 0); // make PB0 as HIGH (LED turns ON)
// CLEAR(DDRB, 1); // make PB0 as INPUT
// SET(PORTB, 1); // make PB0 pullup on
// SET(DDRB, 2); // make PB0 as OUTPUT
// CLEAR(PORTB, 2); // make PB0 as LOW (LED turns OFF)
// CLEAR(DDRB, 4); // make PB0 as INPUT
// CLEAR(PORTB, 4); // make PB0 as LOW (LED turns OFF)
return 0;
}