View previous topic :: View next topic |
Author |
Message |
output flipped Guest
|
dong |
Posted: Wed Apr 26, 2006 12:16 am |
|
|
I am outputting a 8 bit value.I am outputting on port d of my pic
I am using output_d(value);
Is there a way i can flip the output value??
eg.change 00000001 to 10000000
or 10000010 to 01000001 |
|
|
RHA
Joined: 25 Apr 2006 Posts: 31 Location: Germany
|
|
Posted: Wed Apr 26, 2006 1:07 am |
|
|
I think it will work with
output_d(swap(value));
But i didnīt verified.
greets
RHA
Oh no, it doesnīt work. swap only exchanges the nibbles. sorry for that. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Apr 26, 2006 1:33 am |
|
|
This looks like another homework assignment:
- A non-registered user
- A thread title not even closely matching the question (...dong ????)
- Too lazy to use Google or the search function of this forum. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed Apr 26, 2006 9:15 am |
|
|
DING!!!
Even unregistered, LAZY, 'can't-find-the-search-button' students need a little help now and then.
Code: |
for(i = 0, j = 7; i < 8; i++, j--)
{
if(bit_test(variable1, j))// original variable
{
bit_set(variable2, i);// stuff swapped number into this variable
}
else
{
bit_clear(variable2, i);
}
}
|
Ronald |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Apr 26, 2006 9:18 am |
|
|
In my opinion, they then need to be polite, respectful and ask questions that are not repeats. |
|
|
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Wed Apr 26, 2006 9:43 am |
|
|
How about ....
Code: | int8 i;
int8 from;
int8 to;
from = 0b10000010; // example start value
for (i=0; i<8; i++)
shift_right(&to, 1, shift_left(&from, 1, 0));
|
result is in 'to', which is 0b010000001 in this example. _________________ Regards,
Simon. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Apr 26, 2006 9:57 am |
|
|
sjbaxter, rnielsen,
... all nice solutions, but what I tried to point out is that this thread is a repeat question of code already in the Code Section. If you want to show off then try to improve on the code that is in the Code Section and we will all benefit from it.
http://www.ccsinfo.com/forum/viewtopic.php?t=23364 |
|
|
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Wed Apr 26, 2006 12:02 pm |
|
|
ckielstra,
I wasn't trying to show off ... It was a simple answer to the posters original question.
However, rather than leaving cryptic clues to the original question,
Quote: | Too lazy to use Google or the search function of this forum.
|
why didn't you just post a link to the relavent Code Section topic in the first place ! or even state that an answer exists in the Code Section, rather than just having a go at the poster.
It would have saved us all some time. _________________ Regards,
Simon. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Apr 26, 2006 1:31 pm |
|
|
Sorry, I shouldn't have said you were showing off.
I get a bit upset from all those students asking questions that can be answered by a simple search in this forum. Now our Mr/Mrs Output Flipped got an easy answer without having learnt how to find the answer himself. |
|
|
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Wed Apr 26, 2006 1:56 pm |
|
|
ckielstra,
No problem. I agree with your fustrations, but until the forum administrator does something to stop guest posts, then we have to live with it.
I also don't mind giving away solutions which are a few lines of code that are genuine 'engineering' problems. As you may have seen from my previous posts, I do draw the line at 'students' who can't be bothered learning the basics of the C language syntax but still put forward someone elses edited code that isn't even compilable.
Whilst, in the short term, the're getting their homework solved for free, I live in the knowlege that they are in for a big shock if they try getting a job in this business. (I know ... I've interviewed a few ) _________________ Regards,
Simon. |
|
|
|