From 18c96a7ee5a490fab4929a5ac345f8a5dd776ed2 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Wed, 27 Mar 2019 19:37:41 -0700 Subject: [PATCH] init --- build.sh | 4 ++++ listen.sh | 11 ++++++++++ main.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100755 build.sh create mode 100755 listen.sh create mode 100644 main.c diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..62e4f94 --- /dev/null +++ b/build.sh @@ -0,0 +1,4 @@ +avr-gcc -Os -DF_CPU=16000000L -DBAUD=9600UL -mmcu=atmega328p main.c -o main.o +avr-objcopy -O ihex main.o main.hex +avrdude -v -patmega328p -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:main.hex:i + rm main.o main.hex diff --git a/listen.sh b/listen.sh new file mode 100755 index 0000000..869d703 --- /dev/null +++ b/listen.sh @@ -0,0 +1,11 @@ +#stty -F /dev/ttyUSB0 cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts + +stty -F /dev/ttyUSB0 9600 -parenb -parodd cs8 -hupcl \ +-cstopb cread clocal -crtscts -iuclc -ixany -imaxbel \ +-iutf8 -opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill \ + -ofdel nl0 cr0 tab0 bs0 vt0 ff0 -isig -icanon -iexten \ +-echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt \ +-echoctl -echoke + + +tail -f /dev/ttyUSB0 diff --git a/main.c b/main.c new file mode 100644 index 0000000..aeb62be --- /dev/null +++ b/main.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include +#define LED PORTB5 +#define WIRE PORTB0 + + +void uart_init() { + // Upper and lower bytes of the calculated prescaler value for baud. + UBRR0H = UBRRH_VALUE; + UBRR0L = UBRRL_VALUE; + + // Configure data frame size to 8-bits. + UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); + + // Configure to enable transmitter. + UCSR0B = _BV(TXEN0); +} + +void uart_putchar(char c) { + // Wait until the register to write to is free. + loop_until_bit_is_set(UCSR0A, UDRE0); + + // Write the byte to the register. + UDR0 = c; +} + +void uart_putstr(char *data) { + // Loop until end of string writing char by char. + while(*data){ + uart_putchar(*data++); + } +} + + +int main(void) { + + uart_init(); + + DDRB |= (1 << LED); + DDRB |= (1 << WIRE); + for(;;){ + + + uart_putstr("hello\n"); + + _delay_ms(100); + + PORTB |= (1 << LED); + PORTB |= (1 << WIRE); + + _delay_ms(100); + + PORTB &= (0 << LED); + PORTB &= (0 << WIRE); + + } + +}