Tricka90
Member level 1
- Joined
- Sep 2, 2013
- Messages
- 40
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 8
- Activity points
- 385
I'm trying to generate a little melody when my PIC 16F876 turns on. So I wrote in main(), before the while(1) cycle the following note sequence (I use MikroC):
...but it doesn't play the melody just one time! It repeat it forever! Also every repetition it seems like a little bit of code goes on! It looks like a PIC malfunction because if I reduce the lenght of the melody it works PERFECTLY! To be precise, if I stop at note number nine (Sound_Play(349,200) all it's ok, the melody ends and the program goes on correctly. But if I try to add another note it repeats all the melody forever! Do you know why this happens? Do you know how to work around this strange problem?
Code:
Sound_Play(523,600);
Sound_Play(262,200);
Sound_Play(349,400);
Sound_Play(523,600);
Sound_Play(262,200);
Sound_Play(294,200);
Sound_Play(349,200);
Sound_Play(523,200);
Sound_Play(349,200);
Sound_Play(294,400);
Sound_Play(523,600);
Sound_Play(233,200);
Sound_Play(349,400);
Sound_Play(466,600);
Sound_Play(349,200);
Sound_Play(233,400);
Sound_Play(440,200);
Sound_Play(349,200);
Sound_Play(233,400);
Sound_Play(440,1400);
Delay_ms(1000);
...but it doesn't play the melody just one time! It repeat it forever! Also every repetition it seems like a little bit of code goes on! It looks like a PIC malfunction because if I reduce the lenght of the melody it works PERFECTLY! To be precise, if I stop at note number nine (Sound_Play(349,200) all it's ok, the melody ends and the program goes on correctly. But if I try to add another note it repeats all the melody forever! Do you know why this happens? Do you know how to work around this strange problem?