View previous topic :: View next topic |
Author |
Message |
alexz
Joined: 17 Sep 2004 Posts: 133 Location: UK
|
How to define a bit from an address |
Posted: Fri Oct 15, 2004 6:19 am |
|
|
I have got a register at the particular address in another device.
Say #define ADDR 0x01
I want to work with separe bits, of this register, which is at ADDR address from the PIC.
What is the way to define a bit from this register?
Thanks _________________ Alex |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
|
alexz
Joined: 17 Sep 2004 Posts: 133 Location: UK
|
|
Posted: Fri Oct 15, 2004 6:53 am |
|
|
Another device ,means USBN9603, which has its own registers, and I have to WR/RD to/from them.
And I also need to work with its separate bits of each register. _________________ Alex |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Oct 15, 2004 8:01 am |
|
|
There are lots of ways to do it, structs, unions...but probably the best way for you would be to just read the value and then use
Code: |
bit_set()
bit_clear()
bit_test()
|
functions on it. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Fri Oct 15, 2004 8:14 am |
|
|
First, define the byte:
#byte SSPCON = 0x14
Then, define the individual bits inside that byte:
//SSPCON bits
#bit SSPM0 = SSPCON.0
#bit SSPM1 = SSPCON.1
#bit SSPM2 = SSPCON.2
#bit SSPM3 = SSPCON.3
#bit CKP = SSPCON.4
#bit SSPEN = SSPCON.5
#bit SSPOV = SSPCON.6
#bit WCOL = SSPCON.7
Now, you can simply manipulate those bits...
if(CKP)
{
do this;
}
or....
CKP = 0;
and so forth.
Ronald |
|
|
alexz
Joined: 17 Sep 2004 Posts: 133 Location: UK
|
|
Posted: Fri Oct 15, 2004 8:25 am |
|
|
rnielsen wrote: | First, define the byte:
#byte SSPCON = 0x14
Then, define the individual bits inside that byte:
//SSPCON bits
#bit SSPM0 = SSPCON.0
#bit SSPM1 = SSPCON.1
#bit SSPM2 = SSPCON.2
#bit SSPM3 = SSPCON.3
#bit CKP = SSPCON.4
#bit SSPEN = SSPCON.5
#bit SSPOV = SSPCON.6
#bit WCOL = SSPCON.7
Now, you can simply manipulate those bits...
if(CKP)
{
do this;
}
or....
CKP = 0;
and so forth.
Ronald |
It is very close to what I need, but what is the way to be able to have those bits in the following way:
if(SSPCONbits.CKP)
{
do this;
}
How can I define those bits to get them look like on the above? _________________ Alex |
|
|
alexz
Joined: 17 Sep 2004 Posts: 133 Location: UK
|
|
Posted: Fri Oct 15, 2004 9:02 am |
|
|
Basically,the story is that I have an external device to be controled by the PIC. I have to access this device's registers by bits.
I am writing first the address of the register, I am going to work with,
a pointer if you like,
then I need to set or clear bits in this register.
How to do that? _________________ Alex |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Oct 15, 2004 9:59 am |
|
|
If you have the CCS compiler, and you got it any time in the last
several months, then you already have a driver for the usbn960x
chips on your system.
It's called: USBN960x.C
It will be in this folder: c:\Program Files\Picc\Drivers.
(In fact, look at all the files in that folder that start with "usb").
To see how the driver reads and writes to registers in the USB chip,
look at these functions:
usbn_write()
usbn_read()
Look at how those functions toggle the control signals on the USBN960x
chip. Look at the USBN960x data sheet while you're doing this.
This will show you how the interface works. |
|
|
|