From fd77ed3244a10f86b633e88d2051276820f257ea Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 10 Feb 2021 11:35:09 +0100 Subject: [PATCH] added comments and removed unnecesary wait --- Microcontrollers/Opdracht 2.2/Debug/Makefile | 125 +++++++++ .../Opdracht 2.2/Debug/Opdracht 2.2.eep | 1 + .../Opdracht 2.2/Debug/Opdracht 2.2.lss | 242 ++++++++++++++++++ .../Opdracht 2.2/Debug/makedep.mk | 6 + .../Opdracht 2.2/Debug/memoryfile.xml | 17 ++ .../Opdracht 2.2.componentinfo.xml | 42 +++ .../Opdracht 2.2/Opdracht 2.2.cproj | 87 +++++++ Microcontrollers/Opdracht 2.2/main.c | 59 +++++ .../opdracht 1.3/Debug/makedep.mk | 6 + 9 files changed, 585 insertions(+) create mode 100644 Microcontrollers/Opdracht 2.2/Debug/Makefile create mode 100644 Microcontrollers/Opdracht 2.2/Debug/Opdracht 2.2.eep create mode 100644 Microcontrollers/Opdracht 2.2/Debug/Opdracht 2.2.lss create mode 100644 Microcontrollers/Opdracht 2.2/Debug/makedep.mk create mode 100644 Microcontrollers/Opdracht 2.2/Debug/memoryfile.xml create mode 100644 Microcontrollers/Opdracht 2.2/Opdracht 2.2.componentinfo.xml create mode 100644 Microcontrollers/Opdracht 2.2/Opdracht 2.2.cproj create mode 100644 Microcontrollers/Opdracht 2.2/main.c create mode 100644 Microcontrollers/opdracht 1.3/Debug/makedep.mk diff --git a/Microcontrollers/Opdracht 2.2/Debug/Makefile b/Microcontrollers/Opdracht 2.2/Debug/Makefile new file mode 100644 index 0000000..828f1e4 --- /dev/null +++ b/Microcontrollers/Opdracht 2.2/Debug/Makefile @@ -0,0 +1,125 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +SHELL := cmd.exe +RM := rm -rf + +USER_OBJS := + +LIBS := +PROJ := + +O_SRCS := +C_SRCS := +S_SRCS := +S_UPPER_SRCS := +OBJ_SRCS := +ASM_SRCS := +PREPROCESSING_SRCS := +OBJS := +OBJS_AS_ARGS := +C_DEPS := +C_DEPS_AS_ARGS := +EXECUTABLES := +OUTPUT_FILE_PATH := +OUTPUT_FILE_PATH_AS_ARGS := +AVR_APP_PATH :=$$$AVR_APP_PATH$$$ +QUOTE := " +ADDITIONAL_DEPENDENCIES:= +OUTPUT_FILE_DEP:= +LIB_DEP:= +LINKER_SCRIPT_DEP:= + +# Every subdirectory with source files must be described here +SUBDIRS := + + +# Add inputs and outputs from these tool invocations to the build variables +C_SRCS += \ +../main.c + + +PREPROCESSING_SRCS += + + +ASM_SRCS += + + +OBJS += \ +main.o + +OBJS_AS_ARGS += \ +main.o + +C_DEPS += \ +main.d + +C_DEPS_AS_ARGS += \ +main.d + +OUTPUT_FILE_PATH +=Opdracht\ 2.2.elf + +OUTPUT_FILE_PATH_AS_ARGS +="Opdracht 2.2.elf" + +ADDITIONAL_DEPENDENCIES:= + +OUTPUT_FILE_DEP:= ./makedep.mk + +LIB_DEP+= + +LINKER_SCRIPT_DEP+= + + +# AVR32/GNU C Compiler +./main.o: .././main.c + @echo Building file: $< + @echo Invoking: XC8 C Compiler : 2.31 + $(QUOTE)C:\Program Files\Microchip\xc8\v2.31\bin\xc8-cc.exe$(QUOTE) -mcpu=ATmega128 -mdfp="C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\xc8" -c -x c -funsigned-char -funsigned-bitfields -mext=cci -D__ATmega128__ -DDEBUG -Og -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" + @echo Finished building: $< + + + + + +# AVR32/GNU Preprocessing Assembler + + + +# AVR32/GNU Assembler + + + + +ifneq ($(MAKECMDGOALS),clean) +ifneq ($(strip $(C_DEPS)),) +-include $(C_DEPS) +endif +endif + +# Add inputs and outputs from these tool invocations to the build variables + +# All Target +all: $(OUTPUT_FILE_PATH) $(ADDITIONAL_DEPENDENCIES) + +$(OUTPUT_FILE_PATH): $(OBJS) $(USER_OBJS) $(OUTPUT_FILE_DEP) $(LIB_DEP) $(LINKER_SCRIPT_DEP) + @echo Building target: $@ + @echo Invoking: XC8 C Linker : 2.31 + $(QUOTE)C:\Program Files\Microchip\xc8\v2.31\bin\xc8-cc.exe$(QUOTE) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -mcpu=ATmega128 -mdfp="C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\xc8" -Wl,-Map="Opdracht 2.2.map" -funsigned-char -funsigned-bitfields -Wl,--start-group -Wl,-lm -Wl,--end-group -Wl,--gc-sections -Og -ffunction-sections -fdata-sections -fpack-struct -fshort-enums --memorysummary,memoryfile.xml + @echo Finished building target: $@ + "C:\Program Files\Microchip\xc8\v2.31\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "Opdracht 2.2.elf" "Opdracht 2.2.hex" + "C:\Program Files\Microchip\xc8\v2.31\bin\avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "Opdracht 2.2.elf" "Opdracht 2.2.eep" || exit 0 + "C:\Program Files\Microchip\xc8\v2.31\bin\avr-objdump.exe" -h -S "Opdracht 2.2.elf" > "Opdracht 2.2.lss" + + + + + + + +# Other Targets +clean: + -$(RM) $(OBJS_AS_ARGS) $(EXECUTABLES) + -$(RM) $(C_DEPS_AS_ARGS) + rm -rf "Opdracht 2.2.elf" "Opdracht 2.2.hex" "Opdracht 2.2.eep" "Opdracht 2.2.map" "Opdracht 2.2.usersignatures" "Opdracht 2.2.a" "Opdracht 2.2.lss" + \ No newline at end of file diff --git a/Microcontrollers/Opdracht 2.2/Debug/Opdracht 2.2.eep b/Microcontrollers/Opdracht 2.2/Debug/Opdracht 2.2.eep new file mode 100644 index 0000000..7c166a1 --- /dev/null +++ b/Microcontrollers/Opdracht 2.2/Debug/Opdracht 2.2.eep @@ -0,0 +1 @@ +:00000001FF diff --git a/Microcontrollers/Opdracht 2.2/Debug/Opdracht 2.2.lss b/Microcontrollers/Opdracht 2.2/Debug/Opdracht 2.2.lss new file mode 100644 index 0000000..25acebe --- /dev/null +++ b/Microcontrollers/Opdracht 2.2/Debug/Opdracht 2.2.lss @@ -0,0 +1,242 @@ + +Opdracht 2.2.elf: file format elf32-avr + +Sections: +Idx Name Size VMA LMA File off Algn + 0 .data 00000000 00800100 00800100 00000192 2**0 + ALLOC, LOAD, DATA + 1 .text 000000a4 00000000 00000000 00000054 2**1 + CONTENTS, ALLOC, LOAD, READONLY, CODE + 2 .comment 0000002f 00000000 00000000 00000192 2**0 + CONTENTS, READONLY + 3 .debug_aranges 00000038 00000000 00000000 000001c1 2**0 + CONTENTS, READONLY, DEBUGGING + 4 .debug_info 00000b2a 00000000 00000000 000001f9 2**0 + CONTENTS, READONLY, DEBUGGING + 5 .debug_abbrev 00000830 00000000 00000000 00000d23 2**0 + CONTENTS, READONLY, DEBUGGING + 6 .debug_line 000002e4 00000000 00000000 00001553 2**0 + CONTENTS, READONLY, DEBUGGING + 7 .debug_frame 00000074 00000000 00000000 00001838 2**2 + CONTENTS, READONLY, DEBUGGING + 8 .debug_str 0000027d 00000000 00000000 000018ac 2**0 + CONTENTS, READONLY, DEBUGGING + 9 .debug_loc 000000e2 00000000 00000000 00001b29 2**0 + CONTENTS, READONLY, DEBUGGING + 10 .debug_ranges 00000028 00000000 00000000 00001c0b 2**0 + CONTENTS, READONLY, DEBUGGING + 11 .text 00000004 0000013a 0000013a 0000018e 2**1 + CONTENTS, ALLOC, LOAD, READONLY, CODE + 12 .note.gnu.avr.deviceinfo 0000003c 00000000 00000000 00001c34 2**2 + CONTENTS, READONLY, DEBUGGING + 13 .text.wait 0000001e 0000011c 0000011c 00000170 2**1 + CONTENTS, ALLOC, LOAD, READONLY, CODE + 14 .text.__vector_2 00000028 000000a4 000000a4 000000f8 2**1 + CONTENTS, ALLOC, LOAD, READONLY, CODE + 15 .text.__vector_3 00000028 000000cc 000000cc 00000120 2**1 + CONTENTS, ALLOC, LOAD, READONLY, CODE + 16 .text.main 00000028 000000f4 000000f4 00000148 2**1 + CONTENTS, ALLOC, LOAD, READONLY, CODE + +Disassembly of section .text: + +00000000 <__vectors>: + 0: 0c 94 46 00 jmp 0x8c ; 0x8c <__ctors_end> + 4: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 8: 0c 94 52 00 jmp 0xa4 ; 0xa4 <_etext> + c: 0c 94 66 00 jmp 0xcc ; 0xcc <__vector_3> + 10: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 14: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 18: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 1c: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 20: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 24: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 28: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 2c: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 30: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 34: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 38: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 3c: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 40: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 44: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 48: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 4c: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 50: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 54: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 58: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 5c: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 60: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 64: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 68: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 6c: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 70: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 74: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 78: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 7c: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 80: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 84: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + 88: 0c 94 9d 00 jmp 0x13a ; 0x13a <__bad_interrupt> + +0000008c <__ctors_end>: + 8c: 11 24 eor r1, r1 + 8e: 1f be out 0x3f, r1 ; 63 + 90: cf ef ldi r28, 0xFF ; 255 + 92: d0 e1 ldi r29, 0x10 ; 16 + 94: de bf out 0x3e, r29 ; 62 + 96: cd bf out 0x3d, r28 ; 61 + 98: 0e 94 7a 00 call 0xf4 ; 0xf4
+ 9c: 0c 94 50 00 jmp 0xa0 ; 0xa0 <_exit> + +000000a0 <_exit>: + a0: f8 94 cli + +000000a2 <__stop_program>: + a2: ff cf rjmp .-2 ; 0xa2 <__stop_program> + +Disassembly of section .text: + +0000013a <__bad_interrupt>: + 13a: 0c 94 00 00 jmp 0 ; 0x0 <__TEXT_REGION_ORIGIN__> + +Disassembly of section .text.wait: + +0000011c : +#include +#include +#include + +void wait( int ms ) { + for (int i=0; i + #else + //round up by default + __ticks_dc = (uint32_t)(ceil(fabs(__tmp))); + #endif + + __builtin_avr_delay_cycles(__ticks_dc); + 122: e3 ec ldi r30, 0xC3 ; 195 + 124: f9 e0 ldi r31, 0x09 ; 9 + 126: 31 97 sbiw r30, 0x01 ; 1 + 128: f1 f7 brne .-4 ; 0x126 + 12a: 00 c0 rjmp .+0 ; 0x12c + 12c: 00 00 nop + 12e: 2f 5f subi r18, 0xFF ; 255 + 130: 3f 4f sbci r19, 0xFF ; 255 + 132: 28 17 cp r18, r24 + 134: 39 07 cpc r19, r25 + 136: ac f3 brlt .-22 ; 0x122 + _delay_ms( 1 ); // library function (max 30 ms at 8MHz) + } +} + 138: 08 95 ret + +Disassembly of section .text.__vector_2: + +000000a4 <__vector_2>: + +ISR( INT1_vect ) { + a4: 1f 92 push r1 + a6: 0f 92 push r0 + a8: 0f b6 in r0, 0x3f ; 63 + aa: 0f 92 push r0 + ac: 11 24 eor r1, r1 + ae: 8f 93 push r24 + if (PORTC == 0b10000000) + b0: 85 b3 in r24, 0x15 ; 21 + b2: 80 38 cpi r24, 0x80 ; 128 + b4: 11 f4 brne .+4 ; 0xba <__vector_2+0x16> + { + PORTC == 0b00000001; + b6: 85 b3 in r24, 0x15 ; 21 + b8: 03 c0 rjmp .+6 ; 0xc0 <__vector_2+0x1c> + } else { + PORTC = PORTC << 1; + ba: 85 b3 in r24, 0x15 ; 21 + bc: 88 0f add r24, r24 + be: 85 bb out 0x15, r24 ; 21 + } + + +} + c0: 8f 91 pop r24 + c2: 0f 90 pop r0 + c4: 0f be out 0x3f, r0 ; 63 + c6: 0f 90 pop r0 + c8: 1f 90 pop r1 + ca: 18 95 reti + +Disassembly of section .text.__vector_3: + +000000cc <__vector_3>: + +ISR( INT2_vect ) { + cc: 1f 92 push r1 + ce: 0f 92 push r0 + d0: 0f b6 in r0, 0x3f ; 63 + d2: 0f 92 push r0 + d4: 11 24 eor r1, r1 + d6: 8f 93 push r24 + if (PORTC == 0b00000001) + d8: 85 b3 in r24, 0x15 ; 21 + da: 81 30 cpi r24, 0x01 ; 1 + dc: 11 f4 brne .+4 ; 0xe2 <__vector_3+0x16> + { + PORTC = 0b10000000; + de: 80 e8 ldi r24, 0x80 ; 128 + e0: 85 bb out 0x15, r24 ; 21 + } + PORTC = PORTC >> 1; + e2: 85 b3 in r24, 0x15 ; 21 + e4: 86 95 lsr r24 + e6: 85 bb out 0x15, r24 ; 21 +} + e8: 8f 91 pop r24 + ea: 0f 90 pop r0 + ec: 0f be out 0x3f, r0 ; 63 + ee: 0f 90 pop r0 + f0: 1f 90 pop r1 + f2: 18 95 reti + +Disassembly of section .text.main: + +000000f4
: +int main(void) +{ + /* Replace with your application code */ + + // Init I/O + DDRD = 0xF0; // PORTD (7:4) is output, (3:0) is input + f4: 80 ef ldi r24, 0xF0 ; 240 + f6: 81 bb out 0x11, r24 ; 17 + DDRC = 0xFF; + f8: 8f ef ldi r24, 0xFF ; 255 + fa: 84 bb out 0x14, r24 ; 20 + + // Init Interrupt hardware + EICRA |= 0x2C; // INT2 falling edge, INT1 rising edge + fc: ea e6 ldi r30, 0x6A ; 106 + fe: f0 e0 ldi r31, 0x00 ; 0 + 100: 80 81 ld r24, Z + 102: 8c 62 ori r24, 0x2C ; 44 + 104: 80 83 st Z, r24 + EIMSK |= 0x06; // Enable INT2 & INT1 + 106: 89 b7 in r24, 0x39 ; 57 + 108: 86 60 ori r24, 0x06 ; 6 + 10a: 89 bf out 0x39, r24 ; 57 + + PORTC = 0x01; + 10c: 81 e0 ldi r24, 0x01 ; 1 + 10e: 85 bb out 0x15, r24 ; 21 + + sei(); + 110: 78 94 sei + + while (1) + { + wait(500); + 112: 84 ef ldi r24, 0xF4 ; 244 + 114: 91 e0 ldi r25, 0x01 ; 1 + 116: 0e 94 8e 00 call 0x11c ; 0x11c + 11a: fb cf rjmp .-10 ; 0x112 diff --git a/Microcontrollers/Opdracht 2.2/Debug/makedep.mk b/Microcontrollers/Opdracht 2.2/Debug/makedep.mk new file mode 100644 index 0000000..6a14fde --- /dev/null +++ b/Microcontrollers/Opdracht 2.2/Debug/makedep.mk @@ -0,0 +1,6 @@ +################################################################################ +# Automatically-generated file. Do not edit or delete the file +################################################################################ + +main.c + diff --git a/Microcontrollers/Opdracht 2.2/Debug/memoryfile.xml b/Microcontrollers/Opdracht 2.2/Debug/memoryfile.xml new file mode 100644 index 0000000..d62a7ce --- /dev/null +++ b/Microcontrollers/Opdracht 2.2/Debug/memoryfile.xml @@ -0,0 +1,17 @@ + + + + + bytes + 131072 + 318 + 130754 + + + bytes + 4096 + 0 + 4096 + + + diff --git a/Microcontrollers/Opdracht 2.2/Opdracht 2.2.componentinfo.xml b/Microcontrollers/Opdracht 2.2/Opdracht 2.2.componentinfo.xml new file mode 100644 index 0000000..bbcc667 --- /dev/null +++ b/Microcontrollers/Opdracht 2.2/Opdracht 2.2.componentinfo.xml @@ -0,0 +1,42 @@ + + + + + + + Device + Startup + + + Atmel + 1.6.0 + C:/Program Files (x86)\Atmel\Studio\7.0\Packs + + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\xc8\avr\include\avr\iom128.h + + header + XC + JdJ7J9I/SJh965SEyyyVYw== + + xc8/avr/include/avr/iom128.h + + + + + ATmega_DFP + C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.6.364/Atmel.ATmega_DFP.pdsc + 1.6.364 + true + ATmega128 + + + + Resolved + Fixed + true + + + \ No newline at end of file diff --git a/Microcontrollers/Opdracht 2.2/Opdracht 2.2.cproj b/Microcontrollers/Opdracht 2.2/Opdracht 2.2.cproj new file mode 100644 index 0000000..4052ff0 --- /dev/null +++ b/Microcontrollers/Opdracht 2.2/Opdracht 2.2.cproj @@ -0,0 +1,87 @@ + + + + 2.0 + 7.0 + com.microchip.xc8 + {7328e66f-4181-4553-9542-da5cc2a74a4e} + ATmega128 + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + Opdracht 2.2 + Opdracht 2.2 + Opdracht 2.2 + XC8_2.31 + true + false + true + true + + + true + + 2 + 0 + 0 + + + + + + True + True + True + + + (%24DeviceMacro) + NDEBUG + + + Optimize for size (-Os) + True + True + True + + + libm + + + + + + + + + True + True + + + (%24DeviceMacro) + DEBUG + + + Optimize debugging experience (-Og) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + + + + \ No newline at end of file diff --git a/Microcontrollers/Opdracht 2.2/main.c b/Microcontrollers/Opdracht 2.2/main.c new file mode 100644 index 0000000..56f878f --- /dev/null +++ b/Microcontrollers/Opdracht 2.2/main.c @@ -0,0 +1,59 @@ +/* + * Opdracht 2.2.c + * + * Created: 10-2-2021 10:58:13 + * Author : Sem + */ +#define F_CPU 10e6 +#include +#include +#include + +void wait( int ms ) { + for (int i=0; i> 1; +} + + +int main(void) +{ + /* Replace with your application code */ + + // Init I/O + DDRD = 0xF0; // PORTD (7:4) is output, (3:0) is input + DDRC = 0xFF; + + // Init Interrupt hardware + EICRA |= 0x2C; // INT2 falling edge, INT1 rising edge + EIMSK |= 0x06; // Enable INT2 & INT1 + + PORTC = 0x01; + + sei(); + + while (1) + { + wait(500); + } +} + diff --git a/Microcontrollers/opdracht 1.3/Debug/makedep.mk b/Microcontrollers/opdracht 1.3/Debug/makedep.mk new file mode 100644 index 0000000..6a14fde --- /dev/null +++ b/Microcontrollers/opdracht 1.3/Debug/makedep.mk @@ -0,0 +1,6 @@ +################################################################################ +# Automatically-generated file. Do not edit or delete the file +################################################################################ + +main.c +