Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

doubt regarding music generation using at89c51

Status
Not open for further replies.

bobdxcool

Member level 5
Member level 5
Joined
Mar 9, 2012
Messages
82
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
2,042
this is the circuit i'm planing to use to generate some msic using 8051..


pls tell me whether any other modifications are needed?


this is the program written!






Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<reg51.h>
sbit out=P1^0;  //output pin 1
 
void delay(unsigned char p,unsigned char q)
{
TMOD=0x01;  //timer0 mode1(16 bit)
TL0=q;      //load TL0
TH0=p;      //load TH0
TR0=1;   //turn on T0
while(TF0==0); // wait for flag generation
TR0=0;   // turn off T0
TF0=0;    // clear TF0
}
 
void play(unsigned char j,unsigned char k)
{
int i;
for(i=0;i<1000;i++)  //to play sound
{
  out=1;
  delay(j,k);
  out=0;
  delay(j,k);
}
}
 
void main()
{
int l;
while(1)
{
  play(0xfc,0x66);  //playing sound of frequency of about 500 hertz with a delay between two frequencies
  for(l=0;l<5;l++)   
  {
   delay(0x00,0x00);  //delay of 71 miliseconds
  }
  play(0xfe,0x33);  //playing sound of frequency of about 1000 hertz with a delay between two frequencies
  for(l=0;l<5;l++)
  {
   delay(0x00,0x00);  
  }
  play(0xff,0xa3);  //playing sound of frequency of about 5000 hertz with a delay between two frequencies
  for(l=0;l<5;l++)
  {
   delay(0x00,0x00);  
  }
  play(0xff,0xd1);  //playing sound of frequency of about 10000 hertz with a delay between two frequencies
  for(l=0;l<5;l++)
  {
   delay(0x00,0x00);  
  }
  play(0xff,0xdc);  //playing sound of frequency of about 13000 hertz with a delay between two frequencies
  for(l=0;l<5;l++)
  {
   delay(0x00,0x00);  
  }
  play(0xff,0xcc);  //playing sound of frequency of about 9300 hertz with a delay between two frequencies
  for(l=0;l<5;l++)
  {
   delay(0x00,0x00);  
  }
  play(0xff,0xe8);  //playing sound of frequency of about 20000 hertz with a delay between two frequencies
  for(l=0;l<5;l++)
  {
   delay(0x00,0x00);  
  }
} 
}





How to produce sound using microcontroller.gif
 
Last edited by a moderator:

Well, you are trying to generate the square wave signal on the appropriate pin.
This may play tones on a piezo. But I doubt that members might not call this "music".
Lets see.
 

Well, you are trying to generate the square wave signal on the appropriate pin.
This may play tones on a piezo. But I doubt that members might not call this "music".
Lets see.


so what if i place a 150 ohm speaker in place of the buzzer??
 

Don't use an ordinary speaker (low impedance) without an additional amplifier (single transistor will do). Rather use a piezo-type.

[Depends all on exact circuit. consider the port pull ups are present or not etc]

You better use an amplifire to hear something high. easyest way is to attach the base of a bipolar transistor to the pin and put the speaker in the collector circuit as a load. You can control the loudness and tons by using software PWM.
 
Last edited:

Don't use an ordinary speaker (low impedance) without an additional amplifier (single transistor will do). Rather use a piezo-type.

[Depends all on exact circuit. consider the port pull ups are present or not etc]

You better use an amplifire to hear something high. easyest way is to attach the base of a bipolar transistor to the pin and put the speaker in the collector circuit as a load. You can control the loudness and tons by using software PWM.

so i'll connect a speaker (1 terminal) to the collector of npn bc 547 transistor nd other terminal to ground.....nd connect base of tran to p1.0 and emitter to ground!!

correct me if i am wrong!!

between i have a 150 ohm speaker ..can it b used?? or should i go for an 8 ohm one only??

how to vary the loudness????
 

The 8051 port pin can sink 1.6mA (3.2mA for port 0) and source 60uA. Therefore, if you drive significant current, try to arrange your circuits to use current sinking.

See http://www.freewebs.com/maheshwankhede/ports.html for idea

You can choose any one option:-
1. Connect the speaker between the P1.0 pin and ground Do not omit series resistor 1K! [limit current as needed. check datasheet]

**broken link removed**

if you move the ground connection of the speaker to Vcc, you will get more volume.
[limit current as needed. check datasheet]

2.Use Transistor TO DRIVE SPEAKER

3.Use Transistor as directed and can control the loudness by using software PWM.
 

@papunblg

i am using a 4ohm 3 watt speaker and 2n3904 npn transistor as its driver.
i am connecting a 10k resistor b/w port of uc and base of 2n3904.the collector of the transistor i am connecting to 1 terminal of speaker,emitter to ground.
the other terminal of speaker should be grounded or should it be connected to VCC(5v of uc)??

correct me if i am wrong in other steps.
 

@papunblg

i am using a 4ohm 3 watt speaker and 2n3904 npn transistor as its driver.
i am connecting a 10k resistor b/w port of uc and base of 2n3904.the collector of the transistor i am connecting to 1 terminal of speaker,emitter to ground.
the other terminal of speaker should be grounded or should it be connected to VCC(5v of uc)??

correct me if i am wrong in other steps.


attachment.php


Here is an example. In place of the buzzer, you can connect a speaker

or

bb.GIF
72443d1334176344t-bb.gif
 
Last edited:

hanks a ton sir!

---------- Post added at 19:26 ---------- Previous post was at 17:44 ----------

instead of 12v can i connect it 5 volt??
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top