![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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 | |
| |
| | (permalink) | |
| Quote:
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?. | ||
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| 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! | |
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| 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 | |
| |
| | (permalink) |
| You do not need the mask if temp is a 16 bit unsigned. Good chance the your integers are unsigned by default. | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| 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 |