Jump to content
Sign in to follow this  
zoom

Digital Input Access

Recommended Posts

Hi,

 

I have numbered input pins sequentially 0 through n. I want to map these pin numbers to their hardware port.pin.

The concept like this: pinmap [ porta.5, porta.4, porta.3, portc.5, portc.4 ...]. And then do testpin( pinmap(pin) );

 

Here's what I'm doing now, but it feels like such a kludge:

 

	unsigned char port =  pinmap[pin] & 11100000b;
unsigned char bitnum = pinmap[pin] & 00000111b; 

switch (port)
{
	case A0: //101
	val = test_bit( porta, bitnum );
	break;	

	case B0: //110
	val = test_bit( portb, bitnum );
	break;

	case C0: //111
	val = test_bit( portc, bitnum );
	break;
}

Can anyone sugget a better way?

Thanks a lot everyone,

Colin

Share this post


Link to post
Share on other sites

Colin,

I have numbered input pins sequentially 0 through n. I want to map these pin numbers to their hardware port.pin.

The concept like this: pinmap [ porta.5, porta.4, porta.3, portc.5, portc.4 ...]. And then do testpin( pinmap(pin) );

Does this mapping want to be done at runtime, or can it be done at compile time?

 

Regards

Dave

Share this post


Link to post
Share on other sites
Colin,
I have numbered input pins sequentially 0 through n. I want to map these pin numbers to their hardware port.pin.

The concept like this: pinmap [ porta.5, porta.4, porta.3, portc.5, portc.4 ...]. And then do testpin( pinmap(pin) );

Does this mapping want to be done at runtime, or can it be done at compile time?

 

Regards

Dave

 

The pin number assignments are fixed, so compile time it is.

 

Also I should have written: pinmap[pin] above.

 

Thanks a lot for you help,

Colin

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...