[ADD] reading echo in oscilloscope

This commit is contained in:
Sem van der Hoeven
2021-03-17 12:02:02 +01:00
parent 547a4f7053
commit c8839a017d
12 changed files with 856 additions and 6 deletions

View File

@@ -29,7 +29,9 @@ Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "opdracht 2.4", "opdracht 2.
EndProject
Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "opdracht 3.3", "opdracht 3.3\opdracht 3.3.cproj", "{985D5C75-F61E-49F1-A532-66A1E6141552}"
EndProject
Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "opdracht 4.1", "opdracht 4.1\opdracht 4.1.cproj", "{2432E6BF-DA1E-4668-99BB-59FEA1F5B8A2}"
Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "opdracht 4.b1", "opdracht 4.b1\opdracht 4.b1.cproj", "{314FE495-A311-499D-B63E-4B5E7B7F2054}"
EndProject
Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "ultrasonicSensor", "ultrasonicSensor\ultrasonicSensor.cproj", "{26DA64DE-DD48-4718-94B5-81F9EC5D4B33}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -89,10 +91,14 @@ Global
{985D5C75-F61E-49F1-A532-66A1E6141552}.Debug|AVR.Build.0 = Debug|AVR
{985D5C75-F61E-49F1-A532-66A1E6141552}.Release|AVR.ActiveCfg = Release|AVR
{985D5C75-F61E-49F1-A532-66A1E6141552}.Release|AVR.Build.0 = Release|AVR
{2432E6BF-DA1E-4668-99BB-59FEA1F5B8A2}.Debug|AVR.ActiveCfg = Debug|AVR
{2432E6BF-DA1E-4668-99BB-59FEA1F5B8A2}.Debug|AVR.Build.0 = Debug|AVR
{2432E6BF-DA1E-4668-99BB-59FEA1F5B8A2}.Release|AVR.ActiveCfg = Release|AVR
{2432E6BF-DA1E-4668-99BB-59FEA1F5B8A2}.Release|AVR.Build.0 = Release|AVR
{314FE495-A311-499D-B63E-4B5E7B7F2054}.Debug|AVR.ActiveCfg = Debug|AVR
{314FE495-A311-499D-B63E-4B5E7B7F2054}.Debug|AVR.Build.0 = Debug|AVR
{314FE495-A311-499D-B63E-4B5E7B7F2054}.Release|AVR.ActiveCfg = Release|AVR
{314FE495-A311-499D-B63E-4B5E7B7F2054}.Release|AVR.Build.0 = Release|AVR
{26DA64DE-DD48-4718-94B5-81F9EC5D4B33}.Debug|AVR.ActiveCfg = Debug|AVR
{26DA64DE-DD48-4718-94B5-81F9EC5D4B33}.Debug|AVR.Build.0 = Debug|AVR
{26DA64DE-DD48-4718-94B5-81F9EC5D4B33}.Release|AVR.ActiveCfg = Release|AVR
{26DA64DE-DD48-4718-94B5-81F9EC5D4B33}.Release|AVR.Build.0 = Release|AVR
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -4,7 +4,7 @@
<SchemaVersion>2.0</SchemaVersion>
<ProjectVersion>7.0</ProjectVersion>
<ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
<ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
<ProjectGuid>{314fe495-a311-499d-b63e-4b5e7b7f2054}</ProjectGuid>
<avrdevice>ATmega128</avrdevice>
<avrdeviceseries>none</avrdeviceseries>
<OutputType>Executable</OutputType>
@@ -15,6 +15,19 @@
<AssemblyName>opdracht 4.b1</AssemblyName>
<Name>opdracht 4.b1</Name>
<RootNamespace>opdracht 4.b1</RootNamespace>
<ToolchainFlavour>Native</ToolchainFlavour>
<KeepTimersRunning>true</KeepTimersRunning>
<OverrideVtor>false</OverrideVtor>
<CacheFlash>true</CacheFlash>
<ProgFlashFromRam>true</ProgFlashFromRam>
<RamSnippetAddress />
<UncachedRange />
<preserveEEPROM>true</preserveEEPROM>
<OverrideVtorValue />
<BootSegment>2</BootSegment>
<ResetRule>0</ResetRule>
<eraseonlaunchrule>0</eraseonlaunchrule>
<EraseKey />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<ToolchainSettings>
@@ -24,5 +37,10 @@
<ToolchainSettings>
</ToolchainSettings>
</PropertyGroup>
<ItemGroup>
<Compile Include="main.c">
<SubType>compile</SubType>
</Compile>
</ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
</Project>

View File

@@ -0,0 +1,139 @@
################################################################################
# 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 += \
../lcd_control.c \
../main.c
PREPROCESSING_SRCS +=
ASM_SRCS +=
OBJS += \
lcd_control.o \
main.o
OBJS_AS_ARGS += \
lcd_control.o \
main.o
C_DEPS += \
lcd_control.d \
main.d
C_DEPS_AS_ARGS += \
lcd_control.d \
main.d
OUTPUT_FILE_PATH +=ultrasonicSensor.elf
OUTPUT_FILE_PATH_AS_ARGS +=ultrasonicSensor.elf
ADDITIONAL_DEPENDENCIES:=
OUTPUT_FILE_DEP:= ./makedep.mk
LIB_DEP+=
LINKER_SCRIPT_DEP+=
# AVR32/GNU C Compiler
./lcd_control.o: .././lcd_control.c
@echo Building file: $<
@echo Invoking: AVR/GNU C Compiler : 5.4.0
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\include" -Og -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -mrelax -g2 -Wall -mmcu=atmega128 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega128" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<"
@echo Finished building: $<
./main.o: .././main.c
@echo Building file: $<
@echo Invoking: AVR/GNU C Compiler : 5.4.0
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\include" -Og -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -mrelax -g2 -Wall -mmcu=atmega128 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega128" -c -std=gnu99 -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: AVR/GNU Linker : 5.4.0
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -Wl,-Map="ultrasonicSensor.map" -Wl,--start-group -Wl,-lm -Wl,--end-group -Wl,--gc-sections -mrelax -mmcu=atmega128 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega128"
@echo Finished building target: $@
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "ultrasonicSensor.elf" "ultrasonicSensor.hex"
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "ultrasonicSensor.elf" "ultrasonicSensor.eep" || exit 0
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "ultrasonicSensor.elf" > "ultrasonicSensor.lss"
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "ultrasonicSensor.elf" "ultrasonicSensor.srec"
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-size.exe" "ultrasonicSensor.elf"
# Other Targets
clean:
-$(RM) $(OBJS_AS_ARGS) $(EXECUTABLES)
-$(RM) $(C_DEPS_AS_ARGS)
rm -rf "ultrasonicSensor.elf" "ultrasonicSensor.a" "ultrasonicSensor.hex" "ultrasonicSensor.lss" "ultrasonicSensor.eep" "ultrasonicSensor.map" "ultrasonicSensor.srec" "ultrasonicSensor.usersignatures"

View File

@@ -0,0 +1,8 @@
################################################################################
# Automatically-generated file. Do not edit or delete the file
################################################################################
lcd_control.c
main.c

View File

@@ -0,0 +1 @@
:00000001FF

View File

@@ -0,0 +1,231 @@
ultrasonicSensor.elf: file format elf32-avr
Sections:
Idx Name Size VMA LMA File off Algn
0 .data 00000000 00800100 00800100 00000166 2**0
CONTENTS, ALLOC, LOAD, DATA
1 .text 00000112 00000000 00000000 00000054 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE
2 .comment 00000030 00000000 00000000 00000166 2**0
CONTENTS, READONLY
3 .note.gnu.avr.deviceinfo 0000003c 00000000 00000000 00000198 2**2
CONTENTS, READONLY
4 .debug_aranges 00000030 00000000 00000000 000001d4 2**0
CONTENTS, READONLY, DEBUGGING
5 .debug_info 000009ad 00000000 00000000 00000204 2**0
CONTENTS, READONLY, DEBUGGING
6 .debug_abbrev 0000084e 00000000 00000000 00000bb1 2**0
CONTENTS, READONLY, DEBUGGING
7 .debug_line 0000030d 00000000 00000000 000013ff 2**0
CONTENTS, READONLY, DEBUGGING
8 .debug_frame 00000044 00000000 00000000 0000170c 2**2
CONTENTS, READONLY, DEBUGGING
9 .debug_str 0000043a 00000000 00000000 00001750 2**0
CONTENTS, READONLY, DEBUGGING
10 .debug_loc 000000d2 00000000 00000000 00001b8a 2**0
CONTENTS, READONLY, DEBUGGING
11 .debug_ranges 00000020 00000000 00000000 00001c5c 2**0
CONTENTS, READONLY, DEBUGGING
Disassembly of section .text:
00000000 <__vectors>:
0: 45 c0 rjmp .+138 ; 0x8c <__ctors_end>
2: 00 00 nop
4: 58 c0 rjmp .+176 ; 0xb6 <__bad_interrupt>
6: 00 00 nop
8: 56 c0 rjmp .+172 ; 0xb6 <__bad_interrupt>
a: 00 00 nop
c: 54 c0 rjmp .+168 ; 0xb6 <__bad_interrupt>
e: 00 00 nop
10: 52 c0 rjmp .+164 ; 0xb6 <__bad_interrupt>
12: 00 00 nop
14: 50 c0 rjmp .+160 ; 0xb6 <__bad_interrupt>
16: 00 00 nop
18: 4e c0 rjmp .+156 ; 0xb6 <__bad_interrupt>
1a: 00 00 nop
1c: 4c c0 rjmp .+152 ; 0xb6 <__bad_interrupt>
1e: 00 00 nop
20: 4a c0 rjmp .+148 ; 0xb6 <__bad_interrupt>
22: 00 00 nop
24: 48 c0 rjmp .+144 ; 0xb6 <__bad_interrupt>
26: 00 00 nop
28: 46 c0 rjmp .+140 ; 0xb6 <__bad_interrupt>
2a: 00 00 nop
2c: 44 c0 rjmp .+136 ; 0xb6 <__bad_interrupt>
2e: 00 00 nop
30: 42 c0 rjmp .+132 ; 0xb6 <__bad_interrupt>
32: 00 00 nop
34: 40 c0 rjmp .+128 ; 0xb6 <__bad_interrupt>
36: 00 00 nop
38: 3e c0 rjmp .+124 ; 0xb6 <__bad_interrupt>
3a: 00 00 nop
3c: 3c c0 rjmp .+120 ; 0xb6 <__bad_interrupt>
3e: 00 00 nop
40: 3a c0 rjmp .+116 ; 0xb6 <__bad_interrupt>
42: 00 00 nop
44: 38 c0 rjmp .+112 ; 0xb6 <__bad_interrupt>
46: 00 00 nop
48: 36 c0 rjmp .+108 ; 0xb6 <__bad_interrupt>
4a: 00 00 nop
4c: 34 c0 rjmp .+104 ; 0xb6 <__bad_interrupt>
4e: 00 00 nop
50: 32 c0 rjmp .+100 ; 0xb6 <__bad_interrupt>
52: 00 00 nop
54: 30 c0 rjmp .+96 ; 0xb6 <__bad_interrupt>
56: 00 00 nop
58: 2e c0 rjmp .+92 ; 0xb6 <__bad_interrupt>
5a: 00 00 nop
5c: 2c c0 rjmp .+88 ; 0xb6 <__bad_interrupt>
5e: 00 00 nop
60: 2a c0 rjmp .+84 ; 0xb6 <__bad_interrupt>
62: 00 00 nop
64: 28 c0 rjmp .+80 ; 0xb6 <__bad_interrupt>
66: 00 00 nop
68: 26 c0 rjmp .+76 ; 0xb6 <__bad_interrupt>
6a: 00 00 nop
6c: 24 c0 rjmp .+72 ; 0xb6 <__bad_interrupt>
6e: 00 00 nop
70: 22 c0 rjmp .+68 ; 0xb6 <__bad_interrupt>
72: 00 00 nop
74: 20 c0 rjmp .+64 ; 0xb6 <__bad_interrupt>
76: 00 00 nop
78: 1e c0 rjmp .+60 ; 0xb6 <__bad_interrupt>
7a: 00 00 nop
7c: 1c c0 rjmp .+56 ; 0xb6 <__bad_interrupt>
7e: 00 00 nop
80: 1a c0 rjmp .+52 ; 0xb6 <__bad_interrupt>
82: 00 00 nop
84: 18 c0 rjmp .+48 ; 0xb6 <__bad_interrupt>
86: 00 00 nop
88: 16 c0 rjmp .+44 ; 0xb6 <__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
00000098 <__do_copy_data>:
98: 11 e0 ldi r17, 0x01 ; 1
9a: a0 e0 ldi r26, 0x00 ; 0
9c: b1 e0 ldi r27, 0x01 ; 1
9e: e2 e1 ldi r30, 0x12 ; 18
a0: f1 e0 ldi r31, 0x01 ; 1
a2: 00 e0 ldi r16, 0x00 ; 0
a4: 0b bf out 0x3b, r16 ; 59
a6: 02 c0 rjmp .+4 ; 0xac <__do_copy_data+0x14>
a8: 07 90 elpm r0, Z+
aa: 0d 92 st X+, r0
ac: a0 30 cpi r26, 0x00 ; 0
ae: b1 07 cpc r27, r17
b0: d9 f7 brne .-10 ; 0xa8 <__do_copy_data+0x10>
b2: 1e d0 rcall .+60 ; 0xf0 <main>
b4: 2c c0 rjmp .+88 ; 0x10e <_exit>
000000b6 <__bad_interrupt>:
b6: a4 cf rjmp .-184 ; 0x0 <__vectors>
000000b8 <wait_us>:
#include "lcd_control.h"
void wait_us(unsigned int us)
{
for(int i = 0; i < us; i++)
b8: 20 e0 ldi r18, 0x00 ; 0
ba: 30 e0 ldi r19, 0x00 ; 0
bc: 06 c0 rjmp .+12 ; 0xca <wait_us+0x12>
#else
//round up by default
__ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
#endif
__builtin_avr_delay_cycles(__ticks_dc);
be: 46 e0 ldi r20, 0x06 ; 6
c0: 4a 95 dec r20
c2: f1 f7 brne .-4 ; 0xc0 <wait_us+0x8>
c4: 00 c0 rjmp .+0 ; 0xc6 <wait_us+0xe>
c6: 2f 5f subi r18, 0xFF ; 255
c8: 3f 4f sbci r19, 0xFF ; 255
ca: 28 17 cp r18, r24
cc: 39 07 cpc r19, r25
ce: b8 f3 brcs .-18 ; 0xbe <wait_us+0x6>
{
_delay_us(1);
}
}
d0: 08 95 ret
000000d2 <wait_ms>:
void wait_ms(unsigned int ms)
{
for(int i = 0; i < ms; i++)
d2: 20 e0 ldi r18, 0x00 ; 0
d4: 30 e0 ldi r19, 0x00 ; 0
d6: 08 c0 rjmp .+16 ; 0xe8 <wait_ms+0x16>
#else
//round up by default
__ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
#endif
__builtin_avr_delay_cycles(__ticks_dc);
d8: e7 e8 ldi r30, 0x87 ; 135
da: f3 e1 ldi r31, 0x13 ; 19
dc: 31 97 sbiw r30, 0x01 ; 1
de: f1 f7 brne .-4 ; 0xdc <wait_ms+0xa>
e0: 00 c0 rjmp .+0 ; 0xe2 <wait_ms+0x10>
e2: 00 00 nop
e4: 2f 5f subi r18, 0xFF ; 255
e6: 3f 4f sbci r19, 0xFF ; 255
e8: 28 17 cp r18, r24
ea: 39 07 cpc r19, r25
ec: a8 f3 brcs .-22 ; 0xd8 <wait_ms+0x6>
{
_delay_ms(1);
}
}
ee: 08 95 ret
000000f0 <main>:
int main(void)
{
DDRG = 0x01; // port g pin 0 on output, 1 on input. 0 is trig, 1 is echo
f0: 81 e0 ldi r24, 0x01 ; 1
f2: 80 93 64 00 sts 0x0064, r24 ; 0x800064 <__TEXT_REGION_LENGTH__+0x7e0064>
/* Replace with your application code */
while (1)
{
PORTG = 0x00; // 10 us low pulse
f6: c5 e6 ldi r28, 0x65 ; 101
f8: d0 e0 ldi r29, 0x00 ; 0
fa: 18 82 st Y, r1
wait_us(10);
fc: 8a e0 ldi r24, 0x0A ; 10
fe: 90 e0 ldi r25, 0x00 ; 0
100: db df rcall .-74 ; 0xb8 <wait_us>
PORTG = 0x01;
102: 81 e0 ldi r24, 0x01 ; 1
104: 88 83 st Y, r24
wait_ms(100);
106: 84 e6 ldi r24, 0x64 ; 100
108: 90 e0 ldi r25, 0x00 ; 0
10a: e3 df rcall .-58 ; 0xd2 <wait_ms>
10c: f4 cf rjmp .-24 ; 0xf6 <main+0x6>
0000010e <_exit>:
10e: f8 94 cli
00000110 <__stop_program>:
110: ff cf rjmp .-2 ; 0x110 <__stop_program>

View File

@@ -0,0 +1,20 @@
S0180000756C747261736F6E696353656E736F722E737265634E
S113000045C0000058C0000056C0000054C00000A5
S113001052C0000050C000004EC000004CC00000A0
S11300204AC0000048C0000046C0000044C00000B0
S113003042C0000040C000003EC000003CC00000C0
S11300403AC0000038C0000036C0000034C00000D0
S113005032C0000030C000002EC000002CC00000E0
S11300602AC0000028C0000026C0000024C00000F0
S113007022C0000020C000001EC000001CC0000000
S11300801AC0000018C0000016C0000011241FBED2
S1130090CFEFD0E1DEBFCDBF11E0A0E0B1E0E2E1FF
S11300A0F1E000E00BBF02C007900D92A030B10751
S11300B0D9F71ED02CC0A4CF20E030E006C046E023
S11300C04A95F1F700C02F5F3F4F28173907B8F35F
S11300D0089520E030E008C0E7E8F3E13197F1F754
S11300E000C000002F5F3F4F28173907A8F3089579
S11300F081E080936400C5E6D0E018828AE090E055
S1130100DBDF81E0888384E690E0E3DFF4CFF894DA
S1050110FFCF1B
S9030000FC

View File

@@ -0,0 +1,133 @@
/*
* lcd_controlc.c
*
* Created: 24-2-2021 11:55:12
* Author: Sem
*/
#define F_CPU 10e6
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include <stdio.h>
#include "lcd_control.h"
void _delay_ms(double __ms);
void lcd_clear() {
lcd_write_command (0x01); //Leeg display
_delay_ms(2);
lcd_write_command (0x80); //Cursor terug naar start
}
void lcd_strobe_lcd_e(void) {
sbi_porta(LCD_E); // E high
_delay_ms(1);
cbi_porta(LCD_E); // E low
_delay_ms(1);
}
void sbi_portc(int index){
PORTC |= (1<<index);
}
void cbi_portc(int index){
PORTC &= ~(1<<index);
}
void sbi_porta(int index){
PORTA |= (1<<index);
}
void cbi_porta(int index){
PORTA &= ~(1<<index);
}
void init_4bits_mode(void) {
// PORTC output mode and all low (also E and RS pin)
// Init I/O
DDRC = 0xFF; // PORTD(7) output, PORTD(6:0) input
PORTC = 0xFF;
DDRD = 0xFF;
DDRA = 0xFF;
PORTC = 0x00;
PORTA = 0x00;
PORTC = 0x20; // function for 4-bit 1 row
lcd_strobe_lcd_e();
PORTC = 0x20; // function high nibble 4-bit 2 row
lcd_strobe_lcd_e();
PORTC = 0x80; // function low nibble 4-bit 2 row
lcd_strobe_lcd_e();
PORTC = 0x00; // function high nibble turn on visible blinking-block cursor
lcd_strobe_lcd_e();
PORTC = 0xF0; // function low nibble turn on visible blinking-block cursor
lcd_strobe_lcd_e();
PORTC = 0x00; // Entry mode set high nibble
lcd_strobe_lcd_e();
PORTC = 0x60; // Entry mode set low nibble
lcd_strobe_lcd_e();
// return home
lcd_write_command(0x02);
lcd_strobe_lcd_e();
}
void lcd_write_character(unsigned char byte){
//upper nibble
PORTC = byte;
sbi_porta(LCD_RS);
lcd_strobe_lcd_e();
//lower nibble
PORTC = (byte<<4);
sbi_porta(LCD_RS);
lcd_strobe_lcd_e();
}
void lcd_write_command(unsigned char byte){
//upper nibble
PORTC = byte;
cbi_porta(LCD_RS);
lcd_strobe_lcd_e();
//lower nibble
PORTC = (byte<<4);
cbi_porta(LCD_RS);
lcd_strobe_lcd_e();
}
void lcd_write_string(const char *str) {
for(;*str; str++){
lcd_write_character(*str);
}
}
void lcd_move_right(void){
lcd_write_command(0x1E);
}
void lcd_write_int(int number)
{
int length = snprintf(NULL, 0, "%d", number + 1);
char str[length + 1];
snprintf(str, length + 1, "%d", number + 1);
lcd_write_string(str);
}

View File

@@ -0,0 +1,30 @@
/*
* lcd_control.h
*
* Created: 24-2-2021 11:56:16
* Author: Sem
*/
#ifndef LCD_CONTROL_H_
#define LCD_CONTROL_H_
#define LCD_E 6
#define LCD_RS 4
void _delay_ms(double __ms);
void lcd_strobe_lcd_e(void);
void sbi_portc(int index);
void cbi_portc(int index);
void sbi_porta(int index);
void cbi_porta(int index);
void init_4bits_mode(void);
void lcd_write_string(const char *str);
void lcd_write_character(unsigned char byte);
void lcd_write_command(unsigned char byte);
void lcd_clear();
void lcd_write_int(int number);
#endif /* LCD_CONTROL_H_ */

View File

@@ -0,0 +1,54 @@
/*
* ultrasonicSensor.c
*
* Created: 17-3-2021 09:47:12
* Author : Sem
timer aanzetten met tccrn2
interrupt op falling edge van echo
in interrupt timer op 0 zetten en tccrn2 op 0
*/
#define F_CPU 20e6
#include <avr/io.h>
#include <util/delay.h>
#include "lcd_control.h"
void wait_us(unsigned int us)
{
for(int i = 0; i < us; i++)
{
_delay_us(1);
}
}
void wait_ms(unsigned int ms)
{
for(int i = 0; i < ms; i++)
{
_delay_ms(1);
}
}
int main(void)
{
DDRG = 0x01; // port g pin 0 on output, 1 on input. 0 is trig, 1 is echo
/* Replace with your application code */
while (1)
{
PORTG = 0x00; // 10 us low pulse
wait_us(10);
PORTG = 0x01;
wait_ms(100);
}
}

View File

@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<Store xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="AtmelPackComponentManagement">
<ProjectComponents>
<ProjectComponent z:Id="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
<CApiVersion></CApiVersion>
<CBundle></CBundle>
<CClass>Device</CClass>
<CGroup>Startup</CGroup>
<CSub></CSub>
<CVariant></CVariant>
<CVendor>Atmel</CVendor>
<CVersion>1.6.0</CVersion>
<DefaultRepoPath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath>
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
<Description></Description>
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\include\</AbsolutePath>
<Attribute></Attribute>
<Category>include</Category>
<Condition>C</Condition>
<FileContentHash i:nil="true" />
<FileVersion></FileVersion>
<Name>include/</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\include\avr\iom128.h</AbsolutePath>
<Attribute></Attribute>
<Category>header</Category>
<Condition>C</Condition>
<FileContentHash>JdJ7J9I/SJh965SEyyyVYw==</FileContentHash>
<FileVersion></FileVersion>
<Name>include/avr/iom128.h</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\templates\main.c</AbsolutePath>
<Attribute>template</Attribute>
<Category>source</Category>
<Condition>C Exe</Condition>
<FileContentHash>zBFq/2TxUzr5xF+6ABRBCw==</FileContentHash>
<FileVersion></FileVersion>
<Name>templates/main.c</Name>
<SelectString>Main file (.c)</SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\templates\main.cpp</AbsolutePath>
<Attribute>template</Attribute>
<Category>source</Category>
<Condition>C Exe</Condition>
<FileContentHash>mkKaE95TOoATsuBGv6jmxg==</FileContentHash>
<FileVersion></FileVersion>
<Name>templates/main.cpp</Name>
<SelectString>Main file (.cpp)</SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega128</AbsolutePath>
<Attribute></Attribute>
<Category>libraryPrefix</Category>
<Condition>GCC</Condition>
<FileContentHash i:nil="true" />
<FileVersion></FileVersion>
<Name>gcc/dev/atmega128</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
</Files>
<PackName>ATmega_DFP</PackName>
<PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.6.364/Atmel.ATmega_DFP.pdsc</PackPath>
<PackVersion>1.6.364</PackVersion>
<PresentInProject>true</PresentInProject>
<ReferenceConditionId>ATmega128</ReferenceConditionId>
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:string></d4p1:string>
</RteComponents>
<Status>Resolved</Status>
<VersionMode>Fixed</VersionMode>
<IsComponentInAtProject>true</IsComponentInAtProject>
</ProjectComponent>
</ProjectComponents>
</Store>

View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<ProjectVersion>7.0</ProjectVersion>
<ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
<ProjectGuid>{26da64de-dd48-4718-94b5-81f9ec5d4b33}</ProjectGuid>
<avrdevice>ATmega128</avrdevice>
<avrdeviceseries>none</avrdeviceseries>
<OutputType>Executable</OutputType>
<Language>C</Language>
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
<OutputFileExtension>.elf</OutputFileExtension>
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
<AssemblyName>ultrasonicSensor</AssemblyName>
<Name>ultrasonicSensor</Name>
<RootNamespace>ultrasonicSensor</RootNamespace>
<ToolchainFlavour>Native</ToolchainFlavour>
<KeepTimersRunning>true</KeepTimersRunning>
<OverrideVtor>false</OverrideVtor>
<CacheFlash>true</CacheFlash>
<ProgFlashFromRam>true</ProgFlashFromRam>
<RamSnippetAddress />
<UncachedRange />
<preserveEEPROM>true</preserveEEPROM>
<OverrideVtorValue />
<BootSegment>2</BootSegment>
<ResetRule>0</ResetRule>
<eraseonlaunchrule>0</eraseonlaunchrule>
<EraseKey />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<ToolchainSettings>
<AvrGcc>
<avrgcc.common.Device>-mmcu=atmega128 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega128"</avrgcc.common.Device>
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>NDEBUG</Value>
</ListValues>
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\</Value>
</ListValues>
</avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.linker.libraries.Libraries>
<ListValues>
<Value>libm</Value>
</ListValues>
</avrgcc.linker.libraries.Libraries>
<avrgcc.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\</Value>
</ListValues>
</avrgcc.assembler.general.IncludePaths>
</AvrGcc>
</ToolchainSettings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<ToolchainSettings>
<AvrGcc>
<avrgcc.common.Device>-mmcu=atmega128 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega128"</avrgcc.common.Device>
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>DEBUG</Value>
</ListValues>
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\</Value>
</ListValues>
</avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.optimization.level>Optimize debugging experience (-Og)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.linker.libraries.Libraries>
<ListValues>
<Value>libm</Value>
</ListValues>
</avrgcc.linker.libraries.Libraries>
<avrgcc.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\</Value>
</ListValues>
</avrgcc.assembler.general.IncludePaths>
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
</AvrGcc>
</ToolchainSettings>
</PropertyGroup>
<ItemGroup>
<Compile Include="lcd_control.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="lcd_control.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="main.c">
<SubType>compile</SubType>
</Compile>
</ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
</Project>