PDA

View Full Version : Candy Candy (Old Japanese cartoon) Melody with PIC12F675



ivanrosales
- 28th August 2011, 18:39
Hi, this is my implementation of the ending song of an anime serie of my childhood, please give a try...



'************************************************* ***************
'* Name : Candy12F675 *
'* Author : Ivan Rosales - Guadalajara, Jalisco, México *
'* Notice : Copyright (c) 2011 Ivan Rosales *
'* : All Rights Reserved *
'* Date : 31/07/2011 *
'* Version : 1.0 *
'* Notes : Reproduce la melodía "Ashita ga Suki", *
'* : de la serie infantil japonesa "Candy Candy" *
'************************************************* ***************
'Si se usa una pequeña bocina, poner un capacitor de
'10uF ó 22uF en serie con ésta.
'[Pin 2]___[+Cap 10uF-]___[+Bocina-]___Tierra
'Si se usa piezo-eléctrico, poner directo del pin 2 a tierra.
'Conectar un LED del Pin 5 a tierra.

'_________________________________________________ _______________
'Letra:
'En mi ventana veo brillar,
'las estrellas muy cerca de mí,
'cierro los ojos, quiero soñar,
'con un dulce porvenir...

'Quiero vivir y disfrutar,
'la alegría de la juventud,
'no habrá noche para mí,
'sin estrellas que den luz...

'Gira, gira, carrusel,
'tus ruedas de cristal
'recorriendo mil caminos
'tu destino encontrarás...

'Candy, Candy, Candy, Candy.
'_________________________________________________ _______________


'Configuración del PIC:
@ Device PIC12F675,WDT_ON,PWRT_ON,PROTECT_OFF,MCLR_OFF,BOD_ OFF
ansel=0 'No usar ADC's las entradas serán digitales
cmcon=7 'No usar comparadores analógicos
trisio=%011011 'GP2 y GP5 Serán salidas
DEFINE OSCCAL_1K 1 'Auto-Calibración del reloj interno

'Declaración de Variables:
LED var gpio.2
Piezo var gpio.5
Cont var byte
Nota var byte
Dur var byte
Largo var byte


'Programa Principal:
Pause 500 'Pausa de .5 Seg para inicializar bien el PIC
largo=149
Bucle:
if largo=149 then 'Arreglo para que repita el estribillo
largo=65 'Reproduce las primeras 65 notas
else
largo=149 'Reproduce todas las 149 notas
endif
for cont = 0 to largo
'Lista de las notas musicales, el 0 es silencio:
lookup cont,[98,0,98,0,98,0,98,0,98,0,94,0,90,0,98,0,_
98,0,98,0,98,0,102,0,99,0,98,0,98,0,99,0,94,0,_
94,0,94,0,98,0,99,0,99,0,99,0,98,0,94,0,90,0,_
90,0,98,0,94,0,90,0,88,0,94,0,90,0,_
105,0,105,0,105,0,105,0,108,0,109,0,108,0,_
105,0,102,0,102,0,102,0,108,0,105,0,_
98,0,102,0,99,0,98,0,94,0,_
105,0,108,0,109,0,105,0,_
105,0,108,0,109,0,105,0,_
105,0,108,0,109,0,111,0,_
109,0,108,0,109,0,109,0,108,0,109,0,109,0,108,0,10 9,0,111,0,108,0,109,0],nota
'Lista de las duraciones de cada nota y silencio:
lookup cont,[20,4,20,4,20,4,40,4,20,4,20,4,20,4,60,22,_
20,4,20,4,40,4,40,2,20,4,20,4,20,4,20,4,60,22,_
20,4,20,4,20,4,20,4,60,16,20,4,20,4,20,4,60,22,_
20,4,20,4,40,4,40,4,20,4,40,4,80,44,_
20,4,20,4,20,4,60,4,20,4,20,4,60,44,_
20,4,40,4,60,4,20,4,40,4,60,44,_
20,4,40,4,20,4,40,4,60,44,_
20,4,20,4,20,4,40,44,_
20,4,20,4,20,4,40,44,_
20,4,20,4,40,4,100,44,_
20,4,20,4,60,40,20,4,20,4,60,50,20,4,20,4,80,50,20 ,4,40,4,100,4],dur

if nota=0 then 'Arreglo para que encienda el LED al ritmo de la melodía
led=0
else
led=1
endif

Sound piezo,[nota,dur] 'Reproduce una nota (o silencio)
next
if largo=149 then pause 3000 'Si es el final de la melodía hace una pausa
Goto bucle 'Repite indefinidamente la melodía
end

lester
- 29th August 2011, 13:08
Re posted to Projects - 'Music' area

A schematic would be a great addition to the code example

thanks for your contribution

ivanrosales
- 31st August 2011, 15:05
Sorry, the schematic is very simple, you can use a small speaker with a 10uF - 22uF electrolitic capacitor in series or you can use a piezoelectric directly connected between pin 2 and ground:


PIC12F675
10uF ___
\] -o|° |o-
.---|]-------o| |o-
| /]+ -o| |o- LED
| -o|___|o----->|--.
| |
| |
| |
| + __ /| |
'---| | | Small Speaker |
.---|__| | |
| \| |
| |
'----------------------------'
|
===
GND

lester
- 1st September 2011, 05:44
Thanks, your project has been updated. its here (http://www.picbasic.co.uk/forum/content.php?r=424-Candy-Candy-%28Old-Japanese-cartoon%29-Melody-with-PIC12F675) Really appreciate your taking time to add the scematic. It maybe simple, but many beginners really need that little bit of extra info.

rsocor01
- 3rd September 2011, 01:29
ivanrosales,

Your project is too cool :D, so I had to give it a try. I made some changes to make it work with a PIC18F4550. Thank you.

Robert


http://www.youtube.com/watch?v=s-lBkHvDrxE

ivanrosales
- 3rd September 2011, 02:39
Nice implementation Robert!, the original melody's name is Ashita Ga Suki:


http://www.youtube.com/watch?v=t3nbaWpak1o

The PBP's Sound statement do all the trick, I just feed it with the result of the two lookup lists, one is for the PBP's Notes values an the other is for the duration (notes and silences).
In the "first pass" only the first 65 notes are played and then the whole 149.

rsocor01
- 4th September 2011, 02:18
The PBP's Sound statement do all the trick, I just feed it with the result of the two lookup lists, one is for the PBP's Notes values an the other is for the duration (notes and silences).
In the "first pass" only the first 65 notes are played and then the whole 149.

Yes, the code is pretty simple. The hard part, at least for me, is feeding the right note values and durations to the code. I guess that you have some knowledge in music theory.

ivanrosales
- 4th September 2011, 04:07
Robert, in fact I don't have music knowledge, what I did was somewhat cheating.
There is a nice Android app called xPiano, this app saves what you play in it as a txt file, then I made a "keyword" spreadsheet in excel to convert the xPiano notes to PBP's SOUND values this way I only have to figure out the durations...

Your mission Robert, should you decide to accept it is... ;)
Figure out the note durations for the Super Mario Bros. melody, you can find my spreadsheet with the notes and the "keyword" list for xPiano in this link: http://dl.dropbox.com/u/29237304/xPiano-PIC.xls

Kind regards.

Ivan.

Acetronics2
- 4th September 2011, 17:03
Hi, Ivan

Your mission is to make a search on this Forum with the "BeepMaster" Keyword ...

And Robert will be rid of that terrible curse ...

Alain

ivanrosales
- 4th September 2011, 21:41
Wow! :eek:
Alain, the BeepMaster project from flipper_md is very clever indeed, but with it you will kill the "Hand Made" fun for Robert ;)

Thanks for point us towards the right direction!

When the "light" slaps my face this way, I feel pretty the same than when my big brother told me that "Santa" doesn't exists...

Regards.

Ivan.

Acetronics2
- 5th September 2011, 17:01
Wow! :eek:


When the "light" slaps my face this way, I feel pretty the same than when my big brother told me that "Santa" doesn't exists...

Regards.

Ivan.

Hi, Ivan ...

Santa exists ... I did meet him here : http://www.santaclausvillage.info/

just look : http://www.santaclausvillage.info/?page_id=1462

Alain

ivanrosales
- 6th September 2011, 04:52
Alain, thank you soooo much, you made my day!!!
It makes me "Return to Innocence" (And not, I'm not affiliated in any way to Enigma) :D

johnn34
- 2nd March 2012, 13:38
I read all series of candy candy novel and I also watch this cartoon.candy is life loving and cheerful character.

Japanese cartoon (http://www.japanesecartoons.org/)

jorgepablo
- 13th August 2012, 00:16
Genial Ivan, gracias por el proyecto, me encanto volver a oir esa cancion, estoy preparandola para un pic 16f84a.
Supongo que como sos de mexico hablas español.
¿La cancion la copiaste a oido?, ¿o utilizaste alguna partitura para hacerlo?, estoy pensando en preparar otras melodias