Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:24 17 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Port Function

Author Message
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 08:28am 10 Jun 2015
Copy link to clipboard 
Print this post

Working on a project where I need to read 4 I/O lines at one time and write 4 I/O lines at one time. So for the write I see I can use the port command something like this...

port(2,4) = &HF

But for the function to read a 4 bit port does one do this...

A = port(2,4)

or

A = &H(port(2,4))

assigning the 4 bits of the port to a variable?

Thanks!!!!!
 
Chris Roper
Senior Member

Joined: 19/05/2015
Location: South Africa
Posts: 280
Posted: 08:51am 10 Jun 2015
Copy link to clipboard 
Print this post

  viscomjim said   But for the function to read a 4 bit port does one do this...

A = port(2,4)

or

A = &H(port(2,4))


The first option, if you then want it displayed:

PRINT HEX$(A)

or

PRINT BIN$(A, 4)

To separate the bits you could use:

bit0 = A AND 1
bit1 = (A >> 1) AND 1
bit2 = (A >> 2) AND 1
bit3 = (A >> 3) AND 1

Cheers
Chris


Edited by Chris Roper 2015-06-11
http://caroper.blogspot.com/
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 10:49am 10 Jun 2015
Copy link to clipboard 
Print this post

Thanks Chris, I will give this a whirl.
 
Chris Roper
Senior Member

Joined: 19/05/2015
Location: South Africa
Posts: 280
Posted: 11:47am 10 Jun 2015
Copy link to clipboard 
Print this post

If you run this code you can watch the BIT's as you play with the input signals:

[code]
SetPin 2,din
SetPin 3,din
SetPin 4,din
SetPin 5,din

Do
Print Chr$(27)+"[2;2H"; ' locate Cursor row 2 col 2

a = Port(2,4)
Print Bin$(a,4);

Pause 100 ' prevent flashing on cursor relocate
Loop
[/code]

http://caroper.blogspot.com/
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025