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

struct syntax

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



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

struct syntax
PostPosted: Mon Dec 06, 2004 2:48 pm     Reply with quote

Hello,

I am planning to use a struct to take care of portb status.

The reason is that I can set all pins at the same time.

like:

#byte portb = 0xf81

struct {
int1 pin0;
int1 pin1;
int1 pin2;
int1 pin3;
int1 pin4;
int1 pin5;
int1 pin6;
int1 pin7;
} port;

port.pin0 = 1;
port.pin3 = 1;

portb = port; // bits 0 and 3 goes high

Is this construct correct and/or is there a better way?

Thank you.
Guest








PostPosted: Mon Dec 06, 2004 3:07 pm     Reply with quote

How about this:


Code:
struct {
int1 pin0;
int1 pin1;
int1 pin2;
int1 pin3;
int1 pin4;
int1 pin5;
int1 pin6;
int1 pin7;
} portb;

#byte portb = 0xf81


Code:
portb.pin0 = 1;
portb.pin3 = 1;


or

Code:
portb = {1, 0, 0, 1, 0, 0, 0, 0};
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Mon Dec 06, 2004 3:34 pm     Reply with quote

Basicaly they are the same thing, your suggestion won't work how I need...

In main(), sensors are read and data processed.. depending on the results it sets bits.

In the end of all processing, the byte is copied to portb setting all bits at the same time.

What I asked was ideas on how to write this in C... using structs the code looks nice.
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

PostPosted: Mon Dec 06, 2004 4:05 pm     Reply with quote

future wrote:
Basicaly they are the same thing, your suggestion won't work how I need...

In main(), sensors are read and data processed.. depending on the results it sets bits.

In the end of all processing, the byte is copied to portb setting all bits at the same time.

What I asked was ideas on how to write this in C... using structs the code looks nice.


What is wrong with the "output_b()" command?

An incomplete (and untested) example:

Code:

void main(void)
{
   int portb_shadow;

   portb_shadow=0;
   while(1)
   {
      output_b(portb_shadow);
      portb_shadow ^= 0xFF;
      delay_ms(100);
   }
}

_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
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