|
|
是Arduino Due
我的老师给了我一个超级难的代码(起码对于我来说是这样的),说这个对于我来说很难让我去网上论坛问网友的意见来回答问题(不要鄙视我,我发誓他真的是这样子对我说的)。
以下是代码(其实是他从一个Arduino的论坛上看到的):
===========================================
volatile boolean l;
//TC1 ch 0
void TC3_Handler()
{
TC_GetStatus(TC1, 0);
digitalWrite(13, l = !l);
}
void startTimer(Tc *tc, uint32_t channel, IRQn_Type irq, uint32_t frequency) {
pmc_set_writeprotect(false);
pmc_enable_periph_clk((uint32_t)irq);
TC_Configure(tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK4);
uint32_t rc = VARIANT_MCK/128/frequency; //128 because we selected TIMER_CLOCK4 above
TC_SetRA(tc, channel, rc/2); //50% high, 50% low
TC_SetRC(tc, channel, rc);
TC_Start(tc, channel);
tc->TC_CHANNEL[channel].TC_IER=TC_IER_CPCS;
tc->TC_CHANNEL[channel].TC_IDR=~TC_IER_CPCS;
NVIC_EnableIRQ(irq);
}
void setup(){
pinMode(13,OUTPUT);
startTimer(TC1, 0, TC3_IRQn, 4); //TC1 channel 0, the IRQ for that channel and the desired frequency
}
void loop(){
}
======================================================
能行对行的跟我解释一下这个代码是怎么运作的吗,插上电路其实就是小灯儿1秒钟闪一次。
以下是我老师给我的问题,说要收集网友答案然后写进实验报告里:
1. How many interrupt levels are available in the Arduino Due? Why?
2.How many independent timers are available in the Arduino Due? Why?
3.How can the timers be connected to the interrupt levels? Why?
4.Can you vary the blinking frequency in this sketch? Why and How?
5.Can you use a different timer and channel? Why and How?
6.Explain, line by line, how this code works.
|
|