-
Junior Member
Help with 8051 Music Program
I'm building a project that will play a tune. My rough pseudocode is below.
Main Question: I'm thinking I will store 3 bytes per note in the DB
First byte = note
Second & Third byte = Timer setting for square wave for the selected note. With timer set to 8100H, I get a nice note with a GP transistor driving a small speaker, but I have no idea how far up or down to set the timer for higher/lower notes.
Here is the rough idea:
Pseudocode:
Set data pointer
AGAIN:
until data retrieved = 00H
get next_note from A+DPTR
get note_duration from A+DPTR
move next byte to TL1
inc DPTR
move next byte to TH1
PLAY_NOTE:
SETB TR1 ;start Timer
BACK: (loop here to play the selected note)
JNB TF1, BACK ;while TF1 is zero wait here
CLR TR1 ;stop timer
CPL P2.7 ;complement P2.7 (Output to speaker)
CLR TF1 ;TF1 = 0
SJMP AGAIN
DATA:
DB G, 90h, 80h, G, 90h, 80h, C, a0h, ffh(First few notes of song), 00
(Notes can be characters or integers. Which best?)
END
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
Bookmarks