80 lines
1.5 KiB
C
80 lines
1.5 KiB
C
#include <avr/interrupt.h>
|
|
#include <avr/io.h>
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include "timer.h"
|
|
#include "keyboard.h"
|
|
#include "uart.h"
|
|
#include "calculator.h"
|
|
|
|
void setup_registers() {
|
|
MCUCR &= ~(1 << 4); // PUD
|
|
MCUCR &= ~(1 << 5);
|
|
MCUCR &= ~(1 << 6);
|
|
MCUCR &= ~(1 << 7);
|
|
DDRD &= 0x0F;
|
|
PORTD |= 0xF0;
|
|
|
|
DDRC = 0b111111;
|
|
PORTC = 0b001111;
|
|
}
|
|
|
|
void setup() {
|
|
USART_Init(MYUBRR);
|
|
setup_timer();
|
|
setup_registers();
|
|
}
|
|
|
|
int main(void) {
|
|
puts("Program started\r\n");
|
|
|
|
setup();
|
|
|
|
struct calculator calc;
|
|
struct key keys[KEYS_AMOUNT];
|
|
|
|
fill_buttons_names(keys);
|
|
clearCalc(&calc);
|
|
|
|
while(1) {
|
|
get_physical_keys(keys);
|
|
get_logical_keys(keys);
|
|
|
|
for (int i = 0; i < KEYS_AMOUNT; i++) {
|
|
bool up, down;
|
|
get_event(&keys[i], &up, &down);
|
|
if (down) {
|
|
handleCalc(&calc, keys[i].button);
|
|
printf("-------\r\n");
|
|
printf("%d\r\n", keys[i].button);
|
|
printf("%li\r\n", calc.num1);
|
|
printf("%li\r\n", calc.num2);
|
|
printf("%li\r\n", calc.result);
|
|
printf("%d\r\n", calc.operation);
|
|
printf("%d\r\n", calc.state);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int puts(const char * __str){
|
|
int len = strlen(__str);
|
|
for(size_t i = 0; i < len; i++){
|
|
while (!(UCSR0A & (1<<UDREn)));
|
|
UDR0 = __str[i];
|
|
}
|
|
}
|
|
|
|
int printf( const char * format, ... )
|
|
{
|
|
char buffer[16];
|
|
va_list args;
|
|
va_start (args, format);
|
|
size_t s = vsprintf (buffer,format, args);
|
|
for(size_t i = 0; i < s; i++){
|
|
while (!(UCSR0A & (1<<UDREn)));
|
|
UDR0 = buffer[i];
|
|
}
|
|
va_end (args);
|
|
return s;
|
|
} |