From a184d3555ef9e6d59d800ae3a8d093ab27f723f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=A3=D1=82=D0=BA?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Mon, 24 Apr 2023 11:14:40 +0000 Subject: [PATCH] Initial commit --- GccApplication3.cproj | 122 +++++++++++++++++++++++++++++++++++++ app.c | 50 +++++++++++++++ app.h | 17 ++++++ main.c | 137 +++++++++++++++++++++--------------------- uart.h | 14 +++++ 5 files changed, 273 insertions(+), 67 deletions(-) create mode 100644 GccApplication3.cproj create mode 100644 app.c create mode 100644 app.h create mode 100644 uart.h diff --git a/GccApplication3.cproj b/GccApplication3.cproj new file mode 100644 index 0000000..e5280cf --- /dev/null +++ b/GccApplication3.cproj @@ -0,0 +1,122 @@ + + + + 2.0 + 6.2 + com.Atmel.AVRGCC8.C + {94bbcabe-3e5b-448f-a40b-2b08def16444} + ATmega328P + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + GccApplication3 + GccApplication3 + GccApplication3 + Native + true + false + true + true + + + true + + 2 + 1 + + + + + + + + + + + + + + + + + True + True + True + True + False + True + True + + + NDEBUG + + + Optimize for size (-Os) + True + True + True + + + libm + + + + + + + + + True + True + True + True + False + True + True + + + DEBUG + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + + \ No newline at end of file diff --git a/app.c b/app.c new file mode 100644 index 0000000..095a5f9 --- /dev/null +++ b/app.c @@ -0,0 +1,50 @@ +/* + * core.c + * + * Created: 13.04.2023 14:28:40 + * Author: mrnek + */ +#include +#include +#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) { + +} diff --git a/app.h b/app.h new file mode 100644 index 0000000..d9ccc99 --- /dev/null +++ b/app.h @@ -0,0 +1,17 @@ +#include +/* + * 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); \ No newline at end of file diff --git a/main.c b/main.c index 8052885..ba8669c 100644 --- a/main.c +++ b/main.c @@ -1,67 +1,70 @@ -#include -#include - -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; -} - -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); - } - } - exit: - return 0; -} +#include +#include +#include +#include +#include "timer.h" +#include "app.h" +#include "uart.h" + +void setup() { + USART_Init(MYUBRR); + + DDRD = 0b00001111; + PORTD = 0b11110000; + + DDRC = 0b111111; + PORTC = 0b001111; +} + + +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; + } + } +} + +//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); +} diff --git a/uart.h b/uart.h new file mode 100644 index 0000000..87e89c1 --- /dev/null +++ b/uart.h @@ -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); \ No newline at end of file