diff --git a/Makefile b/Makefile index 4c7662d..e71e046 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ MCU_TTY_BAUD = 57600 MCU_PROGRAMMER = arduino PRG = main -OBJ = main.o uart.o +OBJ = main.o OPTIMIZE = -O2 DEFS = -DF_CPU=$(MCU_FREQ) -DBAUDRATE=$(MCU_TTY_BAUD) diff --git a/main.c b/main.c index 6720334..a1f77b6 100644 --- a/main.c +++ b/main.c @@ -2,24 +2,14 @@ #include #include #include -#include "uart.h" + +#define BAUD_PRESCALE (((F_CPU/(BAUDRATE*8UL)))-1) /* Button matrix between PB3-PB4, PC0-PC3 * PC0-PC3 are inputs, default pull-up * PB3-PB4 are pulled to ground (alternating) while the above are read */ -void print_nibble(uint8_t nibble) { - nibble += 0x30; - if (nibble > 0x39) nibble += 7; - uart_putc(nibble); -} - -void print_int8hex(uint8_t val) { - print_nibble(val >> 4); - print_nibble(val & 0x0F); -} - uint8_t getButtonState() { uint8_t val = 0; @@ -79,6 +69,23 @@ void setrelay(uint8_t n, uint8_t s) { } } +char umode = 't'; +ISR(USART_RX_vect) { + uint8_t c = UDR0; + if (c == 't' || c == 'e' || c == 'd') { + umode = c; + } else if (c >= '0' && c <= '7') { + c = c - '0'; + if (umode == 'e') { + setrelay(c,1); + } else if (umode == 'd') { + setrelay(c,0); + } else if (umode == 't') { + setrelay(c,1 - getrelay(c)); + } + } +} + int main() { DDRC &= ~(0b1111); // This sets PC0 to PC3 to input PORTC |= 0b1111; // This makes dito pull-up per default @@ -92,7 +99,16 @@ int main() { PORTD |= 0b11111100; PORTB |= 0b00000011; + // Init uart + UCSR0A = (1< -#include -#include - -#include "uart.h" - -#define UART_BUFSIZE 64 - -typedef volatile struct { - char data[UART_BUFSIZE]; - uint8_t r; - uint8_t w; -} buf; - -buf __attribute__ ((section (".noinit"))) uart_rxbuf; -buf __attribute__ ((section (".noinit"))) uart_txbuf; - -#define BAUD_PRESCALE (((F_CPU/(BAUDRATE*8UL)))-1) - -void __attribute__ ((naked)) __attribute__ ((section (".init5"))) uart_init() { - uart_rxbuf.r = 0; - uart_rxbuf.w = 0; - - uart_txbuf.r = 0; - uart_txbuf.w = 0; - - UCSR0A = (1< - -uint8_t uart_getc(); -uint8_t uart_putc(unsigned char c);