Download filezillafor windows
Two’s Company, Three’s a Chord. We now have the means of producing a pleasant sounding note, but one note
does not make a pleasant sounding tune. For that we need at least two notes,
one for the melody and another for a bass line, or harmony, this is named
polyphonic sound. Adding an extra note or two to the original chime program is
very simple, it just requires identical routines within the interrupt handler, one
for each note needed. However, the main program is already slowed down
somewhat by the requirements of a single note, so it’s best not to get carried
away, so we’ll add an extra two notes, making three in all. The program listing below produces a chord made up of three individual notes. ' Program 3_NOTE_CHORD.BAS
' Play three notes simultaneously to form a chord
' Device= 18F452 XTAL= 20 DimNOTE_1_COUNTER asWordSYSTEM ' Determines when pin for channel 1 is toggled
DimNOTE_1 asWordSYSTEM ' Determines the pitch of the note DimNOTE_2_COUNTER asWordSYSTEM ' Determines when pin for channel 2 is toggled DimNOTE_2 asWordSYSTEM ' Determines the pitch of the note DimNOTE_3_COUNTER asWordSYSTEM ' Determines when pin for channel 3 is toggled
DimNOTE_3 asWordSYSTEM ' Determines the pitch of the note SymbolTRIGGER = PORTB
DimTIMER1asTMR1L.Word ' Combine TMR1L/TMR1H into 16-bit variable TIMER1 ON_INTERRUPTGotoNOTE_INT ' Point the hardware interrupt to the interrupt handler Delayms100 ' Wait for the PICmicro to stabilise ALL_DIGITAL= True ' Set PORTA and PORTE to all digital mode LowPORTB ' Discharge the capacitors before we start LowPORTA ' Make all of PORTA outputs to help discharge the capacitors Delayms500 ' Jump over the interrupt handling subroutine and the general subroutines GotoMAIN_PROGRAM_LOOP '----[INTERRUPT HANDLER TO PLAY THREE NOTES]---------------------------------------- NOTE_INT: TIMER1= 65460 ' Load TMR1 to increase the interrupt interval IncNOTE_1_COUNTER ' \ IncNOTE_2_COUNTER ' Increment each channel's toggle counter IncNOTE_3_COUNTER ' / ' Note generator for channel 1
IfNOTE_1_COUNTER >= NOTE_1 Then ' Is it time to toggle PORTA.0 ? TRISA= TRISA^ 1 ' Yes. So XOR with 1 to toggle the pin ClearNOTE_1_COUNTER ' And reset the toggle counter Endif
' Note generator for channel 2
IfNOTE_2_COUNTER >= NOTE_2 Then ' Is it time to toggle PORTA.1 ? TRISA= TRISA^ 2 ' Yes. So XOR with 2 to toggle the pin ClearNOTE_2_COUNTER ' And reset the toggle counter Endif
' Note generator for channel 3
IfNOTE_3_COUNTER >= NOTE_3 Then ' Is it time to toggle PORTA.2 ? TRISA= TRISA^ 4 ' Yes. So XOR with 4 to toggle the pin ClearNOTE_3_COUNTER ' And reset the toggle counter Endif ClearPIR1.0 ' Clear TMR1 interrupt flag RetfieFAST ' Return from the interrupt and restore WREG, BSR and STATUS