Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 28th September 2007, 10:00 PM   (permalink)
Default PICC pointer to PORTs possible?

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 is offline  
Old 28th September 2007, 10:06 PM   (permalink)
Default

Quote:
Originally Posted by serj.t.s
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?.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 28th September 2007, 10:11 PM   (permalink)
Default

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.
serj.t.s is offline  
Old 28th September 2007, 10:54 PM   (permalink)
Default

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!
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 28th September 2007, 11:05 PM   (permalink)
Default

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.
3v0 is online now  
Old 28th September 2007, 11:33 PM   (permalink)
Default

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
serj.t.s is offline  
Old 28th September 2007, 11:46 PM   (permalink)
Default

You do not need the mask if temp is a 16 bit unsigned. Good chance the your integers are unsigned by default.
3v0 is online now  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Help with a project helz15 General Electronics Chat 39 15th October 2007 03:33 PM
lack of signal on PIC Ports Hesam Kamalan Micro Controllers 4 7th July 2006 02:00 PM
Help w/ C code.. how to clear array pointer buffer? DanD Micro Controllers 1 25th June 2006 10:04 PM
Got DS18S20 PICC code to work! Oznog Micro Controllers 1 6th July 2004 06:22 AM
Game port to Midi ports? grrr_arrghh General Electronics Chat 0 31st March 2004 09:03 PM



All times are GMT. The time now is 09:17 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker