PORTA or PINA

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

Hi

I’m a bit confused, although I never use the bit level access provided in the Code Vision AVR I have seen others do, but why use PINA instead of PORTA?
The Code Vision AVR user manual suggests using: “PINA.1” for reading bit 1 of port A.

DDRA.1=0;

/* test bit 1 input of port A */
If(PINA.1)

Why not use

If(PORTA.1)

What is the difference between the two codes?
Thanks

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

Hi,

Pin* is for read, Port* is for write and DDR* is for direction...

* = Register ( A, D,C...)

You must also do it so in Assembler ;-)

Squeezy-Power

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

PIN* is the register you use to read the value on a port if it is an input (so if the corresponding bit in DDR* is '0'). PORT* is used to output values, or to read earlier outputted values back.

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

All of this is explained in the datasheet too.

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

Thanks

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

It's always nice to remember that the PIN register can give you feedback to possible fault states on I/O pins. If a pin is set to output and it's port bit is high but it's pin bit is low, that means that there is enough current being drawn from the I/O pin to cause a voltage drop to bellow the low level logic state. This is usually bad.

-Curiosity may have killed the cat
-But that's why they have nine lives

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

Let us not forget that on many (if not all) of the newer AVR's you can also use the PINx register bits to 'toggle' the output pin. Was'nt it nice of me to add more confusion :-) .