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 declare variable like this

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



Joined: 30 Mar 2004
Posts: 8

View user's profile Send private message Visit poster's website

How to declare variable like this
PostPosted: Tue Jul 20, 2004 1:33 am     Reply with quote

I have array

BYTE Dout[4];


I want to declare bit 5 in Dout[2] is VP for use like this

VP=1;
or
VP=0;

How can I declare VP ?

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 20, 2004 2:56 am     Reply with quote

If you don't want to use a union and bitfields, then you
can use the method shown below. Compile this program
and look at the assembly listing (.LST file) to see that it works.

Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

BYTE Dout[4]; 
#byte Dout2 = Dout + 2   
#bit VP = Dout2.5

//====================================
void main()
{

VP = 1;

while(1);
}
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Jul 20, 2004 8:34 am     Reply with quote

Would this also work?

bit_set(Dout[2], 5);// sets bit 5 of Dout[2]

or

bit_clear(Dout[2], 5);// clears bit 5 of Dout[2]

Ronald
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Tue Jul 20, 2004 8:46 am     Reply with quote

I'm sure that works but it does not read as well as this;

VP=1;
or
VP=0;
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