打印
[PIC®/AVR®/dsPIC®产品]

Atmega644 GPIO引脚输出高低电平翻转问题

[复制链接]
660|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
tom_xu|  楼主 | 2020-5-12 09:34 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 tom_xu 于 2020-5-12 09:39 编辑

各位大侠,有个问题请教下,
我用Atmel Start自动生成的项目文件,PORTB GPIO输出高低电平翻转的代码如下:
/**
* \brief Toggle output level on pin
*
* Toggle the pin levels on pin
*
* \param[in] pin       The pin number for device
*/
static inline void PORTB_toggle_pin_level(const uint8_t pin)
{
        PINB = 1 << pin;
}

也就是说 第一次调用PORTB_toggle_pin_level(2)
PB2输出高电平
第一次调用PORTB_toggle_pin_level(2)
PB2输出低电平
但是PINB是PortB Input Pins Address, PORTB输入引脚地址
不知道是怎么能够实现翻转的?
谢谢!


使用特权

评论回复
沙发
tom_xu|  楼主 | 2020-5-12 09:40 | 只看该作者
PINB在数据手册定义:

PINB.png (20.59 KB )

PINB.png

使用特权

评论回复
板凳
ynwa| | 2020-5-12 10:04 | 只看该作者
数据手册67页:
12.2.2 Toggling the Pin
Writing a logic one to PINxn toggles the value of PORTxn, independent on the value of DDRxn.
Note that the SBI instruction can be used to toggle one single bit in a port.

使用特权

评论回复
地板
lcczg| | 2020-5-12 10:06 | 只看该作者
AVR的一个特色

使用特权

评论回复
5
tom_xu|  楼主 | 2020-5-12 10:17 | 只看该作者
ynwa 发表于 2020-5-12 10:04
数据手册67页:
12.2.2 Toggling the Pin
Writing a logic one to PINxn toggles the value of PORTxn, ind ...

太牛了!!!高手!

使用特权

评论回复
6
tom_xu|  楼主 | 2020-5-12 10:22 | 只看该作者
ATMEGA32就没有这个功能。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

66

主题

1657

帖子

4

粉丝