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 support@ccsinfo.com

variable bit mapping to different IO port

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



Joined: 21 Apr 2004
Posts: 10

View user's profile Send private message

variable bit mapping to different IO port
PostPosted: Tue May 25, 2004 9:11 pm     Reply with quote

I want to have an output port that has a variable name and its output PORT registers can be customizable as combination of available PORT reg.

lets say, how do you code this one:
INPUT set as a register with bits 0-5 mapped as PORTA<0:5> and bits 6-7 as PORTE<0:1>.
Ttelmah
Guest







Re: variable bit mapping to different IO port
PostPosted: Wed May 26, 2004 5:30 am     Reply with quote

atabac_2000 wrote:
I want to have an output port that has a variable name and its output PORT registers can be customizable as combination of available PORT reg.

lets say, how do you code this one:
INPUT set as a register with bits 0-5 mapped as PORTA<0:5> and bits 6-7 as PORTE<0:1>.

You don't.
Such a split mapping, is not allowable in any C. However you can simply 'mask' the parts, and combine these, so:
Code:

int8 getval() {
    return((input_a() & 0x3F)+((input_e() & 0x3)<<6));
}


Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 26, 2004 9:13 am     Reply with quote

This may not be exactly what you requested, but
I think it may help.

See Mark's method, in the following thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=17323
He puts all the i/o ports into one structure, and then
defines bitfields within it.

Then you can use the bitfields like this, even though
they are on different i/o ports:

lcd.enable = 1;

lcd.data = value;
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