我用的是ATMega480832针。我有两个LED连接到引脚PA0和PA1。我想把两者都调高。不幸的是,只有PA1发光二极管亮着。
我发现PA0的Pin可以默认设置为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);
}
最佳答案
通过再次写入寄存器PORTA.DIRSET
和PORTA.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