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:
Port is bounded from 1 to 8 if you havent guessed 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!
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;
}
thanks in advance!