ATmega4808 32针-针PA0未被设置为高电平

时间:2019-06-07 16:29:46

标签: c avr atmega microchip

我正在使用ATmega4808 32针。我有2个LED分别连接到引脚PA0和PA1。我想把两者都设置得很高。不幸的是,只有PA1 LED点亮。

我发现默认情况下,PA0引脚可以设置为EXTCLK。如果这是问题,我找不到将端口更改为GPIO的解决方案。

int main(int argc, char** argv) {
    PORTA.DIRSET = PIN0_bm; // Config PA0 as output
    PORTA.DIRSET = PIN1_bm; // Config PA1 as output

    PORTA.OUTSET = PIN0_bm; // Set Pin PA0 to HIGH 
    PORTA.OUTSET = PIN1_bm; // Set Pin PA1 to HIGH 

    while(1){
    }


    return (EXIT_SUCCESS);
}

1 个答案:

答案 0 :(得分:0)

通过再次写入寄存器PORTA.DIRSETPORTA.OUTSET来丢失PIN0的配置。

尝试使用| (bitwise OR)不放弃PIN0配置:

    PORTA.DIRSET  = PIN0_bm; // Config PA0 as output
    PORTA.DIRSET |= PIN1_bm; // Config PA1 as output

    PORTA.OUTSET  = PIN0_bm; // Set Pin PA0 to HIGH
    PORTA.OUTSET |= PIN1_bm; // Set Pin PA1 to HIGH

或者,要同时设置它们:

    PORTA.DIRSET = PIN0_bm | PIN1_bm; // Config PA0 and PA1 as output

    PORTA.OUTSET = PIN0_bm | PIN1_bm; // Set Pin PA0 and PA1 to HIGH