Port read & write

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
rich
Posts: 81
Joined: 19 November 2015, 12:23 PM

Port read & write

Post by rich »

For the statement

var = Register.PortA

Does var get the device port register or the inputs from the device pins?

Thanks
Richard
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Port read & write

Post by dkinzer »

rich wrote:Does var get the device port register or the inputs from the device pins?
Register.PortA returns the value last written to Register.PortA. If you want to read the inputs to the pins you must use Register.PinA. That only works, of course, for pins that are configured as inputs. For pins that are outputs the value of the last value written to the corresponding bit in the Port register unless an external driver is forcing the pin to a different state (a situation that should be avoided).

The attached image, excerpted from an AVR datasheet, illustrates how this works. The Pxn represents an external pin. Above that is the pullup resistor that is enabled by the gate above it. The bottom portion shows the input circuitry while the middle of the right side represents the PORTx latch. The upper right is the data direction control which enables the output driver if the pin is configured to be an output.
Attachments
AVR_IO.jpg
AVR_IO.jpg (63.94 KiB) Viewed 3227 times
- Don Kinzer
rich
Posts: 81
Joined: 19 November 2015, 12:23 PM

Post by rich »

Yes thanks for confirming.

I checked out the data sheer and that is why i ask because i was not sure how ZBasic worked.

Thanks again.

I sure get fast answers !!!
It is great.

Richard
Post Reply