diff options
author | VG <vg@devys.org> | 2015-08-26 18:45:01 +0200 |
---|---|---|
committer | VG <vg@devys.org> | 2015-08-26 18:45:01 +0200 |
commit | 7346cfaad4d969db060f3c7ae242ea93f4fff5c0 (patch) | |
tree | 3d3a09a29f783270b8da931e3c879234553ec43f /powerswitch2 | |
download | avr-7346cfaad4d969db060f3c7ae242ea93f4fff5c0.tar.gz avr-7346cfaad4d969db060f3c7ae242ea93f4fff5c0.tar.bz2 avr-7346cfaad4d969db060f3c7ae242ea93f4fff5c0.zip |
first commitboo-standby-watcher-last-with-amp
Diffstat (limited to 'powerswitch2')
-rw-r--r-- | powerswitch2/Makefile | 39 | ||||
-rw-r--r-- | powerswitch2/main.c | 39 |
2 files changed, 78 insertions, 0 deletions
diff --git a/powerswitch2/Makefile b/powerswitch2/Makefile new file mode 100644 index 0000000..104f084 --- /dev/null +++ b/powerswitch2/Makefile @@ -0,0 +1,39 @@ +DEVICE = attiny2313 +CLOCK = 8000000 +FUSES = -U lfuse:w:0xe4:m -U hfuse:w:0xd9:m + +PROGRAMMER =-c stk500v2 +PROGRAMMER +=-P /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A800dAli-if00-port0 +# in ms should be at least 4 times less than clock speed +SPEED = 4 # for default 1Mhz clock +#SPEED = 0.34 # for 12Mhz clock +DEFS = -DF_CPU=$(CLOCK)UL +LIBS = -Wl,--relax,--gc-sections,--print-gc-sections,--entry=main +LIBS = -Wl,--entry=main,--gc-sections,--rela +CFLAGS = -Wall -Werror -pedantic -std=c99 +CFLAGS += -Os -funsigned-bitfields -fpack-struct -fshort-enums +CFLAGS += -mmcu=$(DEVICE) $(DEFS) +#LDFLAGS = $(LIBS) + +all: main.hex size + +main.hex: main.c + avr-gcc -o main.elf $? $(CFLAGS) $(LDFLAGS) + avr-objcopy -j .text -j .data -O ihex main.elf main.hex + +f: flash +flash: all + avrdude $(PROGRAMMER) -p $(DEVICE) -B $(SPEED) -U flash:w:main.hex:i + +fuse: + avrdude $(PROGRAMMER) -p $(DEVICE) -B $(SPEED) $(FUSES) + +clean: + rm -f *.o *.elf *.hex + +size: + avr-size --mcu=$(DEVICE) -t -A main.elf + avr-size --mcu=$(DEVICE) -C main.elf + avr-nm --size-sort main.elf + + 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 <avr/io.h> +#include <util/delay.h> + +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 <util/setbaud.h> + UBRRH = UBRRH_VALUE; + UBRRL = UBRRL_VALUE; +#if USE_2X + UCSRA |= (1 << U2X); +#else + UCSRA &= ~(1 << U2X); +#endif +} |