View previous topic :: View next topic |
Author |
Message |
atabac_2000
Joined: 21 Apr 2004 Posts: 10
|
variable bit mapping to different IO port |
Posted: Tue May 25, 2004 9:11 pm |
|
|
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 |
Posted: Wed May 26, 2004 5:30 am |
|
|
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
|
|
Posted: Wed May 26, 2004 9:13 am |
|
|
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; |
|
|
|