PICC pointer to PORTs possible?

Status
Not open for further replies.

serj.t.s

New Member
Hi I've just beginned programming pics in C and I was trying to "merge" ports C and D together in one 16bit variable, does anyone have an idea on how can i do this?


Thank you
 
serj.t.s said:
Hi I've just beginned programming pics in C and I was trying to "merge" ports C and D together in one 16bit variable, does anyone have an idea on how can i do this?

Why would you want to?.

You could certainly easily write a function that takes a 16 bit variable and place the top eight bits to one port, and the bottom to another. However, I don't do C, but it's easy in any thing else, so presumably will be in C?.
 
Hi Nigel, I just though it would be more efficient and simple because I'll be manipulating those registers together with shifts and other operations but I guess I'll have to do it yout way.

Thanks for the reply.
 
It would only take 4 words, and 4 instruction cycles (4uS with a 4MHz clock) in assembler - it doesn't get any simpler and more efficient than that!
 
The direct answer is, you can if you compiler allows it.

When asking C questions please let us know what processor and compiler you are using. They differ enough that one needs to know.

I use CCS which has #bit and #byte directives that allow that sort of thing. But no #word. It may exist on 16 bit compilers.

A better, compiler independant, answer is along the line of what Nigel suggested. Declare a 16 bit shadow register (just a 16 bit variable) and do you crunching with it. When needed call a function to write the top 8 bits to C and the lower to D.

If you need speed make the copy function inline.
 
Hi, sorry about the lack of info.

I am using the PICC compiler from HI-Tec h.

And I ended up doing:
PORTC = temp;
PORTD = (temp >> 8) & 0xFF;

This compiler doesn't have BYTE(temp) or char(temp), but it worked this way. Btw I don't think the 0xFF mask is necessary. I guess I'll try it out tomorrow, i am soo lazy
 
You do not need the mask if temp is a 16 bit unsigned. Good chance the your integers are unsigned by default.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…