diff --git a/src/commands.c b/src/commands.c index 5448225..7dd2253 100644 --- a/src/commands.c +++ b/src/commands.c @@ -25,8 +25,6 @@ void cmd_collect_char(char c) if (c == 0xD) { - printf("\n\r"); - /* Null-terminate the string */ command.buf[command.index-1] = '\0'; cmd_handle(&command); @@ -48,15 +46,41 @@ void cmd_handle(cmd_t *command) void cmd_handle_set(char *op1, char *op2) { - int val; + long int val; + char *end; if (0 == strcmp(op1, "t0_top")) { - val = atoi(op2); - if (val) { + val = strtol(op2, &end, 10); + if (op2 != end) { OCR0A = val; - printf("Setting Timer0 TOP to %i\r\n", val); + printf("Setting Timer0 TOP to %li\r\n", val); } else printf("No valid value for t0_top given\n\r"); } + else if (0 == strcmp(op1, "t0_ps")) { + val = strtol(op2, &end, 10); + TCCR0B &= ~((1 << CS00) | (1 << CS01) | (1 << CS02)); + switch (val) + { + case 0: + TCCR0B |= (1 << CS00); + break; + case 8: + TCCR0B |= (1 << CS01); + break; + case 64: + TCCR0B |= (1 << CS00) | (1 << CS01); + break; + case 256: + TCCR0B |= (1 << CS02); + break; + case 1024: + TCCR0B |= (1 << CS02) | (1 << CS00); + break; + default: + printf("No valid prescaler value.\n\r"); + break; + } + } } \ No newline at end of file diff --git a/src/inverter.c b/src/inverter.c index 0be082c..aa6e7f7 100644 --- a/src/inverter.c +++ b/src/inverter.c @@ -20,7 +20,7 @@ int main() while (1) { if ((PORTB & (1<1) { - _delay_us(10); + _delay_us(1); PORTB &= ~(1< +#include #include "include/uart.h" +#include "include/commands.h" static FILE stream = FDEV_SETUP_STREAM(uart_printf, NULL, _FDEV_SETUP_WRITE); @@ -40,3 +42,10 @@ int uart_printf(char var, FILE *stream) return 0; } +ISR(USART1_RX_vect) +{ + char u; + u = UDR1; + + cmd_collect_char(u); +} \ No newline at end of file