Initial commit
This commit is contained in:
parent
0fc4e86a7a
commit
a184d3555e
122
GccApplication3.cproj
Normal file
122
GccApplication3.cproj
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
<?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.2</ProjectVersion>
|
||||||
|
<ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
|
||||||
|
<ProjectGuid>{94bbcabe-3e5b-448f-a40b-2b08def16444}</ProjectGuid>
|
||||||
|
<avrdevice>ATmega328P</avrdevice>
|
||||||
|
<avrdeviceseries>none</avrdeviceseries>
|
||||||
|
<OutputType>Executable</OutputType>
|
||||||
|
<Language>C</Language>
|
||||||
|
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
|
||||||
|
<OutputFileExtension>.elf</OutputFileExtension>
|
||||||
|
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
|
||||||
|
<AssemblyName>GccApplication3</AssemblyName>
|
||||||
|
<Name>GccApplication3</Name>
|
||||||
|
<RootNamespace>GccApplication3</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>
|
||||||
|
<eraseonlaunchrule>1</eraseonlaunchrule>
|
||||||
|
<AsfFrameworkConfig>
|
||||||
|
<framework-data xmlns="">
|
||||||
|
<options />
|
||||||
|
<configurations />
|
||||||
|
<files />
|
||||||
|
<documentation help="" />
|
||||||
|
<offline-documentation help="" />
|
||||||
|
<dependencies>
|
||||||
|
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.21.0" />
|
||||||
|
</dependencies>
|
||||||
|
</framework-data>
|
||||||
|
</AsfFrameworkConfig>
|
||||||
|
</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.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.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.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.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="app.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="app.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="main.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="timer.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="timer.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="uart.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="uart.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||||
|
</Project>
|
50
app.c
Normal file
50
app.c
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* core.c
|
||||||
|
*
|
||||||
|
* Created: 13.04.2023 14:28:40
|
||||||
|
* Author: mrnek
|
||||||
|
*/
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "app.h"
|
||||||
|
|
||||||
|
#define MASK_PIND 0b11110000
|
||||||
|
|
||||||
|
void check_physical_keys_state(struct key *keys) {
|
||||||
|
uint8_t row1;
|
||||||
|
PORTC &= ~(1 << 3);
|
||||||
|
row1 = PIND & MASK_PIND;
|
||||||
|
if (row1 & (1 << 4)) keys[0].is_physical_pressed = false; else keys[0].is_physical_pressed = true;
|
||||||
|
if (row1 & (1 << 5)) keys[1].is_physical_pressed = false; else keys[1].is_physical_pressed = true;
|
||||||
|
if (row1 & (1 << 6)) keys[2].is_physical_pressed = false; else keys[2].is_physical_pressed = true;
|
||||||
|
if (row1 & (1 << 7)) keys[3].is_physical_pressed = false; else keys[3].is_physical_pressed = true;
|
||||||
|
PORTC |= (1 << 3);
|
||||||
|
|
||||||
|
PORTC &= ~(1 << 2);
|
||||||
|
row1 = PIND & MASK_PIND;
|
||||||
|
if (row1 & (1 << 4)) keys[4].is_physical_pressed = false; else keys[4].is_physical_pressed = true;
|
||||||
|
if (row1 & (1 << 5)) keys[5].is_physical_pressed = false; else keys[5].is_physical_pressed = true;
|
||||||
|
if (row1 & (1 << 6)) keys[6].is_physical_pressed = false; else keys[6].is_physical_pressed = true;
|
||||||
|
if (row1 & (1 << 7)) keys[7].is_physical_pressed = false; else keys[7].is_physical_pressed = true;
|
||||||
|
PORTC |= (1 << 2);
|
||||||
|
|
||||||
|
PORTC &= ~(1 << 1);
|
||||||
|
row1 = PIND & MASK_PIND;
|
||||||
|
if (row1 & (1 << 4)) keys[8].is_physical_pressed = false; else keys[8].is_physical_pressed = true;
|
||||||
|
if (row1 & (1 << 5)) keys[9].is_physical_pressed = false; else keys[9].is_physical_pressed = true;
|
||||||
|
if (row1 & (1 << 6)) keys[10].is_physical_pressed = false; else keys[10].is_physical_pressed = true;
|
||||||
|
if (row1 & (1 << 7)) keys[11].is_physical_pressed = false; else keys[11].is_physical_pressed = true;
|
||||||
|
PORTC |= (1 << 1);
|
||||||
|
|
||||||
|
PORTC &= ~(1 << 0);
|
||||||
|
row1 = PIND & MASK_PIND;
|
||||||
|
if (row1 & (1 << 4)) keys[12].is_physical_pressed = false; else keys[12].is_physical_pressed = true;
|
||||||
|
if (row1 & (1 << 5)) keys[13].is_physical_pressed = false; else keys[13].is_physical_pressed = true;
|
||||||
|
if (row1 & (1 << 6)) keys[14].is_physical_pressed = false; else keys[14].is_physical_pressed = true;
|
||||||
|
if (row1 & (1 << 7)) keys[15].is_physical_pressed = false; else keys[15].is_physical_pressed = true;
|
||||||
|
PORTC |= (1 << 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void debounce(struct key *undebounce_keys) {
|
||||||
|
|
||||||
|
}
|
17
app.h
Normal file
17
app.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include <stdbool.h>
|
||||||
|
/*
|
||||||
|
* core.h
|
||||||
|
*
|
||||||
|
* Created: 13.04.2023 14:23:22
|
||||||
|
* Author: mrnek
|
||||||
|
*/
|
||||||
|
#define KEYS_AMOUNT 16
|
||||||
|
|
||||||
|
|
||||||
|
struct key {
|
||||||
|
unsigned long pressed_time;
|
||||||
|
bool is_physical_pressed;
|
||||||
|
bool is_logical_pressed;
|
||||||
|
};
|
||||||
|
|
||||||
|
void check_physical_keys_state(struct key *keys);
|
121
main.c
121
main.c
@ -1,67 +1,70 @@
|
|||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include "timer.h"
|
||||||
|
#include "app.h"
|
||||||
|
#include "uart.h"
|
||||||
|
|
||||||
double calculate(char op, double num1, double num2) {
|
void setup() {
|
||||||
double result = 0;
|
USART_Init(MYUBRR);
|
||||||
switch (op) {
|
|
||||||
case '+':
|
DDRD = 0b00001111;
|
||||||
result = num1 + num2;
|
PORTD = 0b11110000;
|
||||||
break;
|
|
||||||
case '-':
|
DDRC = 0b111111;
|
||||||
result = num1 - num2;
|
PORTC = 0b001111;
|
||||||
break;
|
|
||||||
case '*':
|
|
||||||
result = num1 * num2;
|
|
||||||
break;
|
|
||||||
case '/':
|
|
||||||
result = num1 / num2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
|
||||||
double number = 0;
|
|
||||||
double tmpNumber = 0;
|
|
||||||
char input;
|
|
||||||
char operator;
|
|
||||||
|
|
||||||
while (1) {
|
void countKeysPressedTime(char *keys) {
|
||||||
scanf(" %c", &input);
|
|
||||||
switch (input) {
|
for (int i = 0; i < 16; i++) {
|
||||||
case '+':
|
keyTimeMap[i].key = i;
|
||||||
operator = '+';
|
if (keys[i] == 0) {
|
||||||
tmpNumber = number;
|
keyTimeMap[i].time += 5;
|
||||||
number = 0;
|
} else {
|
||||||
break;
|
keyTimeMap[i].time = 0;
|
||||||
case '-':
|
|
||||||
operator = '-';
|
|
||||||
tmpNumber = number;
|
|
||||||
number = 0;
|
|
||||||
break;
|
|
||||||
case '*':
|
|
||||||
operator = '*';
|
|
||||||
tmpNumber = number;
|
|
||||||
number = 0;
|
|
||||||
break;
|
|
||||||
case '/':
|
|
||||||
operator = '/';
|
|
||||||
tmpNumber = number;
|
|
||||||
number = 0;
|
|
||||||
break;
|
|
||||||
case '=':
|
|
||||||
printf("%lf\n", calculate(operator, tmpNumber, number));
|
|
||||||
tmpNumber = 0;
|
|
||||||
number = 0;
|
|
||||||
break;
|
|
||||||
case 'q':
|
|
||||||
goto exit;
|
|
||||||
// operator doesn't match any case constant
|
|
||||||
default:
|
|
||||||
number = (number * 10) + atof(&input);
|
|
||||||
printf("%.1lf\n", number);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit:
|
}
|
||||||
return 0;
|
|
||||||
|
//void debounce(char *keys) {
|
||||||
|
//if (ms % 5 != 0) return;
|
||||||
|
//isDebounced = 0;
|
||||||
|
//checkKeysState(newKeysState);
|
||||||
|
//
|
||||||
|
//for (int i = 0; i < 16; i++) {
|
||||||
|
//if (newKeysState[i] != keys[i]) {
|
||||||
|
//confidenceLevel = 0;
|
||||||
|
//}
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//if (confidenceLevel < 6) confidenceLevel++;
|
||||||
|
//if (confidenceLevel == 5) {
|
||||||
|
//for (int i = 0; i < 16; i++) {
|
||||||
|
//debouncedKeys[i] = keys[i];
|
||||||
|
//}
|
||||||
|
//isDebounced = 1;
|
||||||
|
//confidenceLevel = 0;
|
||||||
|
//}
|
||||||
|
//}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
|
||||||
|
setup();
|
||||||
|
while(1) {
|
||||||
|
|
||||||
|
USART_Transmit(0x6F);
|
||||||
|
//for(volatile long i = 0; i < 100000; i++){};
|
||||||
|
loop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int fputc(int ch, FILE *stream){
|
||||||
|
USART_Transmit(ch);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user