avr-c atmega324a中的定时器 #定义F#U CPU 800000UL #包括 /* *主程序 */ 内部主(空) { /*将OC1A引脚设置为输出*/ DDRD |=(1

avr-c atmega324a中的定时器 #定义F#U CPU 800000UL #包括 /* *主程序 */ 内部主(空) { /*将OC1A引脚设置为输出*/ DDRD |=(1,c,microcontroller,avr,avr-gcc,C,Microcontroller,Avr,Avr Gcc,首先,当设置TCCR1A等寄存器时,您只需分配您想要输入的值,而不是分配您想要设置的位,因为您将得到不需要的新旧混合 然后尝试更改此选项: #define F_CPU 8000000UL #include <avr/io.h> /* * main -- Main program */ int main(void) { /* Set OC1A pin to be an output */ DDRD|=(1<<5); /* Set output

首先,当设置TCCR1A等寄存器时,您只需分配您想要输入的值,而不是分配您想要设置的位,因为您将得到不需要的新旧混合

然后尝试更改此选项:

#define F_CPU 8000000UL
#include <avr/io.h>

/*
 * main -- Main program
 */
int main(void)
{
    /* Set OC1A pin to be an output */
    DDRD|=(1<<5);

    /* Set output compare register value */
    OCR1A = 4000;


    /* Set timer counter control registers A and B so that
     *  - mode is - clear counter on compare match
     *  - output compare match action is to toggle pin OC1A
     *  - correct clock prescale value is chosen.
     * TCCR1C can just stay as default value (0).
     */

    TCCR1A |=(1<<COM0A0) | (1<<WGM12);
    TCCR1B |= (0<<CS12) | (1<<CS11) | (1<<CS10) | (1<<WGM12) | (1<<WGM12);

    while(1){

    }
}

TCCR1A=(1您完全没有我能看到的使LED闪烁的逻辑(打开和关闭,等等)。在玩计时器之前,先让LED亮起。@rost0031他正试图使用硬件计时器使LED闪烁。好的,我现在看到了。OP,你确定LED闪烁得太快以至于看不到它吗?尝试关闭计时器,通过手动切换输出来查看LED是否亮起。
TCCR1A = (1 << COM1A0);    //COM1A0 in stead of COM0A0, and WGM12 is not part of TCCR1A
TCCR1B = (1 << CS11) | (1 << CS10) | (1 << WGM12);    //No need to write (0 << x) for bits you don't want set, WGM12 is part of TCCR1B