Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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.

New Articles From Microcontroller Tips

Back
Top