commit fd1f7eb73100cbc2e4c9912976e6a9e6f2b9e5bb Author: xoy Date: Wed Dec 11 01:14:46 2024 +0100 [First construction] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2135d58 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.elf +*.hex +*.o diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..c24a894 --- /dev/null +++ b/build.sh @@ -0,0 +1,4 @@ +#!/usr/bin/zsh +avr-as -mmcu=atmega328p -o main.o main.s +avr-ld -o main.elf main.o +avr-objcopy -O ihex main.elf main.hex diff --git a/flash.sh b/flash.sh new file mode 100755 index 0000000..b9c6053 --- /dev/null +++ b/flash.sh @@ -0,0 +1,3 @@ +#!/usr/bin/zsh +DEVICE=/dev/ttyACM0 +sudo avrdude -p m328p -c arduino -P $DEVICE -U flash:w:main.hex diff --git a/main.s b/main.s new file mode 100644 index 0000000..70156a0 --- /dev/null +++ b/main.s @@ -0,0 +1,38 @@ +.equ DDRB, 0x04 +.equ PORTB, 0x05 + +.global main + +main: + ldi r16, 1 + out DDRB, r16 + ldi r16, 0 + out PORTB, r16 +loop_start: + com r16 + out PORTB, r16 +init_sleep: + ldi r18, 0xFF + ldi r19, 0xFF + ldi r20, 0xFF +sleep_outer: + cpi r18, 0x00 + breq loop_start + dec r18 + rjmp sleep_inner1 +sleep_inner0: + cpi r19, 0 + breq sleep_inner0_reset + dec r19 + rjmp sleep_inner1 +sleep_inner0_reset: + ldi r19, 0xFF + rjmp sleep_outer +sleep_inner1: + cpi r20, 0 + breq sleep_inner1_reset + dec r20 + rjmp sleep_inner1 +sleep_inner1_reset: + ldi r20, 0x1F + rjmp sleep_inner0 diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..a614a32 --- /dev/null +++ b/readme.md @@ -0,0 +1,12 @@ +# ATMega328P Blinking LED Assembly + +Toggle a LED about every second with 20MHz. + +## Breadboard structure + +PIN8 > LED > 220Ohm Resistor > GND + +## Used packages (Linux) + +- avr-binutils +- avrdude