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 support@ccsinfo.com

How to read a specific bit of a register?

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



Joined: 29 Dec 2003
Posts: 81

View user's profile Send private message

How to read a specific bit of a register?
PostPosted: Mon Feb 02, 2004 5:50 pm     Reply with quote

Hi,

How can I be able to read a specific bit of a register? I want to know if it is a 1 or 0?

Like the case of LVDCON register were the bit IRVST can't be set but it can be read?

Need your help? thanx
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 02, 2004 6:16 pm     Reply with quote

Use a #bit statement to define the bit as a memory variable.
Then read it or write it, just like a variable. See how CCS
does this for the "t1_overflow" bit in the ex_freqc.c file:
http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_freqc.c
Then check the PIC data sheet to find the address and bit number
of the LVDCON register and the IRVST bit, and do it the same way.
Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

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

Re: How to read a specific bit of a register?
PostPosted: Mon Feb 02, 2004 6:17 pm     Reply with quote

chingB wrote:
Hi,

How can I be able to read a specific bit of a register? I want to know if it is a 1 or 0?

Like the case of LVDCON register were the bit IRVST can't be set but it can be read?

Need your help? thanx


How to test file 0x10, bit 1:

bit_test(*0x10,1)

This function will return TRUE (1) or FALSE (0) depending on the bit.

EDIT: PCM's method is good too. He beat me to the reply. Surprised
h
Guest







PostPosted: Tue Feb 03, 2004 5:34 am     Reply with quote

which method requires less memory?
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Tue Feb 03, 2004 8:01 am     Reply with quote

h wrote:
which method requires less memory?


Try both and look them over in the list file to see if they are different. Sometimes changing syntax reduces code size.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Tue Feb 03, 2004 8:32 am     Reply with quote

Usually the same amount of memory.
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