Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

monotone melody using buzzer

Status
Not open for further replies.

rrb011270

New Member
Mabuhay!

I have a PIC system and I am planning to integrate a monotone melody using a buzzer...

Can anyone help me? a code snippet will do....

Thnx
 
Mabuhay rin sa'yo

If your using a buzzer (like the sonalert ones from Alexan) all you do is apply a voltage across the leads. It already has a built in oscillator/drive circuit.

But if you all you have is a ceramic disk or a speaker and would want to use the PIC to pulsout a ceratin frequency. Here's some codes:

The easiest is to use PICBASIC. (Download it from sonsivri.com.)
All you do is use the FREQOUT command:

__________________________________


FREQOUT portb.1, 500, 528 ' Output to portb pin1, for 500 msec,
' 528hz, which is the note C.

__________________________________



Before, I actually did it in assembly, which is about ten times
more 'econimical' that the PICBASIC equivalent.

__________________________________

; Variable

d3 equ 0X0F ; Variable used to count the number of
; cycles in the duration the sound is
; played.
; d3 = 528 * duration of sound (sec)

; Play sound

MOVLW 0X108 ; Put the value 108h (decimal, 264)
MOVWF d3 ; to d3. A 528hz freq completes 264
; cycles in 500 msec.
Call C1

; C2 Subroutine

C2
BSF PORTB,1 ; High portb pin1.
Call C2_0 ; Call delay subroutine
BCF PORTB,1 ; Low portb pin1.
Call C2_0 ; Call delay subroutine
DECFSZ d3, f ; Decrement d3
goto C2 ; Goto to C2. If d3 is zero
RETURN ; end subroutin

; Delay routine for the on-off sequence

C2_0
MOVLW 0xBD
MOVWF d1
MOVLW 0x01
MOVWF d2

C2_1
DECFSZ d1, f
goto $+2
DECFSZ d2, f
goto C2_1
goto $+1
goto $+1
RETURN

______________________________________



Hope this helps.
 
Before, I actually did it in assembly, which is about ten times
more 'econimical' that the PICBASIC equivalent.

Do you mean it is easier in assembly or picBasic?
I've wanted to learn assembly but was lead to believe it wasn't easier to program in than basic.
 
I meant that a program in assembly, while more complicated to do,
typically uses up less program memory--economical.

But programming in PICBASIC is far easier. In fact now I program exclusively in PICBASIC and have cut my programming time a great deal.

I find that trading off some memory 'real estate' is worth the time savings.

/John


(I ckecked: In the examples above, the code in assembly saves 31 words.)
 
Anyone have done using ANSI C or any C-Language?

trutan said:
I meant that a program in assembly, while more complicated to do,
typically uses up less program memory--economical.

But programming in PICBASIC is far easier. In fact now I program exclusively in PICBASIC and have cut my programming time a great deal.

I find that trading off some memory 'real estate' is worth the time savings.

/John


(I ckecked: In the examples above, the code in assembly saves 31 words.)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top