diff options
author | Jonas Gunz <jonas.gunz@googlemail.com> | 2014-10-19 22:35:32 +0200 |
---|---|---|
committer | Jonas Gunz <jonas.gunz@googlemail.com> | 2014-10-19 22:35:32 +0200 |
commit | 72836e52e1e386c2f4f5dd70553914a3c8feb325 (patch) | |
tree | f5d30b1cb5a1f54bb7770962b8e852a6c31ac30a | |
parent | cbf051d4a171343ae714cfd26730be10de1b65f9 (diff) | |
download | AVR-Tacho-72836e52e1e386c2f4f5dd70553914a3c8feb325.tar.gz |
Uploaded
-rw-r--r-- | .gitattributes | 3 | ||||
-rw-r--r-- | .gitignore | 227 | ||||
-rw-r--r-- | Makefile | 125 | ||||
-rw-r--r-- | Tacho_screen.c | 189 | ||||
-rw-r--r-- | Tacho_screen.cproj | 115 |
5 files changed, 659 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes index 412eeda..157cc39 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8,6 +8,9 @@ *.vbproj merge=union *.fsproj merge=union *.dbproj merge=union +*.cproj merge=union + + # Standard to msysgit *.doc diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..714a294 --- /dev/null +++ b/.gitignore @@ -0,0 +1,227 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml +*.publishproj + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + + +############# +## Python +############# + +*.py[cod] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg + +#avr + +.mk +.d +.eep +.elf +.lss +.map +.o +.srec
\ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..879a067 --- /dev/null +++ b/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:= + +# Every subdirectory with source files must be described here +SUBDIRS := + + +# Add inputs and outputs from these tool invocations to the build variables +C_SRCS += \ +../Tacho_screen.c + + +PREPROCESSING_SRCS += + + +ASM_SRCS += + + +OBJS += \ +Tacho_screen.o + +OBJS_AS_ARGS += \ +Tacho_screen.o + +C_DEPS += \ +Tacho_screen.d + +C_DEPS_AS_ARGS += \ +Tacho_screen.d + +OUTPUT_FILE_PATH +=Tacho_screen.elf + +OUTPUT_FILE_PATH_AS_ARGS +=Tacho_screen.elf + +ADDITIONAL_DEPENDENCIES:= + +OUTPUT_FILE_DEP:= ./makedep.mk + +LIB_DEP+= + +# AVR32/GNU C Compiler + + + +./%.o: .././%.c + @echo Building file: $< + @echo Invoking: AVR/GNU C Compiler : 3.4.2 + $(QUOTE)C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.1002\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -funsigned-char -funsigned-bitfields -DDEBUG -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega8 -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) + @echo Building target: $@ + @echo Invoking: AVR/GNU Linker : 3.4.2 + $(QUOTE)C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.1002\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -Wl,-Map="Tacho_screen.map" -Wl,--start-group -Wl,-lm -Wl,--end-group -Wl,--gc-sections -mmcu=atmega8 + @echo Finished building target: $@ + "C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.1002\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature "Tacho_screen.elf" "Tacho_screen.hex" + "C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.1002\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 "Tacho_screen.elf" "Tacho_screen.eep" || exit 0 + "C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.1002\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "Tacho_screen.elf" > "Tacho_screen.lss" + "C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.1002\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature "Tacho_screen.elf" "Tacho_screen.srec" + "C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.1002\avr8-gnu-toolchain\bin\avr-size.exe" "Tacho_screen.elf" + + + + + + + +# Other Targets +clean: + -$(RM) $(OBJS_AS_ARGS) $(EXECUTABLES) + -$(RM) $(C_DEPS_AS_ARGS) + rm -rf "Tacho_screen.elf" "Tacho_screen.a" "Tacho_screen.hex" "Tacho_screen.lss" "Tacho_screen.eep" "Tacho_screen.map" "Tacho_screen.srec" +
\ No newline at end of file diff --git a/Tacho_screen.c b/Tacho_screen.c new file mode 100644 index 0000000..df8d34c --- /dev/null +++ b/Tacho_screen.c @@ -0,0 +1,189 @@ +/* + * Tacho.c + * + * Created: 19.06.2014 15:33:40 + * Author: Jonas + */ + +#define F_CPU 1000000 +#include <avr/io.h> +#include <util/delay.h> +#include <avr/interrupt.h> + +#define _PRIM PORTC +#define _SEC PORTD + +#define _WHEEL_SIZE 207 + +//Define characters (negative) +#define _C1 0b10101111//0b01010000 +#define _C2 0b11001000//0b00110111 +#define _C3 0b10101000//0b00000000 +#define _C4 0b10100101//0b00000000 +#define _C5 0b10110000//0b00000000 +#define _C6 0b10010001//0b00000000 +#define _C7 0b10101110//0b00000000 +#define _C8 0b10000000//0b00000000 +#define _C9 0b10100000//0b00000000 +#define _C0 0b10000010//0b00000000 +#define _C_ 0b11111101 +#define _CCLEAR 255 + +uint32_t cntr; +unsigned int speed; + +ISR(TIMER0_OVF_vect) +{ + cntr++; +} + +inline void calcSpeed(void) +{ + float tmrSpeed = F_CPU / 256; + float tmrTime = 1 / tmrSpeed; + float comTime = tmrTime * cntr; + + float mps = (_WHEEL_SIZE / 100) / comTime; + + float kmph = mps * 3.6; + + speed = (int)kmph; +}//calcSpeed() + +inline void render(int _screen) +{ + char cNr[16]; + + int i1, i2; + + itoa(_screen, cNr, 10); //convert int to string for rendering + + if(_screen < 10) + { + i1 = 0; + i2 = 1; + cNr[1] = '0'; + } + else + { + i1 = 1; + i2 = 0; + } + + if(_screen > 99 || _screen < 0) + { + _SEC = _PRIM = _C_; + } + else + { + switch (cNr[i1]) //first character + { + case '0': + _PRIM = _C0; + PORTB &= ~(1<<PB2); + break; + case '1': + _PRIM = _C1; + PORTB &= ~(1<<PB2); + break; + case '2': + _PRIM = _C2; + PORTB |= (1<<PB2); + break; + case '3': + _PRIM = _C3; + PORTB &= ~(1<<PB2); + break; + case '4': + _PRIM = _C4; + PORTB &= ~(1<<PB2); + break; + case '5': + _PRIM = _C5; + PORTB &= ~(1<<PB2); + break; + case '6': + _PRIM = _C6; + PORTB &= ~(1<<PB2); + break; + case '7': + _PRIM = _C7; + PORTB &= ~(1<<PB2); + break; + case '8': + _PRIM = _C8; + PORTB &= ~(1<<PB2); + break; + case '9': + _PRIM = _C9; + PORTB &= ~(1<<PB2); + break; + } + + switch (cNr[i2])//second character + { + case '0': + _SEC = _C0; + break; + case '1': + _SEC = _C1; + break; + case '2': + _SEC = _C2; + break; + case '3': + _SEC = _C3; + break; + case '4': + _SEC = _C4; + break; + case '5': + _SEC = _C5; + break; + case '6': + _SEC = _C6; + break; + case '7': + _SEC = _C7; + break; + case '8': + _SEC = _C8; + break; + case '9': + _SEC = _C9; + break; + } + } +}//render() + +int main(void) +{ + TCCR0 = (1 << CS00); // Prescaler 1 + TIMSK = (1<<TOIE0); //Enable Overflowinterrupt + + cntr = 0; //counter for Timer + DDRC = DDRD = 255; // Output for scrren pins + DDRB |= (1<<PB2); + DDRB &= ~(1<<PB1); + + sei(); + + render(0); + + //PORTC = 0b01010000; + while(1)//main loop + { + while(PINB & (1 << PB1) && cntr < 30000){} // wait for reed + TCCR0 = ~(1 << CS00); //disable counter + cli(); //disable interrupts + calcSpeed(); + //reset all variables + cntr = 0; + TCNT0 = 0; + sei();//enable interrupts + TCCR0 = (1 << CS00); //enable counter + + render(speed);//render the calculated speed + _delay_ms(100); + } +}//main()
\ No newline at end of file diff --git a/Tacho_screen.cproj b/Tacho_screen.cproj new file mode 100644 index 0000000..cb4919f --- /dev/null +++ b/Tacho_screen.cproj @@ -0,0 +1,115 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <SchemaVersion>2.0</SchemaVersion> + <ProjectVersion>6.1</ProjectVersion> + <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName> + <ProjectGuid>{862c290e-ca5a-4544-8cf3-b42a901e2a26}</ProjectGuid> + <avrdevice>ATmega8</avrdevice> + <avrdeviceseries>none</avrdeviceseries> + <OutputType>Executable</OutputType> + <Language>C</Language> + <OutputFileName>$(MSBuildProjectName)</OutputFileName> + <OutputFileExtension>.elf</OutputFileExtension> + <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory> + <AssemblyName>Tacho_screen</AssemblyName> + <Name>Tacho_screen</Name> + <RootNamespace>Tacho_screen</RootNamespace> + <ToolchainFlavour>Native</ToolchainFlavour> + <KeepTimersRunning>true</KeepTimersRunning> + <OverrideVtor>false</OverrideVtor> + <CacheFlash>true</CacheFlash> + <ProgFlashFromRam>true</ProgFlashFromRam> + <RamSnippetAddress>0x20000000</RamSnippetAddress> + <UncachedRange /> + <OverrideVtorValue>exception_table</OverrideVtorValue> + <BootSegment>2</BootSegment> + <eraseonlaunchrule>0</eraseonlaunchrule> + <AsfFrameworkConfig> + <framework-data xmlns=""> + <options /> + <configurations /> + <files /> + <documentation help="" /> + <offline-documentation help="" /> + <dependencies> + <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.11.0" /> + </dependencies> + </framework-data> + </AsfFrameworkConfig> + <avrtool>com.atmel.avrdbg.tool.ispmk2</avrtool> + <avrtoolinterface>ISP</avrtoolinterface> + <com_atmel_avrdbg_tool_ispmk2> + <ToolOptions> + <InterfaceProperties> + <JtagEnableExtResetOnStartSession>false</JtagEnableExtResetOnStartSession> + <IspClock>125000</IspClock> + </InterfaceProperties> + <InterfaceName>ISP</InterfaceName> + </ToolOptions> + <ToolType>com.atmel.avrdbg.tool.ispmk2</ToolType> + <ToolNumber>000200185657</ToolNumber> + <ToolName>AVRISP mkII</ToolName> + </com_atmel_avrdbg_tool_ispmk2> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)' == 'Release' "> + <ToolchainSettings> + <AvrGcc> + <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.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.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> + </ToolchainSettings> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> + <ToolchainSettings> + <AvrGcc> + <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.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.optimization.level>Optimize (-O1)</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.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel> + </AvrGcc> + </ToolchainSettings> + </PropertyGroup> + <ItemGroup> + <Compile Include="Tacho_screen.c"> + <SubType>compile</SubType> + </Compile> + </ItemGroup> + <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" /> +</Project>
\ No newline at end of file |