求帮解释下这段代码是什么意思 ARDUINO
voidInit_time(){cli();//disableglobalinterruptsTCCR1A=0;//setentireTCCR1Aregisterto0T...
void Init_time()
{
cli(); // disable global interrupts
TCCR1A = 0; // set entire TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B
// set compare match register to desired timer count:
OCR1A = 781; //50ms
//1/16MHz*1024*781 = 50ms
// turn on CTC mode:
TCCR1B |= (1 << WGM12);
// Set CS10 and CS12 bits for 1024 prescaler:
TCCR1B |= (1 << CS10);
TCCR1B |= (1 << CS12);
// enable timer compare interrupt:
TIMSK1 |= (1 << OCIE1A);
sei(); // enable global interrupts
}
//**********************************************************
//定时器中断
//**********************************************************
ISR(TIMER1_COMPA_vect) //这是定义好的定时器1比较中断
{
Count++;
if (Count>=2) //100ms
{
Count=0;
if(Flag_Buzzer == 1)
digitalWrite(Buzzer, !digitalRead(Buzzer));
}
Count2++;
if(Count2 == 10) //500ms
{
Count2 = 0;
if(Flag_Buzzer == 2)
digitalWrite(Buzzer, !digitalRead(Buzzer));
}
Count3++;
if(Count3 == 20)
{
Count3 = 0;
Sec++;
if(Sec == 60)
{
Sec = 0;
Min++;
if(Min == 60)
{
Min = 0;
Hour++;
if(Hour == 10000)
{
Hour == 9999;
}
}
}
}
Count4++;
if(Count4 == 20)
{
Count4 = 0;
Time++;
}
} 展开
{
cli(); // disable global interrupts
TCCR1A = 0; // set entire TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B
// set compare match register to desired timer count:
OCR1A = 781; //50ms
//1/16MHz*1024*781 = 50ms
// turn on CTC mode:
TCCR1B |= (1 << WGM12);
// Set CS10 and CS12 bits for 1024 prescaler:
TCCR1B |= (1 << CS10);
TCCR1B |= (1 << CS12);
// enable timer compare interrupt:
TIMSK1 |= (1 << OCIE1A);
sei(); // enable global interrupts
}
//**********************************************************
//定时器中断
//**********************************************************
ISR(TIMER1_COMPA_vect) //这是定义好的定时器1比较中断
{
Count++;
if (Count>=2) //100ms
{
Count=0;
if(Flag_Buzzer == 1)
digitalWrite(Buzzer, !digitalRead(Buzzer));
}
Count2++;
if(Count2 == 10) //500ms
{
Count2 = 0;
if(Flag_Buzzer == 2)
digitalWrite(Buzzer, !digitalRead(Buzzer));
}
Count3++;
if(Count3 == 20)
{
Count3 = 0;
Sec++;
if(Sec == 60)
{
Sec = 0;
Min++;
if(Min == 60)
{
Min = 0;
Hour++;
if(Hour == 10000)
{
Hour == 9999;
}
}
}
}
Count4++;
if(Count4 == 20)
{
Count4 = 0;
Time++;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询