Question: Changing Pins from Inputs to Outputs

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys,

I've noticed that on a character display you can read or write data using the same pins.

If I wanted to read and write can I do it on the same pins (on the AVR) by simply redefine them from outputs to inputs(or vice versa)?

PS. Sorry if this is in the wrong forum, I use GCC thats why I'm posting here.

I'm not a cartoon character but I play one in real life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, use the DDRx register to set the i/o direction of the pins.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Write DDRx to set pin/port input/output direction.
Write PORTx to set pin/port hi/low (output) or pullup on/off (input)
Read PORTx to see driver state (output) or pullup state (input)
Read PINx to get actual logic on pin/port (output or input)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Keep in mind that switching the data direction of a pin may cause a glitch. For instance, if you have output a 1 to a pin and then change to input, the pull-up resistor on that pin will be on. If something like this matters to the circuit that is connected to the pin, you may need to be careful when you switch the direction and set the port to the proper value immediately before or after the switch.

Regards,
Steve A.

The Board helps those that help themselves.