We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
i am a noob and learning 8051 coding. i want to know how can i use PWM to write a speaker which can emit diff sound (do,re,mi,etc.) by using 2 pins only. thanks.
if possible, i want a sample source code. thanks.
Start Here:
www.8052.com/.../120112 - links to see the so-called "bible" for the 8051
See also: http://www.8052.com/tutorial
And: http://www.keil.com/books/8051books.asp
And, of course, the Datasheet and the Manufacturer's website for the particular chip that you are using...
can you provide a example code for me please?
HI.
here is start. make sound with p1.0. u must improv
call using sound(int Cycles, char delay); sound: mov dph,r6 mov dpl,r7 loop: cpl p1.0 mov a,r5 mov r2,a djnz R2,$ clr P1.0 mov r2,#10 djnz R2,$ inc dptr mov a,dpl mov b,dph jnz loop ret
Always yo're freind.
Zeusti.
sorry but got last a bit wrong :(
sound(int Cycles, char delay); sound: mov dph,r6 mov dpl,r7 loop: cpl p1.0 mov a,r5 mov r2,a djnz R2,$ inc dptr mov a,dpl mov b,dph jnz loop ret
thanks you very much, i also want to ask how to connect the speaker to the 8051? +ve to the p1.0, and the -ve to the gnd? any other components needed?
if u use a (example 8 ohm) speeker u will need a drivor, ieg a transistor and stuff.
u can use a piezo. won pin on p1.0 and won on ov.
sound(int Cycles, char delay); this isn't asm code, how to call this function? or is it useful for the prog.?
u r write. it is a prototype for the asm function. u put in c and call in c.
Zeusti
who can, even in their wildes imagination, believe that a noob will, in any minuscule way, understand uncommented scribbles?
Erik
his 'advice' has always been questionable, now his English(?) is unreadable as well.
i no people will complain bout my style but here is code with my comments
;=================================================== ; ; Name : DoNote ; ; Purpose : Produce a sound on P1.0 ; ; Parameters : int Cycles (R6:R7) ; unsigned char Delay (R5) ; ; Result : void ; ;=================================================== ?PR?DoNote?sound segment code rseg ?PR?DoNote?sound DoNote: clr a ; Get 0-'Cycles' clr c ; Bcoz code uses up counter subb a,r7 ; And store to dptr mov dpl,a clr a subb a,r6 mov dph,a mov dpl,a Dn_1: cpl p1.0 ; Toggle the port pin mov a,r5 ; Get 'Delay' mov r2,a ; Loop for 'Delay' djnz R2,$ inc dptr ; Update cycle counter mov a,dpl ; While count is not overflowed or a,dph jnz Dn_1 ; Loop ret
in yo're c do this
extern void DoNote ( int Cycles, char delay ); void DoNote ( void ) { DoNote ( }
so there is a donation more than others.
two many things to do here!
extern void DoNote ( int Cycles, char delay ); void foo ( void ) { DoNote ( 10000, 10 ); }
Zeusti,
I'll make no comments about your comments, but I noticed a little error in your code:
;=================================================== ; ; Name : DoNote ; ; Purpose : Produce a sound on P1.0 ; ; Parameters : int Cycles (R6:R7) ; unsigned char Delay (R5) ; ; Result : void ; ;=================================================== ?PR?DoNote?sound segment code rseg ?PR?DoNote?sound DoNote: clr a ; Get 0-'Cycles' clr c ; Bcoz code uses up counter subb a,r7 ; And store to dptr mov dpl,a clr a subb a,r6 mov dph,a ; mov dpl,a <<< I think this should not be here Dn_1: cpl p1.0 ; Toggle the port pin mov a,r5 ; Get 'Delay' mov r2,a ; Loop for 'Delay' djnz R2,$ inc dptr ; Update cycle counter mov a,dpl ; While count is not overflowed or a,dph jnz Dn_1 ; Loop ret
you are write. sorry.
so so many things to do here!