How a speaker gen. a note?

Status
Not open for further replies.

chesskin

New Member
I have connected pin 1.0 to a 8ohm speaker through a op amp LM386.

Referring to lots of online resource.. if they want to generate a song, they would like to do so:

Song: DB 23h, 21h, 23h, 23h, 21h......
DB 23h, 21h, 23h, 23h, 21h......
DB 23h, 21h, 23h, 23h, 21h......
DB 23h, 21h, 23h, 23h, 21h......

and then acall a subroutine like that:

Sing:
......
MOV DPTR, #Song
SETB P1.0 ;TURN SPEAKER ON
MOV A, #0
MOVC A, @A+DPTR
INC DPTR
......

HERE IS MY DOUBT... that since P1.0 is only one bit can either be set it high or low, how can i send the song to this bit ??
And, after i move #Song to DPTR... and also ACC,
the song will automatically sing ??
Why do i send the notes to DPTR and ACC, but the speaker can sound out?
 
You have to generate an AC signal of the correct frequency, to do that turn the pin ON, delay half the wavelength, then turn it OFF again, delay another half wavelength, and turn it ON again - repeat for as long as you want the note to sound.

I've no idea what processor you're using, but a quick google should find you plenty of examples of generating sound.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…