diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..19e273c --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,19 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "/usr/avr/include", + "${workspaceFolder}/**" + ], + "defines": [ + "__AVR_ATmega32U4__" + ], + "compilerPath": "/usr/bin/clang", + "cStandard": "c17", + "cppStandard": "c++14", + "intelliSenseMode": "linux-clang-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..05a7331 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "io.h": "c", + "sfr_defs.h": "c" + } +} \ No newline at end of file diff --git a/Makefile b/Makefile index e1f7428..246130f 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,9 @@ TARGETNAME = togglePin BUILDFOLDER = ./build/ TARGET = $(BUILDFOLDER)$(TARGETNAME) -INC = -Isrc/include -I/usr/lib/avr/include/ -CFLAGS = -Wall -Wpedantic -Wextra -g -Os -mmcu=atmega328p -CPPFLAGS = -DF_CPU=16000000UL +INC = -Isrc/include -I/usr/avr/include +CFLAGS = -Wall -Wpedantic -Wextra -Os -mmcu=atmega32u4 +CPPFLAGS = -DF_CPU=8000000UL SRC = $(wildcard src/*.c) @@ -17,7 +17,7 @@ $(TARGET): $(SRC) rm $@.elf flash: - avrdude -p m328p -P /dev/ttyUSB0 -c arduino -b 57600 -Uflash:w:"$(TARGET).hex":i + avrdude -p m32u4 -P /dev/ttyACM0 -c avr109 -Uflash:w:"$(TARGET).hex":i clean: rm -fr ./src/*.o ./build/ diff --git a/docs/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf b/docs/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf deleted file mode 100644 index 4a9dad4..0000000 Binary files a/docs/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf and /dev/null differ diff --git a/src/inverter.c b/src/inverter.c new file mode 100644 index 0000000..5f813fe --- /dev/null +++ b/src/inverter.c @@ -0,0 +1,110 @@ +#include +#include +#include +#include + +void togglePin(uint8_t port, uint8_t pin); + +void initCtcTimer0(void); +void initOverflowTimer0(void); +void initOverflowTimer1(void); + +void initUart(unsigned int baud); +void uart_sendByte(uint8_t byte); +int uart_printf(char var, FILE *stream); + +static FILE stream = FDEV_SETUP_STREAM(uart_printf, NULL, _FDEV_SETUP_WRITE); + +uint8_t sec = 0; + +int main() +{ + stdout = &stream; + + /* Make PB1 & PB2 an output pin */ + DDRB |= (1 << DDB1); + DDRB |= (1 << DDB2); + + /* With this frequency, it is 38,4k baud */ + initUart(12); + + while (1) { + _delay_ms(1000); + printf("Seconds passed: %u\n\r", sec++); + } + + return 0; +} + + + +void initCtcTimer0(void) +{ + /* Initialize counter 0 */ + TCNT0 = 0; + + /* Enable Counter0 Compare Match A Interrupt */ + TIMSK0 |= (1 << OCIE0A); + + /* Select clock. Prescaler of 0*/ + TCCR0B |= (1 << CS00); + + /* Use CTC Mode */ + TCCR0A |= (1 << WGM01); + + /* + * OCR0A contains TOP value for counter: + */ + OCR0A = 200; +} + +void initOverflowTimer0(void) +{ + /* Prescaler = 0 */ + TCCR0B |= (1<>8); + UBRR1L = (unsigned char)baud; + + /* Enable receiver and transmitter */ + UCSR1B = (1< -#include - - -int main() -{ - DDRB |= 1 << PB2; - - while (1) { - PORTB &= ~(1 << PB2); - _delay_ms(10); - PORTB |= 1 << PB2; - _delay_ms(10); - } - - return 0; -}