Bitwise not working


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Steve's does it... but if you do not want to fiddle with the upper nibble latch

    Code:
    For i=0 to $0F
        temp = PORTB & $F0 ' keep upper nibble
        PORTB= temp | i       ' keep upper, set lower to i
    next
    EDIT - Wow - a lot happens in 10 minutes - I was replying to Steve's #5 and 3 more got in there! :-)
    and attachments did not work for me yesterday - I got corrupt error when tried to open
    Last edited by paul borgmeier; - 18th October 2006 at 13:50.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    Thanks Paul and Steve.

    The solution I was expressing at #6 was the one Paul was describing. That is the solution. Steve clever but you do not keep the upper bits.

    I have not checked if the interrupt flag for the 4:7 of port b is affected if one is trying to write on input bits of the port. That renains to be checked.

    Thanks again,
    Ioannis

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Why not using Grandpa's traditional way?


    Code:
    i    VAR BYTE
    
    
    for i=0 to 15
        PORTB.0 = i.0
        PORTB.1 = i.1
        PORTB.2 = i.2
        PORTB.3 = i.3    
    NEXT i

    mister_e's #5 code is indeed short. Now it keeps upper ones unchanged.
    Last edited by sayzer; - 19th October 2006 at 03:23.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    As the pin are set to input.... if you write to them, the result stay unchanged... as i posted. Not sure with the interrupt.

    Why do you think that PORTB.7=1 or PORTB.7=0 no nothing if the TRIS.7 is not set to 0?

    One thing is sure, you will clear the RBIF bit just by reading PORTB, so the above solution using Temp=PORTB will certainely cause some strange interrupt behaviour (at least you will miss some). All in the datasheet in INTCON register description.
    Last edited by mister_e; - 19th October 2006 at 00:33.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    Steve, yes I know reading the port, RBIF will get reset. But what about writing to the port if the upper nibble is input? Will the write cause Interrupt?

    I can tolerate to loose a few while writing to the port. But producing Int's for this reason is not welcome.

    Sayzer, nice idea the old recipe. I am just looking too shorten my code. I 'll see which method is shortest.


    Thanks,
    Ioannis
    Last edited by Ioannis; - 19th October 2006 at 06:27.

  6. #6
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Both “Temp = PortB” and “PortB = i” read the Port . Both allow for a chance of missing a change and therefore an interrupt. Steve is right in that preserving the state of the upper four pins does not appear necessary since it does not change the input values when the port is written – just the latched values should the pin directions be changed from inputs to outputs. Go with #5.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    OK guys. I thought of preservint the interrupts. Anyway, sometimes your thoughts are silly without the ability to see further...

    Thanks,
    Ioannis

Similar Threads

  1. 16F877A with 20MHz XTAL not working?
    By ustredna in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 19th August 2011, 15:04
  2. 2x16 lcd not working with pic16f72
    By vu2iia in forum Schematics
    Replies: 4
    Last Post: - 16th February 2011, 14:59
  3. Blink.Bas on 18f45k20 Newbie seeks working example.
    By DiscoEd in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 29th December 2009, 03:36
  4. Pic 16 F628A not working
    By turkuaz in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 17th March 2009, 12:26
  5. Hserin not working...
    By robert0 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 22nd August 2005, 12:25

Members who have read this thread : 0

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

Posting Permissions

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