add opdracht 1.6
This commit is contained in:
104
Microcontrollers/opdracht 1.6/main.c
Normal file
104
Microcontrollers/opdracht 1.6/main.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* main.c
|
||||
*
|
||||
* Created: 03-Feb-21 9:17:12 AM
|
||||
* Author: lemms
|
||||
*/
|
||||
# define F_CPU 10000000UL
|
||||
|
||||
#include <util/delay.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
typedef enum {
|
||||
false = 0,
|
||||
true = 1
|
||||
} bool;
|
||||
|
||||
/******************************************************************/
|
||||
void wait( int ms )
|
||||
/*
|
||||
short: Busy wait number of milliseconds
|
||||
inputs: int ms (Number of milliseconds to busy wait)
|
||||
outputs:
|
||||
notes: Busy wait, not very accurate. Make sure (external)
|
||||
clock value is set. This is used by _delay_ms inside
|
||||
util/delay.h
|
||||
Version : DMK, Initial code
|
||||
*******************************************************************/
|
||||
{
|
||||
for (int i=0; i<ms; i++)
|
||||
{
|
||||
_delay_ms( 1 ); // library function (max 30 ms at 8MHz)
|
||||
}
|
||||
}
|
||||
|
||||
void sbi(int REG, int index){
|
||||
REG |= (1<<index);
|
||||
}
|
||||
|
||||
void cbi(int REG, int index){
|
||||
REG &= ~(1<<index);
|
||||
}
|
||||
|
||||
int tbi(int REG, int index){
|
||||
REG ^= (1<<index);
|
||||
return REG;
|
||||
}
|
||||
|
||||
bool checkButton(){
|
||||
return (PINC & 1);
|
||||
}
|
||||
|
||||
bool checkButtonToggle(bool pressed){
|
||||
return (checkButton() == true) && (pressed == false);
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
int main( void )
|
||||
/*
|
||||
short: main() loop, entry point of executable
|
||||
inputs:
|
||||
outputs:
|
||||
notes: Looping forever, flipping bits on PORTD
|
||||
Version : DMK, Initial code
|
||||
*******************************************************************/
|
||||
{
|
||||
bool pressed = checkButton();
|
||||
bool state = false;
|
||||
int ms = 0;
|
||||
int button = 0;
|
||||
int setTime = 1000;
|
||||
DDRD = 0b11111111; // All pins PORTD are set to output
|
||||
DDRC = 0b00000000; // set pint input
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
||||
if(checkButtonToggle(pressed)){
|
||||
pressed = checkButton();
|
||||
state = !state;
|
||||
}
|
||||
|
||||
if(pressed && !checkButton()){
|
||||
pressed = false;
|
||||
}
|
||||
|
||||
if(state){
|
||||
setTime = 250;
|
||||
} else {
|
||||
setTime = 1000;
|
||||
}
|
||||
|
||||
if(ms >= setTime){
|
||||
PORTD = tbi(PORTD, 0);
|
||||
ms = 0;
|
||||
}
|
||||
|
||||
wait(1);
|
||||
|
||||
ms++;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
42
Microcontrollers/opdracht 1.6/opdracht 1.6.componentinfo.xml
Normal file
42
Microcontrollers/opdracht 1.6/opdracht 1.6.componentinfo.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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\xc8\avr\include\avr\iom128.h</AbsolutePath>
|
||||
<Attribute></Attribute>
|
||||
<Category>header</Category>
|
||||
<Condition>XC</Condition>
|
||||
<FileContentHash>JdJ7J9I/SJh965SEyyyVYw==</FileContentHash>
|
||||
<FileVersion></FileVersion>
|
||||
<Name>xc8/avr/include/avr/iom128.h</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>
|
||||
99
Microcontrollers/opdracht 1.6/opdracht 1.6.cproj
Normal file
99
Microcontrollers/opdracht 1.6/opdracht 1.6.cproj
Normal file
@@ -0,0 +1,99 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectVersion>7.0</ProjectVersion>
|
||||
<ToolchainName>com.microchip.xc8</ToolchainName>
|
||||
<ProjectGuid>{2c44e92f-6d48-45bd-810a-ad501ec081fe}</ProjectGuid>
|
||||
<avrdevice>ATmega128</avrdevice>
|
||||
<avrdeviceseries>none</avrdeviceseries>
|
||||
<OutputType>Executable</OutputType>
|
||||
<Language>C</Language>
|
||||
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
|
||||
<OutputFileExtension>.elf</OutputFileExtension>
|
||||
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
|
||||
<AssemblyName>opdracht 1.6</AssemblyName>
|
||||
<Name>opdracht 1.6</Name>
|
||||
<RootNamespace>opdracht 1.6</RootNamespace>
|
||||
<ToolchainFlavour>XC8_2.31</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 />
|
||||
<AsfFrameworkConfig>
|
||||
<framework-data xmlns="">
|
||||
<options />
|
||||
<configurations />
|
||||
<files />
|
||||
<documentation help="" />
|
||||
<offline-documentation help="" />
|
||||
<dependencies>
|
||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.49.1" />
|
||||
</dependencies>
|
||||
</framework-data>
|
||||
</AsfFrameworkConfig>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<ToolchainSettings>
|
||||
<com.microchip.xc8>
|
||||
<com.microchip.xc8.common.optimization.RelaxBranches>True</com.microchip.xc8.common.optimization.RelaxBranches>
|
||||
<com.microchip.xc8.compiler.general.ChangeDefaultCharTypeUnsigned>True</com.microchip.xc8.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<com.microchip.xc8.compiler.general.ChangeDefaultBitFieldUnsigned>True</com.microchip.xc8.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<com.microchip.xc8.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>(%24DeviceMacro)</Value>
|
||||
<Value>NDEBUG</Value>
|
||||
</ListValues>
|
||||
</com.microchip.xc8.compiler.symbols.DefSymbols>
|
||||
<com.microchip.xc8.compiler.optimization.level>Optimize for size (-Os)</com.microchip.xc8.compiler.optimization.level>
|
||||
<com.microchip.xc8.compiler.optimization.PackStructureMembers>True</com.microchip.xc8.compiler.optimization.PackStructureMembers>
|
||||
<com.microchip.xc8.compiler.optimization.AllocateBytesNeededForEnum>True</com.microchip.xc8.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<com.microchip.xc8.compiler.warnings.AllWarnings>True</com.microchip.xc8.compiler.warnings.AllWarnings>
|
||||
<com.microchip.xc8.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</com.microchip.xc8.linker.libraries.Libraries>
|
||||
</com.microchip.xc8>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<ToolchainSettings>
|
||||
<com.microchip.xc8>
|
||||
<com.microchip.xc8.compiler.general.ChangeDefaultCharTypeUnsigned>True</com.microchip.xc8.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<com.microchip.xc8.compiler.general.ChangeDefaultBitFieldUnsigned>True</com.microchip.xc8.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<com.microchip.xc8.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>(%24DeviceMacro)</Value>
|
||||
<Value>DEBUG</Value>
|
||||
</ListValues>
|
||||
</com.microchip.xc8.compiler.symbols.DefSymbols>
|
||||
<com.microchip.xc8.compiler.optimization.level>Optimize debugging experience (-Og)</com.microchip.xc8.compiler.optimization.level>
|
||||
<com.microchip.xc8.compiler.optimization.PackStructureMembers>True</com.microchip.xc8.compiler.optimization.PackStructureMembers>
|
||||
<com.microchip.xc8.compiler.optimization.AllocateBytesNeededForEnum>True</com.microchip.xc8.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<com.microchip.xc8.compiler.optimization.DebugLevel>Default (-g2)</com.microchip.xc8.compiler.optimization.DebugLevel>
|
||||
<com.microchip.xc8.compiler.warnings.AllWarnings>True</com.microchip.xc8.compiler.warnings.AllWarnings>
|
||||
<com.microchip.xc8.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</com.microchip.xc8.linker.libraries.Libraries>
|
||||
<com.microchip.xc8.assembler.debugging.DebugLevel>Default (-Wa,-g)</com.microchip.xc8.assembler.debugging.DebugLevel>
|
||||
</com.microchip.xc8>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="main.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||
</Project>
|
||||
Reference in New Issue
Block a user