Interrupcion por Timer
Ejemplo de uso, un timer que cada cierta cantidad de tiempo cambia de estado el valor de un pin, el LED en este caso:
volatile boolean l;
void TC0_Handler(){
long status=REG_TC0_SR0;
l=!l;
}
void setup(){
pinMode(13,OUTPUT); //LED
pinMode(2,OUTPUT); //TIOA0 => Pin B.25
analogWrite(2,255);//??
REG_PIOB_PDR=0x2000000;//Pin 25 free from GPIO to peripheral use of timer
REG_PIOB_ABSR=0x2000000;//Peripheral B free from GPIO to peripheral use of timer
REG_TC0_WPMR=0x54494d00; //disable protection of registers
REG_TC0_CMR0=0x9c403; //Waveform mode, CLK/128, Mode TIOA
REG_TC0_RA0=0x0; //RA start point is 0
REG_TC0_RC0=0x9fff6; //RC stop point is 0x9fff6=1 second???.REVISAR
REG_TC0_CCR0=0x5; //Enable Channel 0 and start counting by software
REG_TC0_IER0=0x10; //Interrupt when RC is reach.
REG_TC0_IDR0=0xEF; //Disable the others interruptions
NVIC_EnableIRQ(TC0_IRQn); //Enable TC0 interrupts
}
void loop(){
digitalWrite(13,l);
}
Referencias: