Академический Документы
Профессиональный Документы
Культура Документы
{
PORTB = 0;
DDRB = 0b00000010;
setFrequency(1000000);
}
void loop()
{
while(1)
{
on();
delay(1);
off();
delay(1);
}
}
// Set the frequency that we will get on pin OCR1A but don't turn it on
void setFrequency(uint16_t freq)
{
uint32_t requiredDivisor = (F_CPU/2)/(uint32_t)freq;
uint16_t prescalerVal = 1;
uint8_t prescalerBits = 1;
while ((requiredDivisor + prescalerVal/2)/prescalerVal > 256)
{
++prescalerBits;
prescalerVal <<= 1;
}
uint8_t
TCCR1 =
GTCCR =
OCR1C =
}
// Turn the frequency on
void on()
{
TCNT1 = 0;
TCCR1 |= (1 << COM1A0);
}
// Turn the frequency off and turn off the IR LED.
// We let the counter continue running, we just turn off the OCR1A pin.
void off()
{
TCCR1 &= ~(1 << COM1A0);
}