From de57772e2027729e76482a2771d60f444a975036 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Tue, 2 May 2017 21:15:14 +0200 Subject: added UART Library --- .vs/floppyMusic/v14/.atsuo | Bin 34304 -> 34816 bytes floppyMusic/floppy.c | 6 ++---- floppyMusic/floppy.h | 6 +++++- floppyMusic/floppyMusic.cproj | 6 ++++++ floppyMusic/main.c | 14 +++++++++++--- floppyMusic/uart.c | 40 ++++++++++++++++++++++++++++++++++++++++ floppyMusic/uart.h | 28 ++++++++++++++++++++++++++++ 7 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 floppyMusic/uart.c create mode 100644 floppyMusic/uart.h diff --git a/.vs/floppyMusic/v14/.atsuo b/.vs/floppyMusic/v14/.atsuo index 706c20b..eab8b25 100644 Binary files a/.vs/floppyMusic/v14/.atsuo and b/.vs/floppyMusic/v14/.atsuo differ diff --git a/floppyMusic/floppy.c b/floppyMusic/floppy.c index 716502a..e4eff05 100644 --- a/floppyMusic/floppy.c +++ b/floppyMusic/floppy.c @@ -17,7 +17,7 @@ ISR(TIMER0_OVF_vect) for(uint8_t i = 0; i < 8; i++) { - if(floppy_nextrun[i] == (timer_overflow_counter + 1)) //Do Stuff. Doesnt work + if(floppy_nextrun[i] == (timer_overflow_counter + 1)) { floppy_nextrun[i] += floppy_frequencies[i]; floppy_pulse(i); @@ -40,8 +40,6 @@ void floppy_setup(char *_pulse_port, char *_pulse_ddr, char *_direction_port, ch *dDDR = 0xff; *dPORT = 0xff; - - //Variable init timer_overflow_counter = 0; @@ -63,7 +61,7 @@ void floppy_setup(char *_pulse_port, char *_pulse_ddr, char *_direction_port, ch *fPORT = 0xff; //Setup Timer - TCCR0 |= (1 << CS01); // Prescaler 8, for max Frequency of 488 Hertz for F_CPU = 1MHz + TCCR0 |= (1 << CS01); // Prescaler 8 To leave enough time for ISR to complete TIMSK |= (1 << TOIE0); //Activate Interrupt sei(); } diff --git a/floppyMusic/floppy.h b/floppyMusic/floppy.h index 280bb2f..76ad123 100644 --- a/floppyMusic/floppy.h +++ b/floppyMusic/floppy.h @@ -9,9 +9,13 @@ #ifndef FLOPPY_H_ #define FLOPPY_H_ +#ifndef F_CPU +#define F_CPU 16000000UL +#endif + #include #include -#include +#include uint8_t timer_overflow_counter; uint8_t floppy_frequencies[8]; diff --git a/floppyMusic/floppyMusic.cproj b/floppyMusic/floppyMusic.cproj index 71fa9a4..9910c79 100644 --- a/floppyMusic/floppyMusic.cproj +++ b/floppyMusic/floppyMusic.cproj @@ -168,6 +168,12 @@ compile + + compile + + + compile + \ No newline at end of file diff --git a/floppyMusic/main.c b/floppyMusic/main.c index 9743636..c0db582 100644 --- a/floppyMusic/main.c +++ b/floppyMusic/main.c @@ -5,18 +5,26 @@ * Author : Jonas */ + #ifndef F_CPU + #define F_CPU 16000000UL //CPU Running at 16MHz + #endif + #include #include "floppy.h" +#include "uart.h" int main(void) { + uart_init(9600); + floppy_setup(&PORTC, &DDRC, &PORTD, &DDRD); floppy_set_frequency(0, 4); + uart_send_string("Floppy Music\n"); + while (1) { - + floppy_set_frequency(0, uart_recieve()); } -} - +} \ No newline at end of file diff --git a/floppyMusic/uart.c b/floppyMusic/uart.c new file mode 100644 index 0000000..d4d5ccf --- /dev/null +++ b/floppyMusic/uart.c @@ -0,0 +1,40 @@ +/* + * uart.c + * + * Created: 02.05.2017 20:48:26 + * Author: Jonas + */ + + #include "uart.h" + + void uart_init(uint32_t _baud) + { + unsigned int ubrr = _GET_UBBR(_baud); + + UBRRH = (ubrr<<8); + UBRRL = ubrr; + } + + void uart_send(char _data) + { + while(!(UCSRA & (1< + +#define _GET_UBBR(BAUD) ( (F_CPU / 16 * BAUD) - 1) + +void uart_init(uint32_t _baud); + +void uart_send(char _data); + +void uart_send_string(char *_data); + +char uart_recieve(void); + +#endif /* UART_H_ */ \ No newline at end of file -- cgit v1.2.3