Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Is it possible to combine two 8 bit ports in 877A as a single 16 bit port?

Status
Not open for further replies.

vinodstanur

Advanced Member level 3
Joined
Oct 31, 2009
Messages
751
Helped
114
Reputation
234
Reaction score
114
Trophy points
1,333
Location
Kerala (INDIA)
Activity points
7,054
Is it possible to combine two 8 bit ports in 877A as a single 16 bit port so that i could perform 16bit shift and other bitwise operations...
 

Not normally but you can of course write software that 'carries' the end bit from one port into the other.
To output a 16 bit number to two ports (using PORT B and C in my example) you can do this:
PORTB = (Number & 0xFF00) >> 8;
PORTC = Number & 0xFF;

To combine them into a 16 bit number, do the opposite:

Number = (PORTB << 8 ) | PORTC ;

Brian.
 

yes. just create a shadow 16-bit variable and perform right or left shift on it.

using the same example, you can actual great a 32-bit or even a 64-bit variable and shift it left/right.

---------- Post added at 21:05 ---------- Previous post was at 20:31 ----------

a quick example would be:

Code:
#define MSB_PORT PORTC
#define LSB_PORT PORTB
#define OUT_WORD(word_t) {MSB_PORT = 0xff00 & (word_t); LSB_PORT = 0x00ff & (word_t);}
...

unsigned char sPort_16bit=0;

...

  sPort_16bit = sPort_16bit << 1;  //left shift shadow variable
  OUT_WORD(sPort_16bit);          //output the shadow variable on port
...

so all you need is to update the shadow variable.

---------- Post added at 21:06 ---------- Previous post was at 21:05 ----------

and you can scale up the approach to any bit length fairly easily.
 

Is it possible to combine two 8 bit ports in 877A as a single 16 bit port so that i could perform 16bit shift and other bitwise operations...
This is a dirty way which it depends on MCU,compiler,endian.....
Poor portability, good performance....
EX: to use HTC for PIC16
Code:
volatile unsigned short int PORTCB @ 0x00D; // PORTCB.L(PORTB):0x0D, PORTCB.H(PORTC):0x0E

void test( void )
{
   PORTCB <<= 1;
}
 

Just initialize a 16 bit variable & out the lower 8 bit on a port by 'ANDing' with 0x00ff & upper 8 bit on another port by 'ANDing' with 0xff00.
Regards,
Jerin. :)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top