//this is the code for arduino mega, setting the timer in comparison mode
//In the 4.13 of simulIde versión the code works good
/*program that turns a led on and off at 350 ms intervals
using timer 1 in CTC (A) mode or comparison mode*/
#define LED 13
void config_timer(void);
void setup() {
// put your setup code here, to run once:
pinMode(LED,OUTPUT);
config_timer();
}
void loop() {
// put your main code here, to run repeatedly:
}
ISR(TIMER1_COMPA_vect) //Interrupt Service Routine
{
TCNT1=0;
digitalWrite(LED,digitalRead(LED)^1);
}
void config_timer(void){
TCCR1A = TCCR1B = 0;//ELIMINAR CUALQUIE CONF PREVIA DEL TIMER
TCNT1 = 0;//Borro cualquier conteo o valor previo
OCR1A = 21875;// SE COMPARA el timer 1 CONTRA 21875 CONTEOS...con el fin de obtener 350 ms
TCCR1B |= (1 << WGM12); //se configuro el timer 1 en modo de comparación CTC..
TCCR1B |= (1<