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.
viscomjim Guru Joined: 08/01/2014 Location: United StatesPosts: 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 AfricaPosts: 280
Posted: 08:51am 10 Jun 2015
Copy link to clipboard
Print this post
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-11http://caroper.blogspot.com/
viscomjim Guru Joined: 08/01/2014 Location: United StatesPosts: 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 AfricaPosts: 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: