-- ----------------------------------------------------------------------------- -- Example of sound tables, to be used with PLAY_MUSIC -- ----------------------------------------------------------------------------- -- Library for generating sounds, using TMR0 -- -- Use of this library -- make a local copy of this file in the program directory -- Then change the following, according to your needs -- define the IO pin -- define the frequency of each note in table1 -- define the duration of each note in table2 -- from the main program, include this file and call PLAY_SONG -- -- Author : Stef Mientki -- Version: 1.0 07-04-2002 orginal release -- ----------------------------------------------------------------------------- -- ---------------------------------------------------------------------------- -- ---------------------------------------------------------------------------- -- Define at which pin the piezo speaker will be mounted -- (a Piezo speaker may be mounted directly between IO pin and Ground) -- Remember that the IO pin must have a full push-pull circuit, -- so for instance RA4 on a 16F628 is not good enough. -- ---------------------------------------------------------------------------- -- ---------------------------------------------------------------------------- -- ---------------------------------------------------------------------------- -- This constant definies how the music is played, -- that is what is done in the interrupt and what's done outside -- or in other words -- it determines if you can do something during playing of the song -- by declaring it as an var, you can dynamically change between the 2 modes -- IF only one of the 2 modes is used, it's advised to define as a constant, -- it will preserve memory (not only this 1 byte !) -- ---------------------------------------------------------------------------- ;const play_music_mode_interrupt = true -- const bit play_music_mode_interrupt = false -- ---------------------------------------------------------------------------- -- ---------------------------------------------------------------------------- -- ---------------------------------------------------------------------------- const _BMS_table = 1 ;The number of tables (to save memory) -- ---------------------------------------------------------------------------- -- ---------------------------------------------------------------------------- -- ---------------------------------------------------------------------------- -- ---------------------------------------------------------------------------- -- table can be upto 254 bytes long, the name of the table may NOT be changed -- -- the tables contains 2 values per tone -- PERIOD -- DURATION -- -- the PERIOD must be calculated with the next formula -- constant = 1_000_000 / ( 60 * frequency[Hz] ) -- -- the DURATION must be calculated with the next formula -- constant = duration[msec] / 5 -- -- if PERIOD=0 and DURATION<>0 then a long pause is inserted -- -- if DURATION=0 the end of the song is indicated -- -- By these end-markers it's possible to store more songs or couplets into the tables -- (see the demo) -- ---------------------------------------------------------------------------- -- in this case, this table is not used, -- instead below is another table declared -- ---------------------------------------------------------------------------- procedure _table_tone_duration_1 is -- IMPERIAL pragma jump_table assembler addwf PCL,f retlw 75 retlw 80 retlw 0 retlw 27 retlw 75 retlw 80 retlw 0 retlw 27 retlw 75 retlw 80 retlw 0 retlw 27 retlw 95 retlw 54 retlw 0 retlw 27 retlw 63 retlw 27 retlw 75 retlw 80 retlw 0 retlw 27 retlw 95 retlw 54 retlw 0 retlw 27 retlw 63 retlw 27 retlw 75 retlw 161 retlw 0 retlw 54 retlw 50 retlw 80 retlw 0 retlw 27 retlw 50 retlw 80 retlw 0 retlw 27 retlw 50 retlw 80 retlw 0 retlw 27 retlw 47 retlw 54 retlw 0 retlw 27 retlw 63 retlw 27 retlw 80 retlw 80 retlw 0 retlw 27 retlw 95 retlw 54 retlw 0 retlw 27 retlw 63 retlw 27 retlw 75 retlw 161 retlw 0 retlw 54 retlw 37 retlw 80 retlw 0 retlw 27 retlw 75 retlw 54 retlw 0 retlw 27 retlw 75 retlw 27 retlw 37 retlw 54 retlw 0 retlw 54 retlw 40 retlw 54 retlw 0 retlw 27 retlw 42 retlw 27 retlw 45 retlw 27 retlw 47 retlw 27 retlw 45 retlw 54 retlw 0 retlw 54 retlw 71 retlw 27 retlw 0 retlw 27 retlw 53 retlw 54 retlw 0 retlw 54 retlw 56 retlw 54 retlw 0 retlw 27 retlw 60 retlw 27 retlw 63 retlw 27 retlw 67 retlw 27 retlw 63 retlw 54 retlw 0 retlw 54 retlw 95 retlw 27 retlw 0 retlw 27 retlw 80 retlw 54 retlw 0 retlw 54 retlw 95 retlw 54 retlw 0 retlw 27 retlw 80 retlw 27 retlw 63 retlw 80 retlw 0 retlw 27 retlw 75 retlw 54 retlw 0 retlw 27 retlw 63 retlw 27 retlw 50 retlw 161 retlw 0 retlw 54 retlw 37 retlw 80 retlw 0 retlw 27 retlw 75 retlw 54 retlw 0 retlw 27 retlw 75 retlw 27 retlw 37 retlw 54 retlw 0 retlw 54 retlw 40 retlw 54 retlw 0 retlw 27 retlw 42 retlw 27 retlw 45 retlw 27 retlw 47 retlw 27 retlw 45 retlw 54 retlw 0 retlw 54 retlw 71 retlw 27 retlw 0 retlw 27 retlw 53 retlw 54 retlw 0 retlw 54 retlw 56 retlw 54 retlw 0 retlw 27 retlw 60 retlw 27 retlw 63 retlw 27 retlw 67 retlw 27 retlw 63 retlw 54 retlw 0 retlw 54 retlw 95 retlw 27 retlw 0 retlw 27 retlw 80 retlw 54 retlw 0 retlw 54 retlw 95 retlw 54 retlw 0 retlw 27 retlw 63 retlw 27 retlw 75 retlw 80 retlw 0 retlw 27 retlw 95 retlw 54 retlw 0 retlw 27 retlw 63 retlw 27 retlw 0 retlw 0 retlw 0 retlw 0 end assembler end procedure procedure _table_tone_duration_2 is pragma jump_table assembler addwf PCL,f end assembler end procedure -- ---------------------------------------------------------------------------- -- second table -- if the table is not used, it doesn't have to be cleared, -- because due to _BMS_table=1 it will be stuffed away by the compiler. -- ---------------------------------------------------------------------------- -- ---------------------------------------------------------------------------- -- third table -- ---------------------------------------------------------------------------- -- ---------------------------------------------------------------------------- -- fourth table -- ---------------------------------------------------------------------------- procedure _table_tone_duration_4 is pragma jump_table assembler addwf PCL,f retlw 67 retlw 92 retlw 0 ; 0 = end of table retlw 0 ; double 0 , because duration is in second byte end assembler end procedure -- ---------------------------------------------------------------------------- -- fifth table -- ---------------------------------------------------------------------------- procedure _table_tone_duration_5 is pragma jump_table assembler addwf PCL,f retlw 67 retlw 92 retlw 0 ; 0 = end of table retlw 0 ; double 0 , because duration is in second byte end assembler end procedure -- ---------------------------------------------------------------------------- procedure _table_tone_duration_3 is pragma jump_table assembler addwf PCL,f retlw 67 retlw 92 retlw 0 ; 0 = end of table retlw 0 ; double 0 , because duration is in second byte end assembler end procedure -- ---------------------------------------------------------------------------- -- ---------------------------------------------------------------------------- -- ---------------------------------------------------------------------------- -- ---------------------------------------------------------------------------- -- here the actual sound generation routines are included -- ---------------------------------------------------------------------------- include play_music -- ----------------------------------------------------------------------------