Download filezillafor windows
'----[INTERRUPT HANDLER]------------------------------------------------ NOTE_INT: TIMER1= 65490   ' Load TMR1 with a preset value IncNOTE_COUNTER    ' Increment the note counter    IfNOTE_COUNTER > NOTE Then ' Is it time to toggle the pin ? TRISB= TRISB^ 1   ' Toggle pin PORTB.0 ClearNOTE_COUNTER ' Clear the note counter Endif
ClearPIR1.0
' Clear TMR1 interrupt flag RetfieFAST   ' Exit the interrupt         '----[MAIN PROGRAM CODE]--------------------------------------------------         OVER_INTERRUPT:
InputPORTB.0
' Make PORTB.0 and Input SetPORTB.0   ' And set it high ClearNOTE_COUNTER ' Reset the note counter T1CON= %00000001                   ' Turn on TIMER1, with a 1:1 prescaler ClearPIR1.0                        ' Clear TMR1 interrupt flag
SetPIE1.0                          ' Enable TMR1 as peripheral interrupt source    
INTCON=  %11000000              ' Enable global interrupts, peripheral interrupts          ' Play DING chime NOTE = 110    ' Set the frequency of the first chime HighTRIGGER ' Start charging the capacitor Delayms40    ' Allow time for the capacitor to charge InputTRIGGER ' Release the capacitor and let it discharge naturally          Delayms300   ' Delay between chimes          ' Play DONG chime          NOTE = 139    ' Set the frequency of the second chime HighTRIGGER ' Start charging the capacitor Delayms40    ' Allow time for the capacitor to charge InputTRIGGER ' Release the capacitor and let it discharge naturally Stop Now let’s take a look at how the program works. The TIMER1 note generating interrupt is set up the same as the previous pro-
gram, but instead of toggling the port’s pin directly, the direction port (TRISB.0)
is toggled from input to output and vice-versa. This imitates an open collector
output on PORTB.0, which is required to allow the capacitor to be charged via
PORTB.4. A square wave is still produced from PORTB.0 but it is not    udible
yet. PORTB.0 is set at the start of the main program loop so that when the in-
terrupt generator makes the pin an output, it will be output high.
PORTB.0  is  connected  to  an  electrolytic  capacitor  (C1)  via  a  reasonably  high
value  resistor  (R2  which  is  100KW  in
                                                                      this  case).  This  will  ensure  that  the    a-
pacitor’s charge is not dissipated too much by the toggling of PORTB.0.  
PORTB.4 is used to trigger an envelope and produce a chime by momentarily
charging capacitor C1 through resistor R1. This is accomplished by setting the
pin to OUTPUT HIGH, waiting a few tens of milliseconds, then setting the pin
as an INPUT, thus reducing any load from the pin. While C1 remains charged,
the note being produced from pin PORTB.0 will sound, and as C1 discharges,
the note will diminish in volume.
Home | Previous Page | Next Page