MEL PICBASIC Forum - Candy Candy (Old Japanese cartoon) Melody with PIC12F675

• ### Recent Forum Posts

#### Re: Doing something at predefined amount of steps?

No, 200-300=65436.
65435 is -101 in two's complement because 65435+101 = 65536 which, when being truncated to 16 bits is 0.

If what you want is the difference between the two numbers while not...

HenrikOlsson Yesterday, 23:01

#### Re: Doing something at predefined amount of steps?

Thanks Henrik, so Say A=200 B=300, C in this case will be 65535-100=65435, right? So if I take 65535 and minus it result, I should receive correct difference between A and B, right?

CuriousOne Yesterday, 18:46

#### Re: Doing something at predefined amount of steps?

towlerg Yesterday, 18:13

#### Re: Doing something at predefined amount of steps?

It will wrap around, 0-1=65535 provided the variable where the result is stored is a WORD.

HenrikOlsson Yesterday, 17:23

#### Re: Doing something at predefined amount of steps?

Oh and by the way, currently I don't have access to machine with PBP, what will happen if C=A-B and B is > A ? all variables are word length. I need to determine difference between A and B, but...

CuriousOne Yesterday, 16:56

#### Re: Doing something at predefined amount of steps?

Yes, I meant exactly that one.

In my case, there will be 16F886 running at 8mhz and maximum frequency will be around 2khz, so I guess, modulo variant will also work. Will assemble test circuit...

CuriousOne Yesterday, 16:54

#### Re: Doing something at predefined amount of steps?

Wasn’t it just something like this?
not even timing of course because every fifth iteration takes slightly longer to execute, but could be balanced up if it mattered.

variable var word...

Art Yesterday, 15:30

#### Re: Doing something at predefined amount of steps?

I don't know for sure but since it involves division my guess is that this is slower. Speed isn't always everything though.

Tell you what, why don't you try both ways and measure the difference,...

HenrikOlsson Yesterday, 15:01

#### Re: Doing something at predefined amount of steps?

Thanks! this is way better and simpler. Speaking speed-wise, will this be faster in execution than my code with additional variable?

CuriousOne Yesterday, 14:42

#### Re: Newbie Manchester Coding question

Duh, yup, that was it [slapping forehead].

Cheers,

Troy

rocket_troy Yesterday, 14:22
• # 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                   *
'*  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
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```