Musical note using PIC16F84A (Assembly code)

Thread Starter

DonutChan

Joined Mar 3, 2019
33
Hey, it would be real nice if someone could show me how one note could be made let's say "Do". i did find a program but i don't quite understand how it works.. (piezo buzzer used for sound)

(variables)
CBLOCK H'0C'
CNT
CNT10
CNTM
ENDC


10MSEC

;***********************************************
DEL10M MOVLW 10
MOVWF CNT10

DLY10 MOVLW 142
MOVWF CNTM

DLYU GOTO $+1
GOTO $+1

DECFSZ CNTM,1
GOTO DLYU
DECFSZ CNT10,1
GOTO DLY10

RETURN
;**********************************************

DO_ BSF PORTA,3
MOVLW 67
MOVWF CNT
CALL DLY
GOTO $+1
GOTO $+1
NOP
BCF PORTA,3
MOVLW 67
MOVWF CNT
CALL DLY
GOTO $+1
BTFSS PORTB,0
GOTO DO_
RETURN
 

AlbertHall

Joined Jun 4, 2014
12,347
First thing to sort out is what frequency is 'Do'?
Then can calculate the period of the note - (1/frequency), call it P - then you set a pin high, wait P/2, set the pin low, wait P/2, and repeat until bored.
 

jpanhalt

Joined Jan 18, 2008
11,087
This might help with the frequencies and is fun to play with too: https://www.szynalski.com/tone-generator/

Years ago, a good friend gave me this code for a 10F2xx chip (base level). It should be adaptable to your chip easily and you can see how to make individual notes. Sorry to have to add as a edit, it took awhile to find.

Of course, just change the extension to .asm and it should open fine in your IDE.
 

Attachments

Last edited:

atferrari

Joined Jan 6, 2004
4,771
Maybe you know this already but the tone (DO in your case) will have a huge amount of harmonics. Far from a nice sound.

Good luck.
 
Top