Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 19:12 07 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 : Bitwise AND/OR

Author Message
thirsty
Newbie

Joined: 22/06/2016
Location: Australia
Posts: 34
Posted: 11:36pm 18 Jul 2016
Copy link to clipboard 
Print this post

Hi Guys

So I've got this statement:

PORT(2,3,7,4,9,1)=&B10011001

What I'd like to do is conditionally change the first bit. I know I can AND/OR to change it but I'm not sure of the syntax.

I was thinking:

PORT(2,3,7,4,9,1) AND &B10000000

Would that work?
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 03:19am 19 Jul 2016
Copy link to clipboard 
Print this post

A little reference:

[code]
Truth tables:

AND
=========
| 0 | 1
---------
0 | 0 | 0
---------
1 | 0 | 1

OR
=========
| 0 | 1
---------
0 | 0 | 1
---------
1 | 1 | 1
[/code]

AND only gives a 1 when both values are 1
OR only gives a 0 when both values are 0

This is for a single bit. So each single bit is used when AND or OR numbers.

If you want to make a single bit 1 then use OR with a bit 1 in that position.
If you want to make a single bit 0 then use AND with a bit 0 in that position.
Edited by MicroBlocks 2016-07-20
Microblocks. Build with logic.
 
thirsty
Newbie

Joined: 22/06/2016
Location: Australia
Posts: 34
Posted: 02:57pm 19 Jul 2016
Copy link to clipboard 
Print this post

Thanks for that.

Do you know the syntax to do that in MMBasic?
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6269
Posted: 04:45pm 19 Jul 2016
Copy link to clipboard 
Print this post

I think you can read the state of pins that have been set as outputs. If so,
currentstate = PORT(2,3,7,4,9,1) ' read the current settings
otherpins = currentstate AND &B01111111
toppin = currentstate AND &B10000000 ' value is 128 if set or zero if not set

'to set top pin leaving the other pins as they were
PORT(2,3,7,4,9,1)=&B10000000+otherpins
' to reset top pin
PORT(2,3,7,4,9,1)=&B00000000+otherpins ' or just PORT(2,3,7,4,9,1)=otherpins


If that doesn't work, you will need to keep a record of the settings of the other pins.

Jim
VK7JH
MMedit
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2431
Posted: 07:37pm 19 Jul 2016
Copy link to clipboard 
Print this post

i feel i must be missing something. what is wrong with:

pin(9) = 1
to set the top bit high,

pin(9) = 0
to clear the top bit, and,

pin(9) = not pin(9)
to flip the top bit?

(assuming the LAST pin specified in a PORT command is the topmost bit, just checked the manual and corrected post for this)


cheers,
rob :-)Edited by robert.rozee 2016-07-21
 
thirsty
Newbie

Joined: 22/06/2016
Location: Australia
Posts: 34
Posted: 08:52pm 19 Jul 2016
Copy link to clipboard 
Print this post

Actually Rob you are quite right - I think I was just trying to be a bit too clever :) and focusing on the need to change the pattern over the entire port range. The bit I'm trying to turn on/off is indeed on a particular pin and I can just turn it on or off by using the Pin command.

Thanks again all.
 
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