// C++ code
/*
Programa 1: Utilizar a interrupção do WDT para piscar um led a cada 4 segundos
*/
/* REFERENCE:
*
* LAB Name: Arduino Timer Compare Match Interrupt
* Author: Khaled Magdy
* For More Info Visit: www.DeepBlueMbedded.com
*/
/*
* LAB Name: Arduino Timer Compare Match Interrupt
* Author: Khaled Magdy
* For More Info Visit: www.DeepBlueMbedded.com
*/
#define led_pin 7
volatile bool led_val = LOW;
ISR(TIMER1_COMPA_vect)
{
OCR1A += 62500; // Advance The COMPA Register
// Handle The Timer Interrupt
led_val = !led_val;
}
void setup()
{
pinMode(led_pin, OUTPUT);
Serial.begin(9600);
TCCR1A = 0; // Init Timer1A
TCCR1B = 0; // Init Timer1B
TCCR1B |= B00000100; // Prescaler = 256
OCR1A = 62500; // Timer Compare1A Register
TIMSK1 |= B00000010; // Enable Timer COMPA Interrupt
}
void loop()
{
// Do Nothing
Serial.println("led_val: " + (String)led_val);
digitalWrite(led_pin, led_val);
}
/*
Aluno: Luiz Paulo Grafetti Terres
Data : Jun 14, 2024
Email: [email protected] || [email protected]
*/