diff options
-rwxr-xr-x | asm/blink/avrdasm | 2 | ||||
-rw-r--r-- | asm/blink/blink.s | 12 | ||||
-rw-r--r-- | asm/blink/dat.h | 20 | ||||
-rw-r--r-- | asm/blink/makefile | 17 | ||||
-rwxr-xr-x | asm/blinkdelay/avrdasm | 2 | ||||
-rw-r--r-- | asm/blinkdelay/blink.s | 24 | ||||
-rw-r--r-- | asm/blinkdelay/dat.h | 20 | ||||
-rw-r--r-- | asm/blinkdelay/makefile | 17 | ||||
-rw-r--r-- | asm/blinkdelay2/avr.map | 404 | ||||
-rwxr-xr-x | asm/blinkdelay2/avrdasm | 2 | ||||
-rw-r--r-- | asm/blinkdelay2/blink.s | 67 | ||||
-rw-r--r-- | asm/blinkdelay2/dat.h | 25 | ||||
-rw-r--r-- | asm/blinkdelay2/link.ld | 56 | ||||
-rw-r--r-- | asm/blinkdelay2/m328p.ld | 8 | ||||
-rw-r--r-- | asm/blinkdelay2/makefile | 19 | ||||
-rwxr-xr-x | asm/dht11/avrdasm | 2 | ||||
-rw-r--r-- | asm/dht11/blink.s | 71 | ||||
-rw-r--r-- | asm/dht11/dat.h | 25 | ||||
-rw-r--r-- | asm/dht11/link.ld | 34 | ||||
-rw-r--r-- | asm/dht11/makefile | 19 | ||||
-rw-r--r-- | c/blink/blink.c | 23 | ||||
-rw-r--r-- | c/timer/timer.c | 23 | ||||
-rw-r--r-- | c/timer/timerctc.c | 26 | ||||
-rw-r--r-- | readme.md | 3 |
24 files changed, 921 insertions, 0 deletions
diff --git a/asm/blink/avrdasm b/asm/blink/avrdasm new file mode 100755 index 0000000..ea0707b --- /dev/null +++ b/asm/blink/avrdasm @@ -0,0 +1,2 @@ +#!/bin/sh +avr-objdump -D *.elf diff --git a/asm/blink/blink.s b/asm/blink/blink.s new file mode 100644 index 0000000..8577db3 --- /dev/null +++ b/asm/blink/blink.s @@ -0,0 +1,12 @@ +.include "dat.h" + +.globl main +main: + ldi r16, 1<<DDRB5 + ori r16, 1<<DDRB4 + ldi r17, 0<<PORTB5 + ldi r17, 1<<PORTB4 + out DDRB, r16 + out PORTB, r17 +halt: + rjmp halt diff --git a/asm/blink/dat.h b/asm/blink/dat.h new file mode 100644 index 0000000..d3783b6 --- /dev/null +++ b/asm/blink/dat.h @@ -0,0 +1,20 @@ +/* Data Registers */ +.equ PORTB, 0x05 +.equ PORTB0, 0 +.equ PORTB1, 1 +.equ PORTB2, 2 +.equ PORTB3, 3 +.equ PORTB4, 4 +.equ PORTB5, 5 +.equ PORTB6, 6 +.equ PORTB7, 7 +/* Data Direction Registers */ +.equ DDRB, 0x04 +.equ DDRB0, 0 +.equ DDRB1, 1 +.equ DDRB2, 2 +.equ DDRB3, 3 +.equ DDRB4, 4 +.equ DDRB5, 5 +.equ DDRB6, 6 +.equ DDRB7, 7 diff --git a/asm/blink/makefile b/asm/blink/makefile new file mode 100644 index 0000000..4790211 --- /dev/null +++ b/asm/blink/makefile @@ -0,0 +1,17 @@ +CC=avr-gcc +AS=avr-as + +PORT=/dev/ttyACM0 +TARG=blink + +all: build + +build: + $(AS) -mmcu=atmega328p -o $(TARG).elf $(TARG).s + avr-objcopy -j .text -j .data -O ihex $(TARG).elf $(TARG).hex + +burn: + avrdude -v -p atmega328p -c arduino -P $(PORT) -b 115200 -D -U flash:w:$(TARG).hex + +clean: + rm -f $(TARG).elf $(TARG).hex diff --git a/asm/blinkdelay/avrdasm b/asm/blinkdelay/avrdasm new file mode 100755 index 0000000..ea0707b --- /dev/null +++ b/asm/blinkdelay/avrdasm @@ -0,0 +1,2 @@ +#!/bin/sh +avr-objdump -D *.elf diff --git a/asm/blinkdelay/blink.s b/asm/blinkdelay/blink.s new file mode 100644 index 0000000..30219b1 --- /dev/null +++ b/asm/blinkdelay/blink.s @@ -0,0 +1,24 @@ +.include "dat.h" + +.globl main +main: + ldi r16, 1<<DDRB5 + ldi r17, 0<<PORTB5 + out DDRB, r16 + out PORTB, r17 +loop: + /* delay loop */ + ldi r18, 82 + ldi r19, 43 + ldi r20, 0 +l1: + dec r20 + brne l1 + dec r19 + brne l1 + dec r18 + brne l1 + in r16, PORTB + com r16 + out PORTB, r16 + rjmp loop diff --git a/asm/blinkdelay/dat.h b/asm/blinkdelay/dat.h new file mode 100644 index 0000000..d3783b6 --- /dev/null +++ b/asm/blinkdelay/dat.h @@ -0,0 +1,20 @@ +/* Data Registers */ +.equ PORTB, 0x05 +.equ PORTB0, 0 +.equ PORTB1, 1 +.equ PORTB2, 2 +.equ PORTB3, 3 +.equ PORTB4, 4 +.equ PORTB5, 5 +.equ PORTB6, 6 +.equ PORTB7, 7 +/* Data Direction Registers */ +.equ DDRB, 0x04 +.equ DDRB0, 0 +.equ DDRB1, 1 +.equ DDRB2, 2 +.equ DDRB3, 3 +.equ DDRB4, 4 +.equ DDRB5, 5 +.equ DDRB6, 6 +.equ DDRB7, 7 diff --git a/asm/blinkdelay/makefile b/asm/blinkdelay/makefile new file mode 100644 index 0000000..4ad8b12 --- /dev/null +++ b/asm/blinkdelay/makefile @@ -0,0 +1,17 @@ +CC=avr-gcc +AS=avr-as + +PORT=/dev/ttyACM0 +TARG=blink + +all: build + +build: + $(CC) -mmcu=atmega328p -o $(TARG).elf $(TARG).s + avr-objcopy -j .text -j .data -O ihex $(TARG).elf $(TARG).hex + +burn: + avrdude -v -p atmega328p -c arduino -P $(PORT) -b 115200 -D -U flash:w:$(TARG).hex + +clean: + rm -f $(TARG).elf $(TARG).hex diff --git a/asm/blinkdelay2/avr.map b/asm/blinkdelay2/avr.map new file mode 100644 index 0000000..844079f --- /dev/null +++ b/asm/blinkdelay2/avr.map @@ -0,0 +1,404 @@ +Archive member included to satisfy reference by file (symbol) + +/usr/lib/gcc/avr/8.2.0/avr5/libgcc.a(_exit.o) + /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/crtatmega328p.o (exit) + +Memory Configuration + +Name Origin Length Attributes +text 0x0000000000000000 0x0000000000020000 xr +data 0x0000000000800060 0x000000000000ffa0 rw !x +eeprom 0x0000000000810000 0x0000000000010000 rw !x +fuse 0x0000000000820000 0x0000000000000400 rw !x +lock 0x0000000000830000 0x0000000000000400 rw !x +signature 0x0000000000840000 0x0000000000000400 rw !x +user_signatures 0x0000000000850000 0x0000000000000400 rw !x +*default* 0x0000000000000000 0xffffffffffffffff + +Linker script and memory map + +Address of section .data set to 0x800100 +LOAD /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/crtatmega328p.o +LOAD /tmp/ccnHW39M.o +START GROUP +LOAD /usr/lib/gcc/avr/8.2.0/avr5/libgcc.a +LOAD /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/libm.a +LOAD /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/libc.a +LOAD /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/libatmega328p.a +END GROUP + 0x0000000000020000 __TEXT_REGION_LENGTH__ = DEFINED (__TEXT_REGION_LENGTH__)?__TEXT_REGION_LENGTH__:0x20000 + 0x000000000000ffa0 __DATA_REGION_LENGTH__ = DEFINED (__DATA_REGION_LENGTH__)?__DATA_REGION_LENGTH__:0xffa0 + 0x0000000000010000 __EEPROM_REGION_LENGTH__ = DEFINED (__EEPROM_REGION_LENGTH__)?__EEPROM_REGION_LENGTH__:0x10000 + 0x0000000000000400 __FUSE_REGION_LENGTH__ = DEFINED (__FUSE_REGION_LENGTH__)?__FUSE_REGION_LENGTH__:0x400 + 0x0000000000000400 __LOCK_REGION_LENGTH__ = DEFINED (__LOCK_REGION_LENGTH__)?__LOCK_REGION_LENGTH__:0x400 + 0x0000000000000400 __SIGNATURE_REGION_LENGTH__ = DEFINED (__SIGNATURE_REGION_LENGTH__)?__SIGNATURE_REGION_LENGTH__:0x400 + 0x0000000000000400 __USER_SIGNATURE_REGION_LENGTH__ = DEFINED (__USER_SIGNATURE_REGION_LENGTH__)?__USER_SIGNATURE_REGION_LENGTH__:0x400 + +.hash + *(.hash) + +.dynsym + *(.dynsym) + +.dynstr + *(.dynstr) + +.gnu.version + *(.gnu.version) + +.gnu.version_d + *(.gnu.version_d) + +.gnu.version_r + *(.gnu.version_r) + +.rel.init + *(.rel.init) + +.rela.init + *(.rela.init) + +.rel.text + *(.rel.text) + *(.rel.text.*) + *(.rel.gnu.linkonce.t*) + +.rela.text + *(.rela.text) + *(.rela.text.*) + *(.rela.gnu.linkonce.t*) + +.rel.fini + *(.rel.fini) + +.rela.fini + *(.rela.fini) + +.rel.rodata + *(.rel.rodata) + *(.rel.rodata.*) + *(.rel.gnu.linkonce.r*) + +.rela.rodata + *(.rela.rodata) + *(.rela.rodata.*) + *(.rela.gnu.linkonce.r*) + +.rel.data + *(.rel.data) + *(.rel.data.*) + *(.rel.gnu.linkonce.d*) + +.rela.data + *(.rela.data) + *(.rela.data.*) + *(.rela.gnu.linkonce.d*) + +.rel.ctors + *(.rel.ctors) + +.rela.ctors + *(.rela.ctors) + +.rel.dtors + *(.rel.dtors) + +.rela.dtors + *(.rela.dtors) + +.rel.got + *(.rel.got) + +.rela.got + *(.rela.got) + +.rel.bss + *(.rel.bss) + +.rela.bss + *(.rela.bss) + +.rel.plt + *(.rel.plt) + +.rela.plt + *(.rela.plt) + +.text 0x0000000000000000 0x124 + *(.vectors) + .vectors 0x0000000000000000 0x68 /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/crtatmega328p.o + 0x0000000000000000 __vectors + 0x0000000000000000 __vector_default + *(.vectors) + *(.progmem.gcc*) + 0x0000000000000068 . = ALIGN (0x2) + 0x0000000000000068 __trampolines_start = . + *(.trampolines) + .trampolines 0x0000000000000068 0x0 linker stubs + *(.trampolines*) + 0x0000000000000068 __trampolines_end = . + *libprintf_flt.a:*(.progmem.data) + *libc.a:*(.progmem.data) + *(.progmem.*) + 0x0000000000000068 . = ALIGN (0x2) + *(.lowtext) + *(.lowtext*) + 0x0000000000000068 __ctors_start = . + *(.ctors) + 0x0000000000000068 __ctors_end = . + 0x0000000000000068 __dtors_start = . + *(.dtors) + 0x0000000000000068 __dtors_end = . + SORT_BY_NAME(*)(.ctors) + SORT_BY_NAME(*)(.dtors) + *(.init0) + .init0 0x0000000000000068 0x0 /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/crtatmega328p.o + 0x0000000000000068 __init + *(.init0) + *(.init1) + *(.init1) + *(.init2) + .init2 0x0000000000000068 0xc /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/crtatmega328p.o + *(.init2) + *(.init3) + *(.init3) + *(.init4) + *(.init4) + *(.init5) + *(.init5) + *(.init6) + *(.init6) + *(.init7) + *(.init7) + *(.init8) + *(.init8) + *(.init9) + .init9 0x0000000000000074 0x8 /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/crtatmega328p.o + *(.init9) + *(.text) + .text 0x000000000000007c 0x4 /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/crtatmega328p.o + 0x000000000000007c __vector_22 + 0x000000000000007c __vector_1 + 0x000000000000007c __vector_24 + 0x000000000000007c __vector_12 + 0x000000000000007c __bad_interrupt + 0x000000000000007c __vector_6 + 0x000000000000007c __vector_3 + 0x000000000000007c __vector_23 + 0x000000000000007c __vector_25 + 0x000000000000007c __vector_11 + 0x000000000000007c __vector_13 + 0x000000000000007c __vector_17 + 0x000000000000007c __vector_19 + 0x000000000000007c __vector_7 + 0x000000000000007c __vector_5 + 0x000000000000007c __vector_4 + 0x000000000000007c __vector_9 + 0x000000000000007c __vector_2 + 0x000000000000007c __vector_21 + 0x000000000000007c __vector_15 + 0x000000000000007c __vector_8 + 0x000000000000007c __vector_14 + 0x000000000000007c __vector_10 + 0x000000000000007c __vector_16 + 0x000000000000007c __vector_18 + 0x000000000000007c __vector_20 + .text 0x0000000000000080 0xa0 /tmp/ccnHW39M.o + 0x0000000000000080 vectors + 0x00000000000000fe main + .text 0x0000000000000120 0x0 /usr/lib/gcc/avr/8.2.0/avr5/libgcc.a(_exit.o) + 0x0000000000000120 . = ALIGN (0x2) + *(.text.*) + .text.libgcc.mul + 0x0000000000000120 0x0 /usr/lib/gcc/avr/8.2.0/avr5/libgcc.a(_exit.o) + .text.libgcc.div + 0x0000000000000120 0x0 /usr/lib/gcc/avr/8.2.0/avr5/libgcc.a(_exit.o) + .text.libgcc 0x0000000000000120 0x0 /usr/lib/gcc/avr/8.2.0/avr5/libgcc.a(_exit.o) + .text.libgcc.prologue + 0x0000000000000120 0x0 /usr/lib/gcc/avr/8.2.0/avr5/libgcc.a(_exit.o) + .text.libgcc.builtins + 0x0000000000000120 0x0 /usr/lib/gcc/avr/8.2.0/avr5/libgcc.a(_exit.o) + .text.libgcc.fmul + 0x0000000000000120 0x0 /usr/lib/gcc/avr/8.2.0/avr5/libgcc.a(_exit.o) + .text.libgcc.fixed + 0x0000000000000120 0x0 /usr/lib/gcc/avr/8.2.0/avr5/libgcc.a(_exit.o) + 0x0000000000000120 . = ALIGN (0x2) + *(.fini9) + .fini9 0x0000000000000120 0x0 /usr/lib/gcc/avr/8.2.0/avr5/libgcc.a(_exit.o) + 0x0000000000000120 exit + 0x0000000000000120 _exit + *(.fini9) + *(.fini8) + *(.fini8) + *(.fini7) + *(.fini7) + *(.fini6) + *(.fini6) + *(.fini5) + *(.fini5) + *(.fini4) + *(.fini4) + *(.fini3) + *(.fini3) + *(.fini2) + *(.fini2) + *(.fini1) + *(.fini1) + *(.fini0) + .fini0 0x0000000000000120 0x4 /usr/lib/gcc/avr/8.2.0/avr5/libgcc.a(_exit.o) + *(.fini0) + *(.hightext) + *(.hightext*) + *(.progmemx.*) + 0x0000000000000124 . = ALIGN (0x2) + *(.jumptables) + *(.jumptables*) + 0x0000000000000124 _etext = . + +.data 0x0000000000800100 0x0 load address 0x0000000000000124 + [!provide] PROVIDE (__data_start = .) + *(.data) + .data 0x0000000000800100 0x0 /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/crtatmega328p.o + .data 0x0000000000800100 0x0 /tmp/ccnHW39M.o + .data 0x0000000000800100 0x0 /usr/lib/gcc/avr/8.2.0/avr5/libgcc.a(_exit.o) + *(.data*) + *(.gnu.linkonce.d*) + *(.rodata) + *(.rodata*) + *(.gnu.linkonce.r*) + 0x0000000000800100 . = ALIGN (0x2) + 0x0000000000800100 _edata = . + [!provide] PROVIDE (__data_end = .) + +.bss 0x0000000000800100 0x0 + [!provide] PROVIDE (__bss_start = .) + *(.bss) + .bss 0x0000000000800100 0x0 /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/crtatmega328p.o + .bss 0x0000000000800100 0x0 /tmp/ccnHW39M.o + .bss 0x0000000000800100 0x0 /usr/lib/gcc/avr/8.2.0/avr5/libgcc.a(_exit.o) + *(.bss*) + *(COMMON) + [!provide] PROVIDE (__bss_end = .) + 0x0000000000000124 __data_load_start = LOADADDR (.data) + 0x0000000000000124 __data_load_end = (__data_load_start + SIZEOF (.data)) + +.noinit 0x0000000000800100 0x0 + [!provide] PROVIDE (__noinit_start = .) + *(.noinit*) + [!provide] PROVIDE (__noinit_end = .) + 0x0000000000800100 _end = . + [!provide] PROVIDE (__heap_start = .) + +.eeprom 0x0000000000810000 0x0 + *(.eeprom*) + 0x0000000000810000 __eeprom_end = . + +.fuse + *(.fuse) + *(.lfuse) + *(.hfuse) + *(.efuse) + +.lock + *(.lock*) + +.signature + *(.signature*) + +.stab + *(.stab) + +.stabstr + *(.stabstr) + +.stab.excl + *(.stab.excl) + +.stab.exclstr + *(.stab.exclstr) + +.stab.index + *(.stab.index) + +.stab.indexstr + *(.stab.indexstr) + +.comment + *(.comment) + +.note.gnu.avr.deviceinfo + 0x0000000000000000 0x40 + .note.gnu.avr.deviceinfo + 0x0000000000000000 0x40 /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/crtatmega328p.o + +.note.gnu.build-id + *(.note.gnu.build-id) + +.debug + *(.debug) + +.line + *(.line) + +.debug_srcinfo + *(.debug_srcinfo) + +.debug_sfnames + *(.debug_sfnames) + +.debug_aranges + *(.debug_aranges) + +.debug_pubnames + *(.debug_pubnames) + +.debug_info 0x0000000000000000 0x5f4 + *(.debug_info .gnu.linkonce.wi.*) + .debug_info 0x0000000000000000 0x5f4 /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/crtatmega328p.o + +.debug_abbrev 0x0000000000000000 0x5a2 + *(.debug_abbrev) + .debug_abbrev 0x0000000000000000 0x5a2 /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/crtatmega328p.o + +.debug_line 0x0000000000000000 0x1d + *(.debug_line .debug_line.* .debug_line_end) + .debug_line 0x0000000000000000 0x1d /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/crtatmega328p.o + +.debug_frame + *(.debug_frame) + +.debug_str 0x0000000000000000 0x208 + *(.debug_str) + .debug_str 0x0000000000000000 0x208 /usr/lib/gcc/avr/8.2.0/../../../../avr/lib/avr5/crtatmega328p.o + +.debug_loc + *(.debug_loc) + +.debug_macinfo + *(.debug_macinfo) + +.debug_weaknames + *(.debug_weaknames) + +.debug_funcnames + *(.debug_funcnames) + +.debug_typenames + *(.debug_typenames) + +.debug_varnames + *(.debug_varnames) + +.debug_pubtypes + *(.debug_pubtypes) + +.debug_ranges + *(.debug_ranges) + +.debug_macro + *(.debug_macro) + +.debug_addr + *(.debug_addr) +OUTPUT(blink.elf elf32-avr) +LOAD linker stubs diff --git a/asm/blinkdelay2/avrdasm b/asm/blinkdelay2/avrdasm new file mode 100755 index 0000000..ea0707b --- /dev/null +++ b/asm/blinkdelay2/avrdasm @@ -0,0 +1,2 @@ +#!/bin/sh +avr-objdump -D *.elf diff --git a/asm/blinkdelay2/blink.s b/asm/blinkdelay2/blink.s new file mode 100644 index 0000000..efc9255 --- /dev/null +++ b/asm/blinkdelay2/blink.s @@ -0,0 +1,67 @@ +.include "dat.h" + +vectors: + jmp start + jmp badirq ; IRQ0 + jmp badirq ; IRQ1 + jmp badirq ; PCINT0 + jmp badirq ; PCINT1 + jmp badirq ; PCINT2 + jmp badirq ; Watchdog Timeout + jmp badirq ; Timer2 CompareA + jmp badirq ; Timer2 CompareB + jmp badirq ; Timer2 Overflow + jmp badirq ; Timer1 Capture + jmp badirq ; Timer1 CompareA + jmp badirq ; Timer1 CompareB + jmp badirq ; Timer1 Overflow + jmp badirq ; Timer0 CompareA + jmp badirq ; Timer0 CompareB + jmp badirq ; Timer0 Overflow + jmp badirq ; SPI Transfer Complete + jmp badirq ; USART RX Complete + jmp badirq ; USART UDR Empty + jmp badirq ; USART TX Complete + jmp badirq ; ADC Conversion Complete + jmp badirq ; EEPROM Ready + jmp badirq ; Analog Comparator + jmp badirq ; 2-wire Serial + jmp badirq ; SPM Ready + +start: + eor r1, r1 + out SREG, r1 + ldi r28, 0xff + ldi r29, 0x8 + out SPL, r28 + out SPH, r29 + call main +halt: + rjmp halt + +badirq: + jmp vectors + +.globl main +main: + ldi r16, 1<<DDRB4|1<<DDRB5 + ldi r17, 0<<PORTB4|0<<PORTB5 + out DDRB, r16 + out PORTB, r17 +loop: + /* delay loop */ + ldi r18, 82 + ldi r19, 43 + ldi r20, 0 +l1: + dec r20 + brne l1 + dec r19 + brne l1 + dec r18 + brne l1 + in r17, PORTB + com r17 + andi r17, 1<<PORTB4 + out PORTB, r17 + rjmp loop diff --git a/asm/blinkdelay2/dat.h b/asm/blinkdelay2/dat.h new file mode 100644 index 0000000..5aed9cc --- /dev/null +++ b/asm/blinkdelay2/dat.h @@ -0,0 +1,25 @@ +/* Data Registers */ +.equ PORTB, 0x05 +.equ PORTB0, 0 +.equ PORTB1, 1 +.equ PORTB2, 2 +.equ PORTB3, 3 +.equ PORTB4, 4 +.equ PORTB5, 5 +.equ PORTB6, 6 +.equ PORTB7, 7 +/* Data Direction Registers */ +.equ DDRB, 0x04 +.equ DDRB0, 0 +.equ DDRB1, 1 +.equ DDRB2, 2 +.equ DDRB3, 3 +.equ DDRB4, 4 +.equ DDRB5, 5 +.equ DDRB6, 6 +.equ DDRB7, 7 +/* Stack */ +.equ SPL, 0x3d +.equ SPH, 0x3e +/* Status Register */ +.equ SREG, 0x3f diff --git a/asm/blinkdelay2/link.ld b/asm/blinkdelay2/link.ld new file mode 100644 index 0000000..671a3c6 --- /dev/null +++ b/asm/blinkdelay2/link.ld @@ -0,0 +1,56 @@ +OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr") +OUTPUT_ARCH(avr:5) +MEMORY +{ + text (rx) : ORIGIN = 0, LENGTH = 128K + data (rw!x) : ORIGIN = 0x800060, LENGTH = 64K /* 0xffa0? */ + eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K + fuse (rw!x) : ORIGIN = 0x820000, LENGTH = 1K + lock (rw!x) : ORIGIN = 0x830000, LENGTH = 1K + signature (rw!x) : ORIGIN = 0x840000, LENGTH = 1K + user_signatures (rw!x) : ORIGIN = 0x850000, LENGTH = 1K +} +SECTIONS +{ + .text : + { + *(.vectors) + KEEP(*(.vectors)) + *(.start) + *(.text) + _etext = .; + } >text + .data : + { + *(.data) + . = ALIGN(2); + _edata = . ; + } >data AT>text + .bss ADDR(.data) + SIZEOF (.data) : AT (ADDR (.bss)) + { + *(.bss) + *(.bss*) + *(COMMON) + . = ALIGN(2); + } >data + .eeprom : + { + KEEP(*(.eeprom*)) + } >eeprom + .fuse : + { + KEEP(*(.fuse)) + KEEP(*(.lfuse)) + KEEP(*(.hfuse)) + KEEP(*(.efuse)) + } >fuse + .lock : + { + KEEP(*(.lock*)) + } >lock + .signature : + { + KEEP(*(.signature*)) + } >signature + _end = .; +} diff --git a/asm/blinkdelay2/m328p.ld b/asm/blinkdelay2/m328p.ld new file mode 100644 index 0000000..cc16198 --- /dev/null +++ b/asm/blinkdelay2/m328p.ld @@ -0,0 +1,8 @@ +SECTIONS +{ + . = 0x0; + .text : { *(.text) } + . = 0x8000000; + .data : { *(.data) } + .bss : { *(.bss) } +} diff --git a/asm/blinkdelay2/makefile b/asm/blinkdelay2/makefile new file mode 100644 index 0000000..063bd39 --- /dev/null +++ b/asm/blinkdelay2/makefile @@ -0,0 +1,19 @@ +AS=avr-as +LD=avr-ld +LDSCRIPT=link.ld + +PORT=/dev/ttyACM0 +TARG=blink + +all: build + +build: + $(AS) -mmcu=atmega328p -c -o $(TARG).o $(TARG).s + $(LD) -T$(LDSCRIPT) -o $(TARG).elf $(TARG).o + avr-objcopy -j .text -j .data -O ihex $(TARG).elf $(TARG).hex + +burn: + avrdude -v -p atmega328p -c arduino -P $(PORT) -b 115200 -D -U flash:w:$(TARG).hex + +clean: + rm -f $(TARG).elf $(TARG).o $(TARG).hex diff --git a/asm/dht11/avrdasm b/asm/dht11/avrdasm new file mode 100755 index 0000000..ea0707b --- /dev/null +++ b/asm/dht11/avrdasm @@ -0,0 +1,2 @@ +#!/bin/sh +avr-objdump -D *.elf diff --git a/asm/dht11/blink.s b/asm/dht11/blink.s new file mode 100644 index 0000000..5fe337f --- /dev/null +++ b/asm/dht11/blink.s @@ -0,0 +1,71 @@ +.include "dat.h" + +vectors: + jmp start + jmp badirq ; IRQ0 + jmp badirq ; IRQ1 + jmp badirq ; PCINT0 + jmp badirq ; PCINT1 + jmp badirq ; PCINT2 + jmp badirq ; Watchdog Timeout + jmp badirq ; Timer2 CompareA + jmp badirq ; Timer2 CompareB + jmp badirq ; Timer2 Overflow + jmp badirq ; Timer1 Capture + jmp badirq ; Timer1 CompareA + jmp badirq ; Timer1 CompareB + jmp badirq ; Timer1 Overflow + jmp badirq ; Timer0 CompareA + jmp badirq ; Timer0 CompareB + jmp badirq ; Timer0 Overflow + jmp badirq ; SPI Transfer Complete + jmp badirq ; USART RX Complete + jmp badirq ; USART UDR Empty + jmp badirq ; USART TX Complete + jmp badirq ; ADC Conversion Complete + jmp badirq ; EEPROM Ready + jmp badirq ; Analog Comparator + jmp badirq ; 2-wire Serial + jmp badirq ; SPM Ready + +start: + eor r1, r1 + out SREG, r1 + ldi r28, 0xff + ldi r29, 0x8 + out SPL, r28 + out SPH, r29 + call main +halt: + rjmp halt + +badirq: + jmp vectors + +.globl delayloop +delayloop: + ldi r18, 82 + ldi r19, 43 + ldi r20, 0 +l1: + dec r20 + brne l1 + dec r19 + brne l1 + dec r18 + brne l1 + ret + +.globl main +main: + ldi r16, 1<<DDRB4|1<<DDRB5 + ldi r17, 0<<PORTB4|0<<PORTB5 + out DDRB, r16 + out PORTB, r17 +∞: + call delayloop + in r17, PORTB + com r17 + ;andi r17, 1<<PORTB4 + out PORTB, r17 + rjmp ∞ diff --git a/asm/dht11/dat.h b/asm/dht11/dat.h new file mode 100644 index 0000000..5aed9cc --- /dev/null +++ b/asm/dht11/dat.h @@ -0,0 +1,25 @@ +/* Data Registers */ +.equ PORTB, 0x05 +.equ PORTB0, 0 +.equ PORTB1, 1 +.equ PORTB2, 2 +.equ PORTB3, 3 +.equ PORTB4, 4 +.equ PORTB5, 5 +.equ PORTB6, 6 +.equ PORTB7, 7 +/* Data Direction Registers */ +.equ DDRB, 0x04 +.equ DDRB0, 0 +.equ DDRB1, 1 +.equ DDRB2, 2 +.equ DDRB3, 3 +.equ DDRB4, 4 +.equ DDRB5, 5 +.equ DDRB6, 6 +.equ DDRB7, 7 +/* Stack */ +.equ SPL, 0x3d +.equ SPH, 0x3e +/* Status Register */ +.equ SREG, 0x3f diff --git a/asm/dht11/link.ld b/asm/dht11/link.ld new file mode 100644 index 0000000..0e8fb64 --- /dev/null +++ b/asm/dht11/link.ld @@ -0,0 +1,34 @@ +OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr") +OUTPUT_ARCH(avr:5) +MEMORY +{ + text (rx) : ORIGIN = 0, LENGTH = 32K + data (rw!x) : ORIGIN = 0x800100, LENGTH = 2303 + eeprom (rw!x) : ORIGIN = 0x800900, LENGTH = 1K +} +SECTIONS +{ + .text : + { + *(.vectors) + *(.text) + _etext = .; + } >text + .data : + { + *(.data) + . = ALIGN(2); + _edata = . ; + } >data AT>text + .bss ADDR(.data) + SIZEOF (.data) : AT (ADDR (.bss)) + { + *(.bss) + *(COMMON) + . = ALIGN(2); + } >data + .eeprom : + { + *(.eeprom*) + } >eeprom + _end = .; +} diff --git a/asm/dht11/makefile b/asm/dht11/makefile new file mode 100644 index 0000000..063bd39 --- /dev/null +++ b/asm/dht11/makefile @@ -0,0 +1,19 @@ +AS=avr-as +LD=avr-ld +LDSCRIPT=link.ld + +PORT=/dev/ttyACM0 +TARG=blink + +all: build + +build: + $(AS) -mmcu=atmega328p -c -o $(TARG).o $(TARG).s + $(LD) -T$(LDSCRIPT) -o $(TARG).elf $(TARG).o + avr-objcopy -j .text -j .data -O ihex $(TARG).elf $(TARG).hex + +burn: + avrdude -v -p atmega328p -c arduino -P $(PORT) -b 115200 -D -U flash:w:$(TARG).hex + +clean: + rm -f $(TARG).elf $(TARG).o $(TARG).hex diff --git a/c/blink/blink.c b/c/blink/blink.c new file mode 100644 index 0000000..bb4495a --- /dev/null +++ b/c/blink/blink.c @@ -0,0 +1,23 @@ +#include <avr/io.h>
+#define F_CPU 16000000UL
+#include <util/delay.h>
+
+enum{
+ Delay = 300
+};
+
+int
+main()
+{
+ int led;
+
+ led = 1<<PB1;
+ DDRB |= led;
+
+ for(;;){
+ PORTB ^= led;
+ _delay_ms(Delay);
+ }
+ return 0;
+}
+
diff --git a/c/timer/timer.c b/c/timer/timer.c new file mode 100644 index 0000000..f1231b1 --- /dev/null +++ b/c/timer/timer.c @@ -0,0 +1,23 @@ +#include <avr/io.h>
+
+enum{
+ Dcnt = 62499
+};
+
+int
+main()
+{
+ int led;
+
+ led = 1<<PB1;
+ DDRB |= led;
+ TCCR1B |= 1<<CS12;
+
+ for(;;){
+ if(TCNT1 >= Dcnt){
+ PORTB ^= led;
+ TCNT1 = 0;
+ }
+ }
+}
+
diff --git a/c/timer/timerctc.c b/c/timer/timerctc.c new file mode 100644 index 0000000..7e65b52 --- /dev/null +++ b/c/timer/timerctc.c @@ -0,0 +1,26 @@ +#include <avr/io.h> + +enum{ + Dcnt = 62499 /* 1Hz */ +}; + +int +main() +{ + int led; + + led = 1<<PB1; + DDRB |= led; + TCCR1B |= 1<<CS12; /* f/256 prescaling */ + TCCR1B |= 1<<WGM12; /* ctc op mode */ + OCR1A = Dcnt; /* setup TOP */ + + for(;;){ + /* check if we reached TOP */ + if(TIFR1 & (1<<OCF1A)){ + PORTB ^= led; + TIFR1 = 1<<OCF1A; /* reset the flag */ + } + } +} + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..c1731dd --- /dev/null +++ b/readme.md @@ -0,0 +1,3 @@ +# AVR toys + +Some little AVR microcontroller projects I worked on. |