Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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:D
 
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.
 
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 :p
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top