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

AVR 下用Arduino操作I2C

[复制链接]
1780|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
幸福小强|  楼主 | 2023-11-5 20:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
<p>// Send control and register address bytes</p><p>Wire.beginTransmission(0x20);</p><p>Wire.write(0x00);</p><p>// Write data to IODIRA register</p><p>Wire.write(0xFF);</p><p>// End session</p><p>Wire.endTransmission();</p><p>// Send control and register address bytes</p><p>Wire.beginTransmission(0x20);</p><p>Wire.write(0x12); // GPIOA</p><p>Wire.endTransmission();</p><p>// Read data from port A</p><p>Wire.requestFrom(0x20, 1); // set R/W bit to 1 (read)</p><p>portval = Wire.read(); // still points to 0x12</p><p>Since the GP I/O ports are configured as inputs by default at power-up or after a reset</p><p>(see Table 10-9), the first step could have been omitted. To configure the port as an</p><p>output the IODIRA bits would be set to 0. This is shown in the code snippet in</p><p>Example 10-8.</p><p>Example 10-8. Writing data to the output port</p><p>// Send control and register address bytes</p><p>Wire.beginTransmission(0x20);</p><p>Wire.write(0x00);</p><p>// Write data to IODIRA register</p><p>Wire.write(0x0);</p><p>// End</p><p>Wire.endTransmission();</p><p>// Send control and register address bytes</p><p>Wire.beginTransmission(0x20);</p><p>Wire.write(0x12); // GPIOA</p><p>// Write data to port A</p><p>Wire.write(portval);</p><p>Wire.endTransmission();</p>


使用特权

评论回复
沙发
zhuotuzi| | 2023-11-7 22:27 | 只看该作者
// Send control and register address bytes
Wire.beginTransmission(0x20);
Wire.write(0x00);
// Write data to IODIRA register
Wire.write(0xFF);
// End session
Wire.endTransmission();
// Send control and register address bytes
Wire.beginTransmission(0x20);
Wire.write(0x12);
// GPIOA
Wire.endTransmission();
// Read data from port A
Wire.requestFrom(0x20, 1);
// set R/W bit to 1 (read)
portval = Wire.read();
// Send control and register address bytesWire.beginTransmission(0x20);
Wire.write(0x00);
// Write data to IODIRA register
Wire.write(0x0);
// EndWire.endTransmission();
// Send control and register address bytes
Wire.beginTransmission(0x20);
Wire.write(0x12);
// GPIOA
// Write data to port A
Wire.write(portval);
Wire.endTransmission();

使用特权

评论回复
板凳
zhuotuzi| | 2023-11-7 22:28 | 只看该作者
乱了,帮你修改下。

使用特权

评论回复
地板
Undshing| | 2023-11-12 18:40 | 只看该作者
本帖最后由 Undshing 于 2023-11-12 18:42 编辑

这个用Arduino多啊

使用特权

评论回复
5
pzsh| | 2023-11-21 11:55 | 只看该作者
Arduino还是简单一些,但是好像那个环境下不能单步调试

使用特权

评论回复
6
Bowclad| | 2023-11-23 14:54 | 只看该作者
好乱的格式

使用特权

评论回复
7
MessageRing| | 2023-11-27 14:50 | 只看该作者
还是arduino用的多啊

使用特权

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

本版积分规则

123

主题

1480

帖子

2

粉丝