program with ports

Thread Starter

Sonia1234

Joined Sep 28, 2011
3
Hello friends,

I was working on a project and just got confused where I need to write a program and I really need your valuable opinion on it. My question is how would you write a sample program that tests bit 3 of an input signal coming from port 09h and outputs the word to port 09FBh if this bit is set or to port 0Ah if this bit is reset?
I have brainstormed many times but most of them are not working. Kindly enlighten me with your outputs.
Thanks alot in advance
 

chrisw1990

Joined Oct 22, 2011
551
show us what youve done, tell us what your programming, maybe well help.. its difficult to know what your doing when you could be using AVR, ARM, PIC, FPGA.. and any number of different compilers for assembly or C.
 

@android

Joined Dec 15, 2011
178
I can tell you ruff algorithm if you are looking for it.
1. Configure port to read as i/p port
2. Read data from the port store it in one of the registers
3. Mask the data bits except bit 3 which you intend to read
4. Rotate data bits to right
5. OR it with '0'
6. Read the result
 

Thread Starter

Sonia1234

Joined Sep 28, 2011
3
I can tell you ruff algorithm if you are looking for it.
1. Configure port to read as i/p port
2. Read data from the port store it in one of the registers
3. Mask the data bits except bit 3 which you intend to read
4. Rotate data bits to right
5. OR it with '0'
6. Read the result
Thanks for the reply but how would i mask all the data bits except bit 3 at once, the usual way that I am familiar with is:
AND 00H
AND 01H
AND 03H and so on till bit 15
How would I merge all of this in one statement?
 

MrChips

Joined Oct 2, 2009
30,806
Firstly, tell us which processor you are using.
Secondly, what language and platform are you using.
Thirdly, tell us in a broader picture what you are attempting to do.

To determine the state of a single bit, AND with a mask that has a single bit set to 1 at that bit position.

For example, to determine bit-4

AND 0b0001000

You can unmask mulitple bits with the same mask. For example, to unmask bit-7 and bit-4

AND 0b1001000

(I have seen students attempting to read an 8-bit port and converting it to decimal by unmasking individual bits and combining them using powers of 2 to form the decimal value. I hope this is not what you are attempting to do.)

There are 10 types of people in the world. Those who understand binary and those who don't.
 
Top