From 7346cfaad4d969db060f3c7ae242ea93f4fff5c0 Mon Sep 17 00:00:00 2001 From: VG Date: Wed, 26 Aug 2015 18:45:01 +0200 Subject: first commit --- powerswitch2/main.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 powerswitch2/main.c (limited to 'powerswitch2/main.c') diff --git a/powerswitch2/main.c b/powerswitch2/main.c new file mode 100644 index 0000000..63e5d5c --- /dev/null +++ b/powerswitch2/main.c @@ -0,0 +1,39 @@ +#include +#include + +static inline void uart_init(); +int main() +{ + /* serial */ + uart_init(); + + /* data input */ + PORTB &= ~0x0F; + DDRB |= 0x0F; + + for (;;) + { + while ((UCSRA & (1 << RXC)) == 0); + PORTB ^= UDR & 0x0F; + + while ((UCSRA & (1 << UDRE)) == 0); + UDR = PORTB & 0x0F; + } + + return 0; +} + +static inline void uart_init() +{ + UCSRB |= (1 << RXEN) | (1 << TXEN); + UCSRC |= (1 << UCSZ0) | (1 << UCSZ1); +#define BAUD 38400 +#include + UBRRH = UBRRH_VALUE; + UBRRL = UBRRL_VALUE; +#if USE_2X + UCSRA |= (1 << U2X); +#else + UCSRA &= ~(1 << U2X); +#endif +} -- cgit v1.2.3