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

Newbie here,Help on Accessing bits and nibbles of a Byte

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



Joined: 04 Oct 2007
Posts: 14

View user's profile Send private message

Newbie here,Help on Accessing bits and nibbles of a Byte
PostPosted: Thu Oct 04, 2007 8:01 am     Reply with quote

Does anyone know how to access nibbles and bits of a byte. Also same with the Word,how to access it by byte. Help really needed hope you could advice.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Oct 04, 2007 8:12 am     Reply with quote

Look in the CCS manual at the bit_clear(), bit_set(), and bit_test() functions, also look at the shift, rotate, and swap functions. It wouldn't hurt to read the manual cover to cover.

The "old school" way to set a bit is to logically AND the byte with a "mask" byte which has the required bit set. You clear a bit by ORing with a mask with all bits 1 except the specified bit. You test a bit by ANDing and then checking for zero.
_________________
The search for better is endless. Instead simply find very good and get the job done.
crukid88



Joined: 04 Oct 2007
Posts: 14

View user's profile Send private message

PostPosted: Thu Oct 04, 2007 9:13 am     Reply with quote

so theres no way of directly accessing it?like for example bits in an interrupt register or the TRISB where we set it like let say TRISB.F1 etc...?
TobyHarris



Joined: 27 Sep 2007
Posts: 5

View user's profile Send private message

PostPosted: Thu Oct 04, 2007 9:29 am     Reply with quote

Also look at make8 for splitting a word or long word up into its constituent bytes.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu Oct 04, 2007 10:26 am     Reply with quote

There are ways to access the different registers, directly.

First you need to define the address of the register and give it a name:

Code:
#byte T2CON = 0xFCA // timer2 control


Then you can define individual bits within that address:

Code:
// T2CON bits
#bit TMR2ON = T2CON.2// timer2 ON/OFF bit


Now, you can assign a value to that bit:

Code:
TMR2ON = 0;// turn off timer2


Just look up the addresses of each register, in the spec. sheet, and you're ready to fly. The addresses will vary depending on the part being used. This example is for an 18F2525.

Ronald
crukid88



Joined: 04 Oct 2007
Posts: 14

View user's profile Send private message

PostPosted: Sat Oct 06, 2007 6:16 am     Reply with quote

This is really a big help to me as a beginner thanks
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