4025 views|0 replies

1w

Posts

25

Resources
The OP
 

【ATmega4809 Curiosity Nano Review】Timer [Copy link]

The timer of ATmega4809 is similar to that of ordinary AVR, but it has many more functions and its usage is more complicated.

The following program uses the normal mode of TCA. When the timer overflows, an interrupt is generated and the LED is flipped in the interrupt.

#define F_CPU 20000000L/6

#include <xc.h>
#include <avr/interrupt.h>

SIGNAL(TCA0_OVF_vect)
{
    TCA0.SINGLE.INTFLAGS |= (1<<0);
    PORTF.OUTTGL |= (1<<5);
}

int main(void) {
    
    // PF5 as LED
    PORTF.DIR |= (1<<5);
    
    //TCC0
    // NORMAL mode
    TCA0.SINGLE.CTRLB = 0;
    // DIV1024
    TCA0.SINGLE.CTRLA |= (7<<1) | (1<<0);
    // OVF interrupt
    TCA0.SINGLE.INTCTRL = (1<<0);
    TCA0.SINGLE.PER = F_CPU/1024;
    
    // enable interrupt
    sei();
    
    while(1)
    {
        
    }
    
    return 0;
}




This content is originally created by dcexpert , a user of EEWORLD forum. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source

This post is from MCU
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list