Guest User

Untitled

a guest
Sep 30th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. long Set_frequency(long freq)
  2. {
  3.   TCCR1A = 0b01000000;
  4.   uint16_t ocr;
  5.   if(freq < 134)
  6.   {
  7.     TCCR1B = 0b00001010;
  8.     ocr = 1000000UL/freq - 1;
  9.     freq = 1000000UL/(ocr+1);
  10.   }
  11.   else
  12.   {
  13.     TCCR1B = 0b00001001;
  14.     ocr = 8000000UL/freq - 1;
  15.     freq = 8000000UL/(ocr+1);
  16.   }
  17.   OCR1AH = highByte(ocr);
  18.   OCR1AL = lowByte(ocr);
  19.   TIMSK1 = 0;
  20.   return freq;
  21. }
Add Comment
Please, Sign In to add comment