Checking port for on or off bits

Status
Not open for further replies.

pixman

Member
Hi

i have run it a wall and can't seem to figure out how to check a output or input port if any bit is on.

What i want to do is to check if any bit on the port is on then i will switch a on a bit on anther port.and if the nothing is on then switch off that bit on the other port

if any bit on portb is on then switch portc,1 on.
Is all bits on portb are off then switch portc,1 off
 
Assuming high is on then,
Code:
    if(portb!=0)
        portc.1=1;
    else
        portc.1=0;

You didn't state a language so I assumed C.

Mike.
 
Here's for the whole port.

Make sure that the PortB and PortC are digital i/o. Then set the data direction as input for PortB, and output for PortC. I would use a shadow register like:

Code:
Switches = PORTB
PORTC = Switches
 
Code:
	movf	PORTB,w
	btfss	STATUS,Z
	bcf	PORTC,1
	btfsc	STATUS,Z
	bsf	PORTC,1

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…