DDR PORT and PIN Registers

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

Ok, this is a very simple question, but one that has been bugging me. I've learnt that the PIN register should be used to READ a pin (my first attempt used the Port register, to no effect). There are also two other registers used for setting the port type (I/O) and the other for enabling pullups. Which one is which, and how do I make:

:arrow: An input pin without pullup enabled
:arrow: An input pin with pullup enabled
:arrow: An output pin without pullup enabled
:arrow: An input pin with pullup enabled

So far I have scraped through with BASCOM by trial and error. BASCOM also places the MSB first in binary (obvious, but not at first to me) which originally resulted in much hair-pulling. I've looked in avrbeginners.net (it was a wrench because I no longer consider myself an absolute beginner) but it has a very complexd and long-winded explanation, with a simple yet confusing table. Any ideas?

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

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

I don't think you can have pullups - if the line is input it is high impedance, if it's output it's driven one way or the other.

As for the endian issue.. I'd use C if I where you ;)

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

Hi,

First off - there are no output pins with pullups enabled. Wouldn't be much point, since you are driving the thing anyway!

To set PORTB to an input write the DDRB to 0. I think BASCOM-AVR has another comand for that though ("config portb input" or something like that).

When a pin is an input, writing a '1' to the bit in the PORTB register will enable the pull-up on that pin. To turn off the pull-up, write a '0' to that pit in the PORTB register.

Of course I'm using DDRB and PORTB as examples, it will work with any port.

Regards,

-Colin

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

Ok c_offlyn, so as I understand it, the DDR register sets the port mode, while the PORT register sets the pullups. Yes, BASCOM has a "Set PortB=Input" command - although I suppose this is just a neater way of saying DDRB=0. As for learning C or ASSEMBLER, nuts to that! It's too difficult, and as I already use VB BASCOM's modified BASIC is a breeze to use.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

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

Hi,

Yup - thats it. When a pin is set to input, the PORT register controls that pin's pull-up. If the pin is set to output, then the PORT register controls the logical value on the pin.

Thats the one thing to remember as well if you switch a pin from input to output or vis-versa - there may be some data in the PORT register that wasn't what you were expecting (ie: you had a pull-up enabled, so when you switch it to an output that line will now be high).

Regards,

-Colin

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

c_oflynn wrote:

Yup - thats it. When a pin is set to input, the PORT register controls that pin's pull-up. If the pin is set to output, then the PORT register controls the logical value on the pin.

Just like it says in the datasheet. [Amazing that Atmel collected all that information about each type of chip, put it into a single document, makes it searchable for words and phrases in .PDF format, and updates it from time to time.]

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

DanielOConnor wrote:
I don't think you can have pullups - if the line is input it is high impedance, if it's output it's driven one way or the other.

As for the endian issue.. I'd use C if I where you ;)

YES you can have pullups. An input configured with it's port register written with a '1' enalbed the pullup. A '0' makes it hi-impediance (hi-z).

Bravo c_oflynn for clarifying this!

Regards

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

But do read your manual on the device port you want to use a pullup on because some of the avr's have more than 4 ports and the extra ports might not have pullups!

I believe all of the basic 4 ports have pullups. Of course, if you enable the uart on the 8515 the rx/tx pins are no touched by your in/out/pullup/hi-z settings on those two pins until the uart if switched off.

Regards