Clock divider methods on an Arduino UNO.

Clock PORTB with a signal of 200 Hz which can be easily created using TC1. The procedures are:

1. Configure Port-B to work as output.

2. Configure TC1 to pulse TOV1 flag at every 5 ms (1/.005 = 200 Hz). Use TOV1 as triggering source for the 200 Hz clocking signal of PORTB Register.

The Sketch: (try and check that L at DPin-13 blinks at 0.75 Hz)

void setup()
{
  DDRB = 0xFF;        //all pints of PORTB are output
  PORTB = 0x00;      //all pins are LOW

  //---TC1 intialization to generate 200 Hz triggering pulse (the TOV1 flag)
  TCCR1A = 0x0000;   //Normal Mode operation of TC1/TCNT1
  TCCR1B = 0x0000;   //TCNT1 is OFF
  TCNT1 = 0x7290;   //preset count for the overflow event to occur at 5 ms interval at clkTC1 = 2 MHz
  //2000000*.005 = 10000; ==> 0x10000 - 10000 = 0x7290
  TCCR1B = 0x02;    //start TC1 at driving clock (clkTc1) = 16000000/8 = 2 MHz
}

void loop()
{
  while (bitRead(TIFR1, 0) != HIGH)
  {
    ;     //5 ms has not elapsed
  }
  bitSet(TIFR1, 0);    //clear TOV1 flag bit
  TCNT1 = 0x7290;      //re-load preset count
  PORTB = PORTB + 1;
}