From f9357256249657af2374e3c334b9180e63dc5a30 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Fri, 16 Jun 2017 00:22:47 +0200 Subject: Split in different files --- .vs/floppyMusic/v14/.atsuo | Bin 54784 -> 74240 bytes floppyMusic/floppy.c | 6 +- floppyMusic/floppyMusic.componentinfo.xml | 12 +- floppyMusic/floppyMusic.cproj | 20 ++- floppyMusic/main.c | 152 +----------------- floppyMusic/midi.c | 42 +++++ floppyMusic/midi.h | 34 ++++ floppyMusic/music.c | 247 ++++++++++++++++++++++++++++++ floppyMusic/music.h | 49 ++++++ floppyMusic/uart.c | 15 +- floppyMusic/uart.h | 4 +- 11 files changed, 412 insertions(+), 169 deletions(-) create mode 100644 floppyMusic/midi.c create mode 100644 floppyMusic/midi.h create mode 100644 floppyMusic/music.c create mode 100644 floppyMusic/music.h diff --git a/.vs/floppyMusic/v14/.atsuo b/.vs/floppyMusic/v14/.atsuo index c49928c..afdd2ba 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 9d6bd54..6a12af6 100644 --- a/floppyMusic/floppy.c +++ b/floppyMusic/floppy.c @@ -13,7 +13,7 @@ ISR(TIMER0_OVF_vect) timer_overflow_counter ++; - *fPORT = 0xff; + *fPORT = 0xff; //Deactivate all previously activated pins for(uint8_t i = 0; i < 8; i++) { @@ -35,6 +35,7 @@ void floppy_setup(char *_pulse_port, char *_pulse_ddr, char *_direction_port, ch dPORT = _direction_port; dDDR = _direction_ddr; + //Floppy inputs are active low so they are initialized high *fDDR = 0xff; *fPORT = 0xff; *dDDR = 0xff; @@ -51,14 +52,13 @@ void floppy_setup(char *_pulse_port, char *_pulse_ddr, char *_direction_port, ch } //Return all FDDs to track 0 - for(uint8_t i = 0; i < 200; i++) { _delay_ms(5); *fPORT ^= 0xff; } - *dPORT = 0x00; + *dPORT = 0x00; //Head needs to be reversed *fPORT = 0xff; //Setup Timer diff --git a/floppyMusic/floppyMusic.componentinfo.xml b/floppyMusic/floppyMusic.componentinfo.xml index ebbfd74..886ee29 100644 --- a/floppyMusic/floppyMusic.componentinfo.xml +++ b/floppyMusic/floppyMusic.componentinfo.xml @@ -26,13 +26,13 @@ - C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\include\avr\iom8.h + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\include\avr\iom32.h header C - hDXIougjReqD1inJugv1UA== + lmy51QeNKtBwSFwznyeJmw== - include/avr/iom8.h + include/avr/iom32.h @@ -59,13 +59,13 @@ - C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega8 + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega32 libraryPrefix GCC - gcc/dev/atmega8 + gcc/dev/atmega32 @@ -74,7 +74,7 @@ C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.132/Atmel.ATmega_DFP.pdsc 1.2.132 true - ATmega8 + ATmega32 diff --git a/floppyMusic/floppyMusic.cproj b/floppyMusic/floppyMusic.cproj index 9c197cc..0ab48be 100644 --- a/floppyMusic/floppyMusic.cproj +++ b/floppyMusic/floppyMusic.cproj @@ -5,7 +5,7 @@ 7.0 com.Atmel.AVRGCC8.C dce6c7e3-ee26-4d79-826b-08594b9ad897 - ATmega8 + ATmega32 none Executable C @@ -40,7 +40,7 @@ com.atmel.avrdbg.tool.stk500 - 0x1E9307 + 0x1E9502 @@ -82,7 +82,7 @@ - -mmcu=atmega8 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega8" + -mmcu=atmega32 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega32" True True True @@ -120,7 +120,7 @@ - -mmcu=atmega8 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega8" + -mmcu=atmega32 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega32" True True True @@ -167,6 +167,18 @@ compile + + compile + + + compile + + + compile + + + compile + compile diff --git a/floppyMusic/main.c b/floppyMusic/main.c index 18e8dbf..7583bc8 100644 --- a/floppyMusic/main.c +++ b/floppyMusic/main.c @@ -5,28 +5,6 @@ * Author : Jonas */ - #define c 130 - #define d 147 - #define e 165 - #define f 175 - #define g 195 - #define gS 208 - #define a 220 - #define aS 228 - #define b 233 - #define cH 261 - #define cSH 277 - #define dH 294 - #define dSH 311 - #define eH 330 - #define fH 349 - #define fSH 370 - #define gH 390 - #define gSH 415 - #define aH 440 - - #define _GET_UBBR(BAUD) ( (F_CPU / 16 * BAUD) - 1) - #ifndef F_CPU #define F_CPU 16000000UL //CPU Running at 16MHz #endif @@ -34,139 +12,21 @@ #include #include "floppy.h" +#include "music.h" +#include "uart.h" -void imperial_march(); - -void beep(int _f, unsigned int _t); - -void delay_ms(unsigned int ms ); - - int main(void) { + uart_init(9600); floppy_setup(&PORTC, &DDRC, &PORTB, &DDRB); - - floppy_set_frequency(0, 0); - floppy_set_frequency(1, 0); - DDRD = 0xff; + DDRA = 0xff; + uart_send_string("Hallo\n"); while (1) { play_imperial_march(); _delay_ms(2000); + uart_send_string("Hallo\n"); } } -void delay_ms(unsigned int ms ) -{ - unsigned int i; - for (i = 0; i<= ms; i++) - _delay_ms(1); -} - -void play_imperial_march() -{ - beep(a, 500); - beep(a, 500); - beep(a, 500); - beep(f, 350); - beep(cH, 150); - beep(a, 500); - beep(f, 350); - beep(cH, 150); - beep(a, 650); - - delay_ms(150); - //end of first bit - - beep(eH, 500); - beep(eH, 500); - beep(eH, 500); - beep(fH, 350); - beep(cH, 150); - beep(gS, 500); - beep(f, 350); - beep(cH, 150); - beep(a, 650); - - delay_ms(150); - //end of second bit... - - beep(aH, 500); - beep(a, 300); - beep(a, 150); - beep(aH, 400); - beep(gSH, 200); - beep(gH, 200); - beep(fSH, 125); - beep(fH, 125); - beep(fSH, 250); - - delay_ms(250); - - beep(aS, 250); - beep(dSH, 400); - beep(dH, 200); - beep(cSH, 200); - beep(cH, 125); - beep(b, 125); - beep(cH, 250); - - delay_ms(250); - - beep(f, 125); - beep(gS, 500); - beep(f, 375); - beep(a, 125); - beep(cH, 500); - beep(a, 375); - beep(cH, 125); - beep(eH, 650); - - //end of third bit... (Though it doesn't play well) - //let's repeat it - - beep(aH, 500); - beep(a, 300); - beep(a, 150); - beep(aH, 400); - beep(gSH, 200); - beep(gH, 200); - beep(fSH, 125); - beep(fH, 125); - beep(fSH, 250); - - delay_ms(250); - - beep(aS, 250); - beep(dSH, 400); - beep(dH, 200); - beep(cSH, 200); - beep(cH, 125); - beep(b, 125); - beep(cH, 250); - - delay_ms(250); - - beep(f, 250); - beep(gS, 500); - beep(f, 375); - beep(cH, 125); - beep(a, 500); - beep(f, 375); - beep(cH, 125); - beep(a, 650); - //end of the song -} - -void beep(int _f, unsigned int _t) -{ - PORTD = ~ floppy_calc_freq(_f / 3); - floppy_set_frequency(0, floppy_calc_freq(_f / 3)); - floppy_set_frequency(1, floppy_calc_freq(_f / 3)); - delay_ms(_t); - PORTD = 0xff; - floppy_set_frequency(0, 0); - floppy_set_frequency(1, 0); - _delay_ms(10); -} \ No newline at end of file diff --git a/floppyMusic/midi.c b/floppyMusic/midi.c new file mode 100644 index 0000000..ff70a95 --- /dev/null +++ b/floppyMusic/midi.c @@ -0,0 +1,42 @@ +/* + * midi.c + * + * Created: 12.06.2017 20:43:47 + * Author: Jonas + */ + +#include "midi.h" + +void midi_setup() +{ + uart_init(9600); +} + +void midi_recieve(struct midi_command *_command) +{ + if(!(UCSRB & (1<> 4) & 0x0f; // Shift channel into first 4 bits; + note = data1; + velocity = data2; + + _command->command = command; + _command->channel=channel; + _command->note = note; + _command->velocity = velocity; + +} + +void midi_send(struct midi_command _command) +{ + +} \ No newline at end of file diff --git a/floppyMusic/midi.h b/floppyMusic/midi.h new file mode 100644 index 0000000..f30f1c4 --- /dev/null +++ b/floppyMusic/midi.h @@ -0,0 +1,34 @@ +/* + * midi.h + * + * Created: 12.06.2017 20:43:37 + * Author: Jonas + */ + + +#ifndef MIDI_H_ +#define MIDI_H_ + +#define _MIDI_SEND 0 +#define _MIDI_RECIEVE 1 + +#include "uart.h" + +struct midi_command +{ + char command; + char channel; + char note; + char velocity; +}; + + +void midi_setup(); + +void midi_recieve(struct midi_command *_command); + +void midi_send(struct midi_command _command); + + + +#endif /* MIDI_H_ */ \ No newline at end of file diff --git a/floppyMusic/music.c b/floppyMusic/music.c new file mode 100644 index 0000000..5dc644f --- /dev/null +++ b/floppyMusic/music.c @@ -0,0 +1,247 @@ +/* + * music.c + * + * Created: 12.06.2017 18:59:47 + * Author: Jonas + */ + + #include "music.h" + + void delay_ms(unsigned int ms ) + { + unsigned int i; + for (i = 0; i<= ms; i++) + _delay_ms(1); + } + + void play_imperial_march() + { + beep(a, 500); + beep(a, 500); + beep(a, 500); + beep(f, 350); + beep(cH, 150); + beep(a, 500); + beep(f, 350); + beep(cH, 150); + beep(a, 650); + + delay_ms(150); + //end of first bit + + beep(eH, 500); + beep(eH, 500); + beep(eH, 500); + beep(fH, 350); + beep(cH, 150); + beep(gS, 500); + beep(f, 350); + beep(cH, 150); + beep(a, 650); + + delay_ms(150); + //end of second bit... + + beep(aH, 500); + beep(a, 300); + beep(a, 150); + beep(aH, 400); + beep(gSH, 200); + beep(gH, 200); + beep(fSH, 125); + beep(fH, 125); + beep(fSH, 250); + + delay_ms(250); + + beep(aS, 250); + beep(dSH, 400); + beep(dH, 200); + beep(cSH, 200); + beep(cH, 125); + beep(b, 125); + beep(cH, 250); + + delay_ms(250); + + beep(f, 125); + beep(gS, 500); + beep(f, 375); + beep(a, 125); + beep(cH, 500); + beep(a, 375); + beep(cH, 125); + beep(eH, 650); + + //end of third bit... (Though it doesn't play well) + //let's repeat it + + beep(aH, 500); + beep(a, 300); + beep(a, 150); + beep(aH, 400); + beep(gSH, 200); + beep(gH, 200); + beep(fSH, 125); + beep(fH, 125); + beep(fSH, 250); + + delay_ms(250); + + beep(aS, 250); + beep(dSH, 400); + beep(dH, 200); + beep(cSH, 200); + beep(cH, 125); + beep(b, 125); + beep(cH, 250); + + delay_ms(250); + + beep(f, 250); + beep(gS, 500); + beep(f, 375); + beep(cH, 125); + beep(a, 500); + beep(f, 375); + beep(cH, 125); + beep(a, 650); + //end of the song + } + + void play_tetris() + { + beep(658, 125); + beep(1320, 500); + beep(990, 250); + beep(1056, 250); + beep(1188, 250); + beep(1320, 125); + beep(1188, 125); + beep(1056, 250); + beep(990, 250); + beep(880, 500); + beep(880, 250); + beep(1056, 250); + beep(1320, 500); + beep(1188, 250); + beep(1056, 250); + beep(990, 750); + beep(1056, 250); + beep(1188, 500); + beep(1320, 500); + beep(1056, 500); + beep(880, 500); + beep(880, 500); + _delay_ms(250); + beep(1188, 500); + beep(1408, 250); + beep(1760, 500); + beep(1584, 250); + beep(1408, 250); + beep(1320, 750); + beep(1056, 250); + beep(1320, 500); + beep(1188, 250); + beep(1056, 250); + beep(990, 500); + beep(990, 250); + beep(1056, 250); + beep(1188, 500); + beep(1320, 500); + beep(1056, 500); + beep(880, 500); + beep(880, 500); + _delay_ms(500); + beep(1320, 500); + beep(990, 250); + beep(1056, 250); + beep(1188, 250); + beep(1320, 125); + beep(1188, 125); + beep(1056, 250); + beep(990, 250); + beep(880, 500); + beep(880, 250); + beep(1056, 250); + beep(1320, 500); + beep(1188, 250); + beep(1056, 250); + beep(990, 750); + beep(1056, 250); + beep(1188, 500); + beep(1320, 500); + beep(1056, 500); + beep(880, 500); + beep(880, 500); + _delay_ms(250); + beep(1188, 500); + beep(1408, 250); + beep(1760, 500); + beep(1584, 250); + beep(1408, 250); + beep(1320, 750); + beep(1056, 250); + beep(1320, 500); + beep(1188, 250); + beep(1056, 250); + beep(990, 500); + beep(990, 250); + beep(1056, 250); + beep(1188, 500); + beep(1320, 500); + beep(1056, 500); + beep(880, 500); + beep(880, 500); + _delay_ms(500); + beep(660, 1000); + beep(528, 1000); + beep(594, 1000); + beep(495, 1000); + beep(528, 1000); + beep(440, 1000); + beep(419, 1000); + beep(495, 1000); + beep(660, 1000); + beep(528, 1000); + beep(594, 1000); + beep(495, 1000); + beep(528, 500); + beep(660, 500); + beep(880, 1000); + beep(838, 2000); + beep(660, 1000); + beep(528, 1000); + beep(594, 1000); + beep(495, 1000); + beep(528, 1000); + beep(440, 1000); + beep(419, 1000); + beep(495, 1000); + beep(660, 1000); + beep(528, 1000); + beep(594, 1000); + beep(495, 1000); + beep(528, 500); + beep(660, 500); + beep(880, 1000); + beep(838, 2000); + + } + + void beep(int _f, unsigned int _t) + { + PORTA = ~ floppy_calc_freq(_f / 3); + + floppy_set_frequency(0, floppy_calc_freq(_f /3) ); + floppy_set_frequency(1, floppy_calc_freq(_f /3) ); + + delay_ms(_t); + + PORTA = 0xff; + + floppy_set_frequency(0, 0); + floppy_set_frequency(1, 0); + + delay_ms(10); + } \ No newline at end of file diff --git a/floppyMusic/music.h b/floppyMusic/music.h new file mode 100644 index 0000000..68a3c1c --- /dev/null +++ b/floppyMusic/music.h @@ -0,0 +1,49 @@ +/* + * music.h + * + * Created: 12.06.2017 18:59:36 + * Author: Jonas + */ + + +#ifndef MUSIC_H_ +#define MUSIC_H_ + +#define c 130 +#define d 147 +#define e 165 +#define f 175 +#define g 195 +#define gS 208 +#define a 220 +#define aS 228 +#define b 233 +#define cH 261 +#define cSH 277 +#define dH 294 +#define dSH 311 +#define eH 330 +#define fH 349 +#define fSH 370 +#define gH 390 +#define gSH 415 +#define aH 440 + +#ifndef F_CPU +#define F_CPU 16000000UL //CPU Running at 16MHz +#endif + +#include +#include + +#include "floppy.h" + +void beep(int _f, unsigned int _t); + +void delay_ms(unsigned int ms ); + +void play_imperial_march(); + +void play_tetris(); + +#endif /* MUSIC_H_ */ \ No newline at end of file diff --git a/floppyMusic/uart.c b/floppyMusic/uart.c index aed8acd..3aac221 100644 --- a/floppyMusic/uart.c +++ b/floppyMusic/uart.c @@ -7,23 +7,20 @@ #include "uart.h" - void uart_init(uint32_t _baud) + void uart_init(unsigned int _baud) { - unsigned int ubrr = _GET_UBBR(_baud); + unsigned int ubrr = (F_CPU / (16 * _baud)) - 1; - UBRRH = (ubrr<<8); - UBRRL = ubrr; + UBRRH = (unsigned char)(ubrr>>8) & 0xff; + UBRRL = (unsigned char)ubrr & 0xff; - /* Enable receiver and transmitter */ UCSRB = (1< + #define _GET_UBBR(BAUD) ( (F_CPU / 16 * BAUD) - 1) -void uart_init(uint32_t _baud); +void uart_init(unsigned int _baud); void uart_send(char _data); @@ -25,4 +26,5 @@ void uart_send_string(char *_data); char uart_recieve(void); + #endif /* UART_H_ */ \ No newline at end of file -- cgit v1.2.3