View previous topic :: View next topic |
Author |
Message |
crukid88
Joined: 04 Oct 2007 Posts: 14
|
Newbie here,Help on Accessing bits and nibbles of a Byte |
Posted: Thu Oct 04, 2007 8:01 am |
|
|
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
|
|
Posted: Thu Oct 04, 2007 8:12 am |
|
|
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
|
|
Posted: Thu Oct 04, 2007 9:13 am |
|
|
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
|
|
Posted: Thu Oct 04, 2007 9:29 am |
|
|
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
|
|
Posted: Thu Oct 04, 2007 10:26 am |
|
|
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
|
|
Posted: Sat Oct 06, 2007 6:16 am |
|
|
This is really a big help to me as a beginner thanks |
|
|
|