Initial commit

This commit is contained in:
Никита Уткин 2023-04-24 11:14:40 +00:00
parent 0fc4e86a7a
commit a184d3555e
5 changed files with 273 additions and 67 deletions

122
GccApplication3.cproj Normal file
View 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
View 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
View 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
View File

@ -1,67 +1,70 @@
#include <avr/interrupt.h>
#include <avr/io.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "timer.h"
#include "app.h"
#include "uart.h"
double calculate(char op, double num1, double num2) {
double result = 0;
switch (op) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
result = num1 / num2;
break;
}
return result;
void setup() {
USART_Init(MYUBRR);
DDRD = 0b00001111;
PORTD = 0b11110000;
DDRC = 0b111111;
PORTC = 0b001111;
}
int main() {
double number = 0;
double tmpNumber = 0;
char input;
char operator;
while (1) {
scanf(" %c", &input);
switch (input) {
case '+':
operator = '+';
tmpNumber = number;
number = 0;
break;
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);
void countKeysPressedTime(char *keys) {
for (int i = 0; i < 16; i++) {
keyTimeMap[i].key = i;
if (keys[i] == 0) {
keyTimeMap[i].time += 5;
} else {
keyTimeMap[i].time = 0;
}
}
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);
}

14
uart.h Normal file
View File

@ -0,0 +1,14 @@
/*
* uart.h
*
* Created: 13.04.2023 15:32:20
* Author: mrnek
*/
#define FOSC 1843200 // Clock Speed
#define BAUD 9600
#define UDREn (5)
#define MYUBRR FOSC/16/BAUD-1
void USART_Transmit(unsigned char data);
void USART_Init(unsigned int ubrr);