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.