View previous topic :: View next topic |
Author |
Message |
chingB
Joined: 29 Dec 2003 Posts: 81
|
How to read a specific bit of a register? |
Posted: Mon Feb 02, 2004 5:50 pm |
|
|
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
|
|
Posted: Mon Feb 02, 2004 6:16 pm |
|
|
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
|
Re: How to read a specific bit of a register? |
Posted: Mon Feb 02, 2004 6:17 pm |
|
|
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. |
|
|
h Guest
|
|
Posted: Tue Feb 03, 2004 5:34 am |
|
|
which method requires less memory? |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Tue Feb 03, 2004 8:01 am |
|
|
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
|
|
Posted: Tue Feb 03, 2004 8:32 am |
|
|
Usually the same amount of memory. |
|
|
|