• Candy Candy (Old Japanese cartoon) Melody with PIC12F675

    Hi, this is my implementation of the ending song of an anime serie of my childhood, please give a try...

    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:

    Code:
                 PIC12F675
        10uF        ___
         \]      -o|°  |o-
     .---|]-------o|   |o-
     |   /]+     -o|   |o-    LED
     |           -o|___|o----->|--.
     |                            |
     |                            |
     |                            |
     | +  __ /|                   |
     '---|  | | Small Speaker     |
     .---|__| |                   |
     |       \|                   |
     |                            |
     '----------------------------'
                    |
                   ===
                   GND
    Code:
    '****************************************************************
    '*  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,109,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
    This article was originally published in forum thread: Candy Candy (Old Japanese cartoon) Melody with PIC12F675 started by ivanrosales View original post