+ else if(num==2)
+ {
+ if(period<0x100)
+ cs = BIT(CS20);
+ else if(period<0x800)
+ {
+ cs = BIT(CS21);
+ period /= 8;
+ }
+ else if(period<0x2000)
+ {
+ cs = BIT(CS21) | BIT(CS20);
+ period /= 32;
+ }
+ else if(period<0x4000)
+ {
+ cs = BIT(CS22);
+ period /= 64;
+ }
+ else if(period<0x8000)
+ {
+ cs = BIT(CS22) | BIT(CS20);
+ period /= 128;
+ }
+ else if(period<0x10000)
+ {
+ cs = BIT(CS22) | BIT(CS21);
+ period /= 256;
+ }
+ else
+ {
+ cs = BIT(CS22) | BIT(CS21) | BIT(CS20);
+ period /= 1024;
+ if(period>0xFF)
+ period = 0xFF;
+ }
+ TCCR2A = BIT(WGM21);
+ TCCR2B = cs;
+ OCR2A = period;
+ TIMSK2 = BIT(OCIE2A);
+ }