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.

Bit of a port question!

Status
Not open for further replies.

hooray

New Member
Hey there, I'm using a PIC1846K20 for a project at the moment and I'd like to know, is there a way to call a specific pin on a I/O port without pointing to the specific name to it? I've got some code that works the way I want it to but its LOOOOONG, have a look for yourself:

Code:
void PortOutSetOn(unsigned short Port)
 {
	
	if (Port == 1)
	PORTDbits.RD0 = 1;
	if (Port == 2)
	PORTDbits.RD1 =1;
	if (Port == 3)
	PORTDbits.RD2 = 1;
	if (Port == 4)
	PORTDbits.RD3 =1;
	if (Port == 5)
	PORTDbits.RD4 = 1;
	if (Port == 6)
	PORTDbits.RD5 =1;
	if (Port == 7)
	PORTDbits.RD6 = 1;
	if (Port == 8)
	PORTDbits.RD7 =1;
 }
Port is bounded from 1 to 8 if you havent guessed :p so yeah, is there a way to assign the turning on of a specific PORTD bit to a corresponding value of Port, without affecting any of the other pins on PORTD?

thanks in advance!
 
nah thats not doing the trick, sorry. either im having some other things going on in the other functions i dont know about yet, or i may need to have a closer look at the operator
 
The code I posted does exactly the same as the routine you posted.

Mike.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top