From f2c5b40d7d792f77c79421b65d1f6abb14cbe8f9 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Tue, 5 Apr 2022 20:26:04 +0200 Subject: [PATCH] First commit from 26/11/2021. --- .gitignore | 2 + i2c_test_attiny85.atsln | 22 +++ .../i2c_test_attiny85.componentinfo.xml | 86 +++++++++ i2c_test_attiny85/i2c_test_attiny85.cproj | 143 +++++++++++++++ i2c_test_attiny85/main.c | 163 ++++++++++++++++++ 5 files changed, 416 insertions(+) create mode 100644 .gitignore create mode 100755 i2c_test_attiny85.atsln create mode 100755 i2c_test_attiny85/i2c_test_attiny85.componentinfo.xml create mode 100755 i2c_test_attiny85/i2c_test_attiny85.cproj create mode 100755 i2c_test_attiny85/main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cce2d4a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Atmel +Debug/ \ No newline at end of file diff --git a/i2c_test_attiny85.atsln b/i2c_test_attiny85.atsln new file mode 100755 index 0000000..2ce8b3c --- /dev/null +++ b/i2c_test_attiny85.atsln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Atmel Studio Solution File, Format Version 11.00 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "i2c_test_attiny85", "i2c_test_attiny85\i2c_test_attiny85.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.ActiveCfg = Debug|AVR + {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.Build.0 = Debug|AVR + {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR + {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/i2c_test_attiny85/i2c_test_attiny85.componentinfo.xml b/i2c_test_attiny85/i2c_test_attiny85.componentinfo.xml new file mode 100755 index 0000000..c640938 --- /dev/null +++ b/i2c_test_attiny85/i2c_test_attiny85.componentinfo.xml @@ -0,0 +1,86 @@ + + + + + + + Device + Startup + + + Atmel + 1.2.0 + C:/Program Files (x86)\Atmel\Studio\7.0\Packs + + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.2.118\include + + include + C + + + include + + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.2.118\include\avr\iotn85.h + + header + C + RcYmivGpgsCGGCzeWAIjcA== + + include/avr/iotn85.h + + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.2.118\templates\main.c + template + source + C Exe + T6Fj/fIqJcOx0GrpJU4zHA== + + templates/main.c + Main file (.c) + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.2.118\templates\main.cpp + template + source + C Exe + YXFphlh0CtZJU+ebktABgQ== + + templates/main.cpp + Main file (.cpp) + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.2.118\gcc\dev\attiny85 + + libraryPrefix + GCC + + + gcc/dev/attiny85 + + + + + ATtiny_DFP + C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.2.118/Atmel.ATtiny_DFP.pdsc + 1.2.118 + true + ATtiny85 + + + + Resolved + Fixed + true + + + \ No newline at end of file diff --git a/i2c_test_attiny85/i2c_test_attiny85.cproj b/i2c_test_attiny85/i2c_test_attiny85.cproj new file mode 100755 index 0000000..67c0970 --- /dev/null +++ b/i2c_test_attiny85/i2c_test_attiny85.cproj @@ -0,0 +1,143 @@ + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + dce6c7e3-ee26-4d79-826b-08594b9ad897 + ATtiny85 + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + i2c_test_attiny85 + i2c_test_attiny85 + i2c_test_attiny85 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 0 + + + + + + + + + + + + + com.atmel.avrdbg.tool.stk500 + + 0x1E930B + + + + 125000 + + ISP + + com.atmel.avrdbg.tool.stk500 + + + STK500 + + ISP + 125000 + + + + + -mmcu=attiny85 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\gcc\dev\attiny85" + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include + + + Optimize for size (-Os) + True + True + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include + + + + + + + + + -mmcu=attiny85 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\gcc\dev\attiny85" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include + + + Default (-Wa,-g) + + + + + + compile + + + + \ No newline at end of file diff --git a/i2c_test_attiny85/main.c b/i2c_test_attiny85/main.c new file mode 100755 index 0000000..2a3892e --- /dev/null +++ b/i2c_test_attiny85/main.c @@ -0,0 +1,163 @@ +/* + * i2c_test_attiny85.c + * + * Created: 12/11/2021 15:26:38 + * Author : 40008304 + */ + +#include +#define F_CPU 1000000 +#include + +#define FRONT 0x51 +#define RIGHT 0x52 +#define LEFT 0x53 +#define NOTHING 0x54 +#define ERROR 0xF0 +#define VOLTMIN 1 + +void led1_init(void); +void led2_init(void); +void led1_stop(void); +void led2_stop(void); +void ADC_init(void); +char ADC_read_value(void); +float ADC_averaging(void); +float measureLed1(void); +float measureLed2(void); +char compareLed(void); + +int main(void) +{ + DDRB |= (1< 0 ; precision --) + { + valeur_finale = valeur_finale +(((ADC_read_value() * 0.01961) - valeur_finale) / 15); + } + return valeur_finale; +}; + +float measureLed1(void) +{ + float adcLed; + led2_stop(); + led1_init(); + _delay_ms(250); + adcLed=ADC_averaging(); + _delay_ms(250); + return adcLed; +}; + +float measureLed2(void) +{ + float adcLed; + led1_stop(); + led2_init(); + _delay_ms(250); + adcLed=ADC_averaging(); + _delay_ms(250); + return adcLed; +}; + +char compareLed(void) +{ + float adcLed1 = measureLed1(); + float adcLed2 = measureLed2(); + float adcCompare = adcLed1 - adcLed2; + if (adcCompare < -VOLTMIN) // adcLed2 > adcLed1 + { + return LEFT; + } + else if (adcCompare > VOLTMIN) + { + return RIGHT; + } + else + { + if((adcLed1 > VOLTMIN) && (adcLed2 > VOLTMIN)) + { + return FRONT; + } + else + { + return NOTHING; + }; + }; +}; +