This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LPC2104 buzzer control

Hello,

Can anyone explain to me how to control buzzer via timer interrupts? I want to play different tones on a buzzer using timer interrupts. So far I have this code:

Init timer:

          //initialize and start Timer #0
          T1TCR = 0x00000002;                           //disable and reset Timer0
          T1PC  = 0x00000000;                           //no prescale of clock
          T1MR0 = FOSC / notes[note];             //calculate no of timer ticks 7.6ms
          T1IR  = 0x000000ff;                           //reset all flags before enable IRQs
          T1MCR = 0x00000003;                           //reset counter and generate IRQ on MR0 match

          //initialize VIC for Timer0 interrupts
          VICIntSelect &= ~0x20;           //Timer1 interrupt is assigned to IRQ (not FIQ)
          VICVectAddr5  = (tU32)timer1ISR; //register ISR address
          VICVectCntl5  = 0x25;            //enable vector interrupt for timer0
          VICIntEnable  |= 0x20;            //enable timer1 interrupt
          T1TCR = 0x00000001;                           //start Timer1

timerISR:

tU16 notes[] = {262, 294, 330, 349, 392, 440, 494, 523}; //C D E F G A B C
int note = 0;
static void timer1ISR(void)
{
        if(note < 8)
                note++;
        else
                note = 0;

                setLED(LED_GREEN, toggleC == 0 ? FALSE : TRUE);
                setBuzzer(toggleC == 0 ? FALSE : TRUE);
                toggleC = ~toggleC;
                countC++;
                if(countC == notes[note])
                {
                        T1TCR = 0x02;
                        T1MR0 = FOSC / notes[note];
                        T1TCR = 0x01;
                        countC = 0;
                }

        T1IR        = 0x000000ff;        //reset all IRQ flags
        VICVectAddr = 0x00000000;        //dummy write to VIC to signal end of interrupt
}

But it only gives me only one tone and I don't know why :( I'm new to ES programming :(

0