Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 18th October 2003, 01:01 AM   (permalink)
Default monotone melody using buzzer

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
rrb011270 is offline  
Old 18th October 2003, 11:33 AM   (permalink)
Default 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.
trutan is offline  
Old 18th October 2003, 02:01 PM   (permalink)
Default

Quote:
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.
__________________
\"Basically, I no longer work for anything but the sensation I have while working.\"
- Albert Giacometti
RonDumas is offline  
Old 18th October 2003, 02:28 PM   (permalink)
Default

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.)
trutan is offline  
Old 20th October 2003, 01:52 AM   (permalink)
Default

Anyone have done using ANSI C or any C-Language?

Quote:
Originally Posted by trutan
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.)
rrb011270 is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 09:15 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker