在AVR ATMega 169中配置PINB.4和PINB.5作为输入引脚并启用上拉?
我想配置两个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经正确设置了 PORT B,但是稍微改进一下您的编码约定也没什么坏处。
除非我误解了您想要完成的任务,否则我认为您的中断配置不正确。
PB4和PB5分别对应于PCINT12和PCINT13。
由于两者都对应于引脚更改中断启用 1,因此您只需启用该引脚即可。
您实际上不需要设置EIFR,除非您尝试手动触发中断。每当发生引脚更改时,该寄存器都会自动标记。
在PCMSK1中,您要设置PCINT13和PCINT12,
这将启用相应引脚上的中断。
SIGNAL 也被贬值。 #include avr/interrupt.h 并使用 ISR。
两个引脚更改都将由该向量处理。
希望这能让事情澄清一点。
You have set up you PORT B correctly but it wouldn't hurt to improve your coding conventions a little.
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.
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
This enables interrupts on the corresponding pins.
Also SIGNAL is depreciated. #include avr/interrupt.h and use ISR.
Both Pin changes will be handled by this vector.
Hope this clears things up a bit.