Download filezillafor windows
'----[MAIN PROGRAM CODE]------------------------------------------------------------ MAIN_PROGRAM_LOOP: InputPORTB ' Remove any loading to the capacitors PORTB= 255 ' Set all pins of PORTB high NOTE_1_COUNTER = 0 ' \ NOTE_2_COUNTER = 0 ' Clear note counters for all channels NOTE_3_COUNTER = 0 ' / T1CON= %00000001 ' Turn on Timer1, prescaler = 1:1
PIR1.0= 0 ' Clear TMR1 interrupt flag
PIE1.0= 1 ' Enable TMR1 as peripheral interrupt source
INTCON= %01000000 ' Keep global interrupts disabled, TMR1 will trigger interrupts CHANNEL_INFO = 0 ' Clear all the channel finished flags TRACK_1_DATA = TRACK_1 ' Point TRACK_1_DATA to the music info for TRACK 1 GosubREAD_NOTE_DATA_FOR_CHANNEL1 ' Read the initial times and NOTE_1 data TRACK_2_DATA = TRACK_2 ' Point TRACK_2_DATA to the music info for TRACK 2 GosubREAD_NOTE_DATA_FOR_CHANNEL2 ' Read the initial times and note data TRACK_3_DATA = TRACK_3 ' Point TRACK_3_DATA to the music info for TRACK 3 GosubREAD_NOTE_DATA_FOR_CHANNEL3 ' Read the initial times and note data TICKS = 0 ' Reset the ticks counter before we enter the loop While1= 1 ' Create an infinite loop to play the music score NOTE_STATUS = 255 ' Set all notes to OFF by default IfTICKS = CHANNEL1_TIME_ON Then ' Have we reached a NOTE_ON time for channel 1? IfCHANNEL_1_NOTE <> 0Then ' Check if there is a note to play GIE= 1 ' Enable the interrupts if channel 1 is to play GosubPLAY_NOTE_1 ' Play the note held in CHANNEL_1_NOTE GosubREAD_NOTE_DATA_FOR_CHANNEL1 ' Read the next time and note data Endif
ElseIfCHANNEL1_TIME_ON = 0Then ' Have we reached the end of TRACK 1 ? CHANNEL_1_FINISHED = 1 ' Yes. So signal that TRACK 1 is finished Endif IfTICKS = CHANNEL2_TIME_ON Then ' Have we reached a NOTE_ON time for channel 2? IfCHANNEL_2_NOTE <> 0Then ' Check for channel 2 music data finished GIE= 1 ' Enable the interrupts if channel 2 is to play GosubPLAY_NOTE_2 ' Play the note held in CHANNEL_2_NOTE GosubREAD_NOTE_DATA_FOR_CHANNEL2 ' Read the next time and note data Endif
ElseIfCHANNEL2_TIME_ON = 0Then ' Have we reached the end of TRACK 2 ? CHANNEL_2_FINISHED = 1 ' Yes. So signal that TRACK 2 is finished Endif IfTICKS = CHANNEL3_TIME_ON Then ' Have we reached a NOTE_ON time for channel 3? IfCHANNEL_3_NOTE <> 0Then ' Check for channel 3 music data finished GIE= 1 ' Enable the interrupts if channel 3 is to play GosubPLAY_NOTE_3 ' Play the note held in CHANNEL_3_NOTE GosubREAD_NOTE_DATA_FOR_CHANNEL3 ' Read the time and note data Endif
ElseIfCHANNEL3_TIME_ON = 0Then ' Have we reached the end of TRACK 3 ? CHANNEL_3_FINISHED = 1 ' Yes. So signal that TRACK 3 is finished Endif ' Exit the loop if all the channels are finished IfCHANNEL_INFO = %00000111ThenBreak TRIGGER_NOTE_1 = NOTE_1_TO_PLAY ' \ TRIGGER_NOTE_2 = NOTE_2_TO_PLAY ' Enable/Disable the chimes for the three notes TRIGGER_NOTE_3 = NOTE_3_TO_PLAY ' / Delayus2000 ' Delay to allow the capacitors to charge InputPORTB ' Turn OFF the notes Delayus4000 ' Delay for the tempo of the tune IncTICKS ' Increment the TICKS counter Wend