我正在编写一个 Atmega324a 微控制器,我正在尝试实现一个计时器(在本例中为 Timer1),它应该使连接到我的电路板的第二个 LED 闪烁。我还需要知道如何识别 LED 连接到的引脚 我找到了数据表: http ://ww1.microchip.com/downloads/en/DeviceDoc/ATmega164A_PA-324A_PA-644A_PA-1284_P_Data-Sheet-40002070A .pdf 但细节对我来说太技术性了,我不知道从哪里开始寻找,最重要的是,得到结果,这就是代码本身。
另外,ISR 功能有什么作用?
下面是定时器 0 的当前 Init_timer 函数。我可以同时启用两个定时器吗?
static void init_timer(void)
{
// Configure Timer0 for CTC mode, 64x prescaler for 1 ms interval
TCCR0A = _BV(WGM01);
TCCR0B = _BV(CS01) | _BV(CS00);
OCR0A = 124;
TIMSK0 = _BV(OCIE0A);
}
int main(void){
MCUSR = 0;
wdt_disable();
init_pins(); // Reset all pins to default state
init_timer(); // Initialize 1 msec timer interrupt
configure_as_output(LOAD_ON);
configure_as_output(LED1);
configure_as_output(LED2);
sei();
.
.
.
}
ISR(TIMER0_COMPA_vect)
{
static uint16_t ms_count = 0;
ms_count++; // milliseconds counter
if (ms_count == TMP107_POLL_PERIOD)
{
tmp107_command(); // send command to temperature sensor
toggle(LED1); // blink status led
ms_count = 0;
}
}