summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2017-05-02 21:15:14 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2017-05-02 21:15:14 +0200
commitde57772e2027729e76482a2771d60f444a975036 (patch)
tree9d694deff1ff1e2261ae0190044486d8414eb05e
parent677c370834102ae43ce19d0931cc98d8267dacc5 (diff)
downloadavrFloppy-de57772e2027729e76482a2771d60f444a975036.tar.gz
added UART Library
-rw-r--r--.vs/floppyMusic/v14/.atsuobin34304 -> 34816 bytes
-rw-r--r--floppyMusic/floppy.c6
-rw-r--r--floppyMusic/floppy.h6
-rw-r--r--floppyMusic/floppyMusic.cproj6
-rw-r--r--floppyMusic/main.c14
-rw-r--r--floppyMusic/uart.c40
-rw-r--r--floppyMusic/uart.h28
7 files changed, 92 insertions, 8 deletions
diff --git a/.vs/floppyMusic/v14/.atsuo b/.vs/floppyMusic/v14/.atsuo
index 706c20b..eab8b25 100644
--- a/.vs/floppyMusic/v14/.atsuo
+++ b/.vs/floppyMusic/v14/.atsuo
Binary files 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 <avr/io.h>
#include <avr/interrupt.h>
-#include <avr/delay.h>
+#include <util/delay.h>
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 Include="main.c">
<SubType>compile</SubType>
</Compile>
+ <Compile Include="uart.c">
+ <SubType>compile</SubType>
+ </Compile>
+ <Compile Include="uart.h">
+ <SubType>compile</SubType>
+ </Compile>
</ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
</Project> \ 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 <avr/io.h>
#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<<UDRE)));
+ UDR = _data;
+ }
+
+ void uart_send_string(char *_data)
+ {
+ char *data = _data;
+
+ while(*data != '\0')
+ {
+ uart_send(*data);
+ data++;
+ }
+ }
+
+ char uart_recieve()
+ {
+ while(!(UCSRA & (1<<RXC)));
+
+ return UDR;
+ } \ No newline at end of file
diff --git a/floppyMusic/uart.h b/floppyMusic/uart.h
new file mode 100644
index 0000000..4943af9
--- /dev/null
+++ b/floppyMusic/uart.h
@@ -0,0 +1,28 @@
+/*
+ * uart.h
+ *
+ * Created: 02.05.2017 20:48:16
+ * Author: Jonas
+ */
+
+
+#ifndef UART_H_
+#define UART_H_
+
+#ifndef F_CPU
+#define F_CPU 16000000UL //CPU Running at 16MHz
+#endif
+
+#include <avr/io.h>
+
+#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