ex01 ok
This commit is contained in:
24
.vscode/c_cpp_properties.json
vendored
Normal file
24
.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "linux-avr-gcc",
|
||||||
|
"includePath": ["${workspaceFolder}/**", "/usr/lib/avr/include/**"],
|
||||||
|
"defines": [],
|
||||||
|
"mergeConfigurations": false,
|
||||||
|
"compilerPath": "/usr/bin/avr-gcc",
|
||||||
|
"cStandard": "gnu11",
|
||||||
|
"cppStandard": "gnu++14",
|
||||||
|
"intelliSenseMode": "linux-gcc-x64",
|
||||||
|
"compilerArgs": ["-mmcu=atmega328p", "-DF_CPU=16000000UL", "-Os"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "linux-gcc-x64",
|
||||||
|
"includePath": ["${workspaceFolder}/**"],
|
||||||
|
"compilerPath": "/usr/bin/gcc",
|
||||||
|
"intelliSenseMode": "linux-gcc-x64",
|
||||||
|
"compilerArgs": [""],
|
||||||
|
"mergeConfigurations": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
||||||
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"io.h": "c"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
# RESSOURCES #
|
# RESSOURCES
|
||||||
|
|
||||||
- https://github.com/m3y54m/start-avr/tree/master
|
- https://github.com/m3y54m/start-avr/tree/master
|
||||||
- avrdude 6.3 doc : https://download-mirror.savannah.gnu.org/releases/avrdude/avrdude-doc-6.3.pdf
|
- 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 ##
|
## ex00
|
||||||
|
|
||||||
avrdude output without flashing :
|
avrdude output without flashing :
|
||||||
|
|
||||||
```
|
```
|
||||||
avrdude -p m328p -c arduino -b 115200 -P /dev/ttyUSB0 -v
|
avrdude -p m328p -c arduino -b 115200 -P /dev/ttyUSB0 -v
|
||||||
|
|
||||||
@@ -73,4 +75,4 @@ avrdude: safemode: efuse reads as 0
|
|||||||
avrdude: safemode: Fuses OK (E:00, H:00, L:00)
|
avrdude: safemode: Fuses OK (E:00, H:00, L:00)
|
||||||
|
|
||||||
avrdude done. Thank you.
|
avrdude done. Thank you.
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -8,12 +8,15 @@ AVRDUDE_MCU_TYPE = m328p
|
|||||||
BAUD_RATE = 115200
|
BAUD_RATE = 115200
|
||||||
SERIAL_PORT = /dev/ttyUSB0
|
SERIAL_PORT = /dev/ttyUSB0
|
||||||
PROGRAMMER_ID = arduino
|
PROGRAMMER_ID = arduino
|
||||||
|
DUMP_ORI = ../../ressources/dump_atmega328p_ori.hex
|
||||||
|
|
||||||
|
|
||||||
all: hex flash
|
all: hex flash
|
||||||
|
|
||||||
|
|
||||||
hex: $(TARGET).hex
|
hex: $(TARGET).hex
|
||||||
|
|
||||||
|
|
||||||
# https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html
|
# https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html
|
||||||
$(TARGET).bin: $(TARGET).c
|
$(TARGET).bin: $(TARGET).c
|
||||||
$(CC) -mmcu=$(AVRGCC_MCU_TYPE) -D F_CPU=$(F_CPU) $(TARGET).c -o $(TARGET).bin
|
$(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
|
avrdude -p $(AVRDUDE_MCU_TYPE) -c $(PROGRAMMER_ID) -b $(BAUD_RATE) -P $(SERIAL_PORT) -U flash:w:$(TARGET).hex
|
||||||
|
|
||||||
|
|
||||||
dump:
|
restore:
|
||||||
avrdude -p m328p -c arduino -b 115200 -P /dev/ttyUSB0 -U flash:r:dump_atmega328p.hex
|
avrdude -p $(AVRDUDE_MCU_TYPE) -c $(PROGRAMMER_ID) -b $(BAUD_RATE) -P $(SERIAL_PORT) -U flash:w:$(DUMP_ORI)
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f main.hex main.bin
|
rm -f main.hex main.bin
|
||||||
|
|
||||||
|
|
||||||
.PHONY : all clean hex flash dump
|
.PHONY : all clean hex flash restore
|
||||||
@@ -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()
|
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;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user