在AVR ATMega 169中配置PINB.4和PINB.5作为输入引脚并启用上拉?

发布于 2024-12-16 17:12:03 字数 400 浏览 1 评论 0原文

我想配置两个AVR蝶形板,其中PORT D是第一个AVR蝶形板的输出端口,并且该PORT D的两个引脚连接到第二个AVR蝶形板的端口B的引脚B.4和B.5 。我还想在这些端口 B 引脚上启用上拉电阻。此配置对于第二个 AVR 是否正确?我缺少什么吗?

  //Init port pins
DDRB = 0x00;
    PORTB |= 0X30;

 //Enable pin change interrupt on PORTB
 PCMSK1 = 0X30;
 EIFR = 0XC0;
 EIMSK = 0XC0;

SIGNAL(SIG_PIN_CHANGE1)--PIN B.4 的引脚改变中断 {..} SIGNAL(SIG_PIN_CHANGE2)--PIN B.5 的引脚改变中断 {......}

I want to configure two AVR butterfly boards in such a way that PORT D is an output port in the first one and two pins of this PORT D are connected to pins B.4 and B.5 of port B of the second AVR butterfly board. I also want to enable pull-ups on these port B pins. Is this configuration correct for the second AVR ? Is there something that i am missing?

  //Init port pins
DDRB = 0x00;
    PORTB |= 0X30;

 //Enable pin change interrupt on PORTB
 PCMSK1 = 0X30;
 EIFR = 0XC0;
 EIMSK = 0XC0;

SIGNAL(SIG_PIN_CHANGE1)-- Pin change interrupt of PIN B.4
{..}
SIGNAL(SIG_PIN_CHANGE2)-- Pin change interrupt of PIN B.5
{..... }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

も让我眼熟你 2024-12-23 17:12:03

您已经正确设置了 PORT B,但是稍微改进一下您的编码约定也没什么坏处。

DDRB&= ~(1<<PB0)|(1<<PB1);
PORTB|= (1<<PB0)|(1<<PB1);

除非我误解了您想要完成的任务,否则我认为您的中断配置不正确。

PB4PB5分别对应于PCINT12PCINT13

由于两者都对应于引脚更改中断启用 1,因此您只需启用该引脚即可。

EIMSK = (1<<PCIE1);

您实际上不需要设置EIFR,除非您尝试手动触发中断。每当发生引脚更改时,该寄存器都会自动标记。

PCMSK1中,您要设置PCINT13PCINT12

PCMSK1 |= (1<<PCINT12)|(1<<PCINT13);

这将启用相应引脚上的中断。

SIGNAL 也被贬值。 #include avr/interrupt.h 并使用 ISR。

ISR(PCINT1_vect){}

两个引脚更改都将由该向量处理。

希望这能让事情澄清一点。

You have set up you PORT B correctly but it wouldn't hurt to improve your coding conventions a little.

DDRB&= ~(1<<PB0)|(1<<PB1);
PORTB|= (1<<PB0)|(1<<PB1);

Unless I am miss-understanding what your trying to accomplish, I don't think your interrupts are configured correctly.

PB4 and PB5 correspond to PCINT12 and PCINT13 respectively.

Since both correspond to Pin Change Interrupt Enable 1 you'll want to only have that pin enabled.

EIMSK = (1<<PCIE1);

You don't actually need to set EIFR unless your trying to manually trigger an interrupt. This register gets flagged automatically whenever a pin change occurs.

In PCMSK1 you want to set PCINT13 and PCINT12

PCMSK1 |= (1<<PCINT12)|(1<<PCINT13);

This enables interrupts on the corresponding pins.

Also SIGNAL is depreciated. #include avr/interrupt.h and use ISR.

ISR(PCINT1_vect){}

Both Pin changes will be handled by this vector.

Hope this clears things up a bit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文