diff options
-rw-r--r-- | .vs/floppyMusic/v14/.atsuo | bin | 54784 -> 74240 bytes | |||
-rw-r--r-- | floppyMusic/floppy.c | 6 | ||||
-rw-r--r-- | floppyMusic/floppyMusic.componentinfo.xml | 12 | ||||
-rw-r--r-- | floppyMusic/floppyMusic.cproj | 20 | ||||
-rw-r--r-- | floppyMusic/main.c | 152 | ||||
-rw-r--r-- | floppyMusic/midi.c | 42 | ||||
-rw-r--r-- | floppyMusic/midi.h | 34 | ||||
-rw-r--r-- | floppyMusic/music.c | 247 | ||||
-rw-r--r-- | floppyMusic/music.h | 49 | ||||
-rw-r--r-- | floppyMusic/uart.c | 15 | ||||
-rw-r--r-- | floppyMusic/uart.h | 4 |
11 files changed, 412 insertions, 169 deletions
diff --git a/.vs/floppyMusic/v14/.atsuo b/.vs/floppyMusic/v14/.atsuo Binary files differindex c49928c..afdd2ba 100644 --- a/.vs/floppyMusic/v14/.atsuo +++ b/.vs/floppyMusic/v14/.atsuo 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 @@ <SourcePath></SourcePath> </d4p1:anyType> <d4p1:anyType i:type="FileInfo"> - <AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\include\avr\iom8.h</AbsolutePath> + <AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\include\avr\iom32.h</AbsolutePath> <Attribute></Attribute> <Category>header</Category> <Condition>C</Condition> - <FileContentHash>hDXIougjReqD1inJugv1UA==</FileContentHash> + <FileContentHash>lmy51QeNKtBwSFwznyeJmw==</FileContentHash> <FileVersion></FileVersion> - <Name>include/avr/iom8.h</Name> + <Name>include/avr/iom32.h</Name> <SelectString></SelectString> <SourcePath></SourcePath> </d4p1:anyType> @@ -59,13 +59,13 @@ <SourcePath></SourcePath> </d4p1:anyType> <d4p1:anyType i:type="FileInfo"> - <AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega8</AbsolutePath> + <AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega32</AbsolutePath> <Attribute></Attribute> <Category>libraryPrefix</Category> <Condition>GCC</Condition> <FileContentHash i:nil="true" /> <FileVersion></FileVersion> - <Name>gcc/dev/atmega8</Name> + <Name>gcc/dev/atmega32</Name> <SelectString></SelectString> <SourcePath></SourcePath> </d4p1:anyType> @@ -74,7 +74,7 @@ <PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.132/Atmel.ATmega_DFP.pdsc</PackPath> <PackVersion>1.2.132</PackVersion> <PresentInProject>true</PresentInProject> - <ReferenceConditionId>ATmega8</ReferenceConditionId> + <ReferenceConditionId>ATmega32</ReferenceConditionId> <RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> <d4p1:string></d4p1:string> </RteComponents> 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 @@ <ProjectVersion>7.0</ProjectVersion> <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName> <ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid> - <avrdevice>ATmega8</avrdevice> + <avrdevice>ATmega32</avrdevice> <avrdeviceseries>none</avrdeviceseries> <OutputType>Executable</OutputType> <Language>C</Language> @@ -40,7 +40,7 @@ </AsfFrameworkConfig> <avrtool>com.atmel.avrdbg.tool.stk500</avrtool> <avrtoolserialnumber /> - <avrdeviceexpectedsignature>0x1E9307</avrdeviceexpectedsignature> + <avrdeviceexpectedsignature>0x1E9502</avrdeviceexpectedsignature> <custom> <ToolOptions> <InterfaceProperties> @@ -82,7 +82,7 @@ <PropertyGroup Condition=" '$(Configuration)' == 'Release' "> <ToolchainSettings> <AvrGcc> - <avrgcc.common.Device>-mmcu=atmega8 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega8"</avrgcc.common.Device> + <avrgcc.common.Device>-mmcu=atmega32 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega32"</avrgcc.common.Device> <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex> <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss> <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep> @@ -120,7 +120,7 @@ <PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <ToolchainSettings> <AvrGcc> - <avrgcc.common.Device>-mmcu=atmega8 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega8"</avrgcc.common.Device> + <avrgcc.common.Device>-mmcu=atmega32 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega32"</avrgcc.common.Device> <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex> <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss> <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep> @@ -167,6 +167,18 @@ <Compile Include="main.c"> <SubType>compile</SubType> </Compile> + <Compile Include="midi.c"> + <SubType>compile</SubType> + </Compile> + <Compile Include="midi.h"> + <SubType>compile</SubType> + </Compile> + <Compile Include="music.c"> + <SubType>compile</SubType> + </Compile> + <Compile Include="music.h"> + <SubType>compile</SubType> + </Compile> <Compile Include="uart.c"> <SubType>compile</SubType> </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 <avr/io.h> #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<<RXEN))) //Return if UART reciever not enabled + return; + + char status, data1, data2; + char command, channel, note, velocity; + + status = uart_recieve(); + data1 = uart_recieve(); + data2 = uart_recieve(); + + command = status & 0x0f; //Mask out last 4 bits + channel = (status >> 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 <avr/io.h> +#include <util/delay.h> + +#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<<RXEN)|(1<<TXEN); - - /* Set frame format: 8data, 2stop bit */ UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0); } void uart_send(char _data) { - while(!(UCSRA & (1<<UDRE))); + while(!(UCSRA & (1<<UDRE))); //Wait for previous data to be sent UDR = _data; } @@ -40,7 +37,7 @@ char uart_recieve() { - while(!(UCSRA & (1<<RXC))); + while(!(UCSRA & (1<<RXC))); //Wait for data return UDR; } diff --git a/floppyMusic/uart.h b/floppyMusic/uart.h index 4943af9..1954357 100644 --- a/floppyMusic/uart.h +++ b/floppyMusic/uart.h @@ -15,9 +15,10 @@ #include <avr/io.h> + #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 |