avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] quick question!!


From: Randy Ott
Subject: Re: [avr-gcc-list] quick question!!
Date: Tue, 14 May 2002 12:03:17 -0500

You can make the AVR ports act like 8051 quasi-bidirectional ports this way:

Put a pull-up resistor on the pin, 47k or 100k is a good number.  Put a 0 on
the PORTx register and make it an input in the DDR.  Now you can read it on
the PINx register just like you can on the '51.  To pull it low, put a 1 in
the DDR and it will go low.  To make it go back high, and revert back to an
input, put a 0 in the DDR.  Kinda works like the open collector port pins on
the '51.  When used this way make sure you NEVER put a 1 in the PORTx
register because it will cause the pin to be forced high and that might
conflict with whatever input is connected to it.  Let the pull-up do the
work.

Hope that helps.

Randy Ott

----- Original Message -----
From: "Peter N Lewis" <address@hidden>
To: <address@hidden>
Sent: Monday, May 13, 2002 10:14 PM
Subject: Re: [avr-gcc-list] quick question!!


> At 14:01 -0500 11/5/02, Brandon Tolbert wrote:
> >Is there any way to set up a pin to be both in and out? I mean when
> >you set the port using the DDRB or DDRD it is either in or out. I
> >have just been changing this before I used the port in the opposite
> >direction is there another way?
>
> If the pin is set to INPUT, then it can be used as both input and
> output.  Externally, pull it low with a very large resistor (100k?),
> and use the PORT register to set or clear the pullup which will then
> change the value.  Be careful with what you are outputing to though,
> because it will need to have very high impedance to ensure it doesn't
> mess up your output.
>
> Also, if my understanding is correct, PIN bits represent the phyiscal
> state of the pin even for outputs, so you can have a pin set to
> OUTPUT and drive it externally and read what the pin is being set to
> externally using the PIN bits.
>
> Both these techniques are a bit dubious and I would try to avoid them
> if I could.  The first one would make me nervous as it depends on the
> pullup resistor values, and the second one would make me nervous
> because you are driving an output.  To get more details, you'd need
> to visit Atmel's site and find some application notes that tell you
> exactly how to do both of these to ensure it will work in your
> situation.
>
> HTH,
>     Peter.
> --
> <http://www.interarchy.com/>  <ftp://ftp.interarchy.com/interarchy.hqx>
> avr-gcc-list at http://avr1.org
>
>


avr-gcc-list at http://avr1.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]