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

How to define a bit from an address

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



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

How to define a bit from an address
PostPosted: Fri Oct 15, 2004 6:19 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 15, 2004 6:50 am     Reply with quote

Quote:
I have got a register at the particular address in another device.
Say #define ADDR 0x01


What do you mean by 'Another device'?

This post shows how to use #byte/#bit:
http://www.ccsinfo.com/forum/viewtopic.php?p=33797&highlight=#33797
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

PostPosted: Fri Oct 15, 2004 6:53 am     Reply with quote

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

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

PostPosted: Fri Oct 15, 2004 8:01 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 15, 2004 8:14 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 15, 2004 8:25 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 15, 2004 9:02 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 15, 2004 9:59 am     Reply with quote

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.
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