Zhougy.vc 发表于 2008-5-30 23:54:11

IO口同时用作输入和输出

马老师您好!请帮我详细讲一下:如果一个IO口同时做输入输出时,当从输入切换到输出要怎么做,
            当从输出切换到输入时又要注意些什么!

machao 发表于 2008-5-31 01:35:50

When switching between tri-state ({DDxn, PORTxn} = 0b00) and output high ({DDxn,PORTxn} = 0b11), an intermediate state with either pull-up enabled ({DDxn, PORTxn} = 0b01) or output low ({DDxn, PORTxn} = 0b10) must occur. Normally, the pull-up enabled state is fully acceptable, as a high-impedant environment will not notice the difference between a strong high driver and a pull-up. If this is not the case, the PUD bit in the SFIOR Register can be set to disable all pull-ups in all ports.
Switching between input with pull-up and output low generates the same problem. The user must use either the tri-state ({DDxn, PORTxn} = 0b00) or the output high state ({DDxn, PORTxn} = 0b11) as an intermediate step.

根据手册的介绍,转换中应该注意以下几点:

1.输入高阻转换为输出高电平时:输入高阻=>输入上拉=>输出高电平
2.输入上拉转换为输出低电平时:输入上拉=>输入高阻=>输出低电平

输出转输入时,先将I/O从输出转成输入,然后再设置成上拉或高阻.

Zhougy.vc 发表于 2008-5-31 10:01:52

Table 32. 端口引脚配置
DDRXN PORTXNPUD( 位于MCUCR)I/O上拉电阻         说明
0   0       X               输入No         高阻态 (Hi-Z)
0   1       0               输入Yes          被外部电路拉低时将输出电流
0   1       1               输入No         高阻态 (Hi-Z)
1   0       X               输出No         输出低电平 ( 吸收电流)
1   1       X                输出   No         输出高电平 ( 输出电流)

这是IC规格书里端口配置的描述,请问第一个高阻态和第三个高阻态有什么区别,分别用在什么情况。表中的X指的是什么,是不是默认设置。

machao 发表于 2008-5-31 18:07:32

DDRXn PORTXn是每个I/O口的控制位.

另外AVR还有一个总的控制位PUD(在于寄存器MCUCR中),当它设置为1时,所有的I/O口工作在输入方式时,上拉均无效.

表中的X指的是任意值,0和1都可以.
页: [1]
查看完整版本: IO口同时用作输入和输出