[英]ATmega4808 32 Pin - Pin PA0 doesn't get set HIGH
I'm using an ATmega4808 32 Pin. 我正在使用ATmega4808 32针。 I have 2 LEDs connected to the pins PA0 and PA1. 我有2个LED分别连接到引脚PA0和PA1。 I want to set both high. 我想把两者都设置得很高。 Unfortunatly only the PA1 LED is on. 不幸的是,只有PA1 LED点亮。
I figured out the PA0 Pin could be set to EXTCLK by default. 我发现默认情况下,PA0引脚可以设置为EXTCLK。 If this is the problem i can't find the solution to change the port to GPIO. 如果这是问题,我找不到将端口更改为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);
}
The configuration of PIN0 is lost by writing again to registers PORTA.DIRSET
and PORTA.OUTSET
. 再次写入寄存器PORTA.DIRSET
和PORTA.OUTSET
将丢失PIN0的配置。
Try using | (bitwise OR)
尝试使用| (bitwise OR)
| (bitwise OR)
to not discard PIN0 config: | (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
Or, to set them at the same time: 或者,要同时设置它们:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.