CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to read a nibble?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
eguti



Joined: 01 Jan 2012
Posts: 2
Location: Brazil

View user's profile Send private message Send e-mail

How to read a nibble?
PostPosted: Fri Jan 06, 2012 12:16 am     Reply with quote

The code "value = input_x()" could read an entire Byte from 8 pins. But, how to read just 4 pins in the same way of the input_x() command?

I think is easy with input(PIN_X) command, but is there another way?

thank
n-squared



Joined: 03 Oct 2006
Posts: 99

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Jan 06, 2012 12:25 am     Reply with quote

There is no way of reading a nibble DIRECTLY.
What you can do is input_x() and AND it with a mask:
Code:

  X = input_b() & 0x0F; / bits 0 to 3
  Y = input_b() >> 4; // bits 4 to 7
  Z = (input_b() & 0x3C) >> 2; // bits 2 to 5


BR
NN
_________________
Every solution has a problem.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Fri Jan 06, 2012 2:56 am     Reply with quote

As an extra comment, look at the 'swap' function in CCS. This uses a single byte command to swap the high and low nibbles in a byte. Much more efficient than four rotations.

Best Wishes
eguti



Joined: 01 Jan 2012
Posts: 2
Location: Brazil

View user's profile Send private message Send e-mail

PostPosted: Fri Jan 06, 2012 8:01 am     Reply with quote

Thanks Ttelmah and n-squared. I will try both tips.

bye
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group