Not or Invert
+ Reply to Thread
Results 1 to 12 of 12

Thread: Not or Invert

  1. #1
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237

    Talking Not or Invert

    Very Very Quick question :-

    I have a digital input..... How do I invert it in software , Brain freeze :-(

    BR
    Andy

    Thank you all for reading

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,215

    Default Re: Not or Invert

    Variable = ~DigitalInputPin
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237

    Default Re: Not or Invert

    so :-

    Not_PB2 = ~DigitalInputPin

    That easy ?

    Thank You

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,215

    Default Re: Not or Invert

    Andy,

    Are you looking for even an easier way?
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237

    Default Re: Not or Invert

    Not at all..

    Just couldn't get it

    Old Age

    Thank you

  6. #6
    Join Date
    Aug 2003
    Location
    Australia
    Posts
    1,043

    Default Re: Not or Invert

    Quote Originally Posted by sayzer View Post
    Are you looking for even an easier way?
    Yeah, increment it.
    If the bit was zero it will increment to one.
    If the bit was one, it will overflow to zero.

    They will both probably end up the same in assembler though.

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,872

    Default Re: Not or Invert

    The @ INC _yourvariable may be even smaller in regard to code size.

    Evil, Art!

    Ioannis

  8. #8
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237

    Default Re: Not or Invert

    Quote Originally Posted by Art View Post
    Yeah, increment it.
    If the bit was zero it will increment to one.
    If the bit was one, it will overflow to zero.

    They will both probably end up the same in assembler though.
    Thank you :-)

  9. #9
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,215

    Default Re: Not or Invert

    Quote Originally Posted by Art View Post
    Yeah, increment it.
    If the bit was zero it will increment to one.
    If the bit was one, it will overflow to zero.

    They will both probably end up the same in assembler though.
    Or decrement it, the same

    or the grandpa's way :

    Variable = NOT DigitalInputPin
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  10. #10
    Join Date
    Aug 2003
    Location
    Australia
    Posts
    1,043

    Default Re: Not or Invert

    incf operates on a byte. It’s ok if you have a whole byte to waste on a single bit.
    You can keep incrementing the byte, and it will toggle bit zero.

    To isolate a bit, I don’t think can be less than two instructions:
    Code:
    movlw    B'00000001'
    xorwf    bits    ,F

  11. #11
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,215

    Default Re: Not or Invert

    Quote Originally Posted by Art View Post
    ...
    To isolate a bit, I donít think can be less than two instructions:
    IF Darrel were here, he could/would come up with something magical to make it less, I think.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  12. #12
    Join Date
    Aug 2003
    Location
    Australia
    Posts
    1,043

    Default Re: Not or Invert

    That’s a tough ask

    I remember PBP used to disassemble BYTE = BYTE + 1 to a copy and add, which could be optimised in assembler,
    but later, I believe it was improved, and PBP will now increment (or decrement) a byte by 1 in a single instruction.

    Yeah Darrel. The timing of that pissed me off as much as anything else.
    We had an LCD graphics competition. It would still be here in a thread somewhere. He didn’t see me flog him in the end.
    He was faster than me, so if I mentioned something it would be done before I got back here, running on a simulator so I’d still have to do it.
    I’d love to see it again, but wouldn’t know how to search for it here.
    Last edited by Art; - 27th February 2019 at 12:01.

Similar Threads

  1. How to invert OWOUT pin in assembly?
    By Norbert in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 7th December 2011, 07:36
  2. invert byte and display
    By Max Power in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th June 2008, 16:36
  3. LONG var, conditional invert sign
    By dcorraliza in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th May 2008, 19:47
  4. Help me to invert voltage
    By vios in forum Schematics
    Replies: 2
    Last Post: - 17th September 2007, 04:18
  5. Serial - to invert or not to invert...?
    By barkerben in forum General
    Replies: 2
    Last Post: - 1st December 2004, 21:47

Members who have read this thread : 17

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts