Homerzinho
New Member
Hi guys, my PIC is connected to a buzzer, and I want to make my code in way that when I press a button the frequency of the buzzer changes.
To change that frequency, I *MUST* use interrupts.
I use cc5x compiler.
I was thinking of something like:
I´m at school now and I can´t test the code.
I need some directions on how to make interrupts with variable timers, and some documentation on TIMERS in the cc5x compiler.
Thanks in advance, I really need to understand that.
----
My finished code looks like this now
To change that frequency, I *MUST* use interrupts.
I use cc5x compiler.
I was thinking of something like:
Code:
void interrupt isr() {
static volatile bit saved_dtr;
saved_dtr = dtr;
; // save the current status of dtr
; // disable reception of serial chars
dtr = B_HIGH;
if(TMR1IF) {
++tmr_aux;
TMR1IF = false;
PORTB.1=~PORTB.1;
}
dtr = saved_dtr;
; // restore the status of dtr
}
}
I´m at school now and I can´t test the code.
I need some directions on how to make interrupts with variable timers, and some documentation on TIMERS in the cc5x compiler.
Thanks in advance, I really need to understand that.
----
My finished code looks like this now
Code:
void interrupt isr(void)
{
if ( T0IF) /* TMR0 overflow interrupt */
{
CLK3=~CLK3; //The buzzer port
TMR0 = 0; // For reseting Timmer 0 value
T0IF = 0; /* reset Timmer 0 flag INTCON<2>*/
}
}
(...)
main()
(...)
T0CON = 0b.1100.0100;
TMR0 = 0; /* 256 @ 64 = 1.64ms/2 delay */
INTCON = 0xF0; // Enable interupt
(...)
/*the function I call if the button is pressed (Every time the button is pressed, the frequency should increase to a maximum then return to the first value)*/
void muda_p(void)
{
switch(T0CON)
{
case 0b.1100.0111: T0CON=0b.1100.0100; break;
case 0b.1100.0110: T0CON=0b.1100.0111; break;
case 0b.1100.0101: T0CON=0b.1100.0110; break;
case 0b.1100.0100: T0CON=0b.1100.0101; break;
}
}
Last edited: