CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

dong

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
output flipped
Guest







dong
PostPosted: Wed Apr 26, 2006 12:16 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 26, 2006 1:07 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 26, 2006 1:33 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 26, 2006 9:15 am     Reply with quote

DING!!!

Even unregistered, LAZY, 'can't-find-the-search-button' students need a little help now and then. Twisted Evil

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

View user's profile Send private message Visit poster's website

PostPosted: Wed Apr 26, 2006 9:18 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Wed Apr 26, 2006 9:43 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 26, 2006 9:57 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Wed Apr 26, 2006 12:02 pm     Reply with quote

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. Evil or Very Mad
_________________
Regards,
Simon.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Apr 26, 2006 1:31 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Wed Apr 26, 2006 1:56 pm     Reply with quote

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 Shocked )
_________________
Regards,
Simon.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group