/*
Arduino function Arduion function
reset (PCINT14/RESET) PC6 1 28 PC5 (ADC5/SCL/PCINT13) analog input 5
digital pin 0(RX) (PCINT16/RXD) PD0 2 27 PC4 (ADC4/SDA/PCINT12) analog input 4
digital pin 1(TX) (PCINT17/TXD) PD1 3 26 PC3 (ADC3/PCINT11) analog input 3
digital pin 2 (PCINT18/INT0) PD2 4 25 PC2 (ADC2/PCINT10) analog input 2
digital pin 3(PWM) (PCINT19/OC2B/INT1) PD3 5 24 PC1 (ADC1/PCINT9) analog input 1
digital pin 4 (PCINT20/XCK/T0) PD4 6 23 PC0 (ADC0/PCINT8) analog input 0
VCC VCC 7 22 GND GND
GND GND 8 21 AREF analog reference
crystal (PCINT6/XTAL1/TOSC1) PB6 9 20 AVCC VCC
crystal (PCINT7/XTAL2/TOSC2) PB7 10 19 PB5 (SCK/PCINT5) digital pin 13
digital pin 5(PWM) (PCINT21/OC0B/T1) PD5 11 18 PB4 (MISO/PCINT4) digital pin 12
digital pin 6(PWM) (PCINT22/OC0A/AIN0) PD6 12 17 PB3 (MOSI/OC2A/PCINT3) digital pin 11 (PWM)
digital pin 7 (PCINT23/AIN1) PD7 13 16 PB2 (SS/OC1B/PCINT2) digital pin 10 (PWM)
digital pin 8 (PCINT0/CLK0/ICP1) PB0 14 15 PB1 (OC1A/PCINT1) digital pin 9 (PWM)
*/
// Timer Interrupt Register Configuration in Arduino | Register Programming in Arduino | T - 19
// https://www.youtube.com/watch?v=-Mk98R5D9ZI&list=PL_zvrXFdKgZqiTxipn7WjT_T9hU7ughQH&index=24
void setup() {
// ENABLE THE GLOBAL INTERRUPT ENABLE BIT
sei();
// ENABLE THE REQUIRED TIMER INTERRUPT
TIMSK1 |= (1 << OCIE1A);
// SET MODE OF THE TIMER
TCCR1A &= ~(1 << WGM10) & ~(1 << WGM11);
TCCR1B &= ~(1 << WGM12) & ~(1 << WGM13); // NORMAL MODE
// SET THE COMPARE OUTPUT MODE
TCCR1A |= (1 << COM1A0);
TCCR1A &= ~(1 << COM1A1); // TOGGLE
// SET THE PRESCALER FOR THE TIMER
TCCR1B |= (1 << CS12) | (1 << CS10);
TCCR1B &= ~(1 << CS11); // PRESCALER = 1024
// START THE TIMER WITH INITIAL VALUE
TCNT1 = 0;
// LOAD THE PERIOD FOR THE TIMER
// The system clock is 16MHz
// The clock frequency becomes 16,000,000 / 1024 = 15,625Hz
// Time for each Tick is 1 / 15625 = 0.00064s = 64us
// For 1000ms to elapse the count is 1000ms / 64us = 15625
OCR1A = 15625;
// CONFIGURE THE OUTPUT COMPARE PIN AS O/P
DDRB |= (1 << DDB1);
}
void loop() {
// put your main code here, to run repeatedly:
}
// IMPLEMENT THE INTERRUPT HANDLER FUNCTION
ISR(TIMER1_COMPA_vect)
{
// USER CODE
TCNT1 = 0;
OCR1A = 15625;
}