Thread: Bitwise Operations

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    53

    Bitwise Operations

    Hello All,

    This is my first post here and I have a question about a function I have made. LATA is 8-bits long and all bits are set ok as in the code below, but what I want the code to do is leave the previous bit set as well and not turn it off so that at the end of the loop all bits are set.

    Code:
    void LED_test (void)
    {
    
    {
    int i;
    LATA = 0b00000001;
    for (i = 0; i < 7; i++)
    {
    Delay_Us( Delay_750mS_Cnt );
    LATA = LATA << 1;
    }
    
    
    }
    Any help on this I will appreciate it.
    Thanks.
    Last edited by drkidd22; 11-12-2009 at 09:26 PM.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Have another copy of LATA, perhaps SUNA. Before you shift LATA, copy to SUNA, and then OR SUNA into LATA.

    (Get it - sooner, later.. har har)
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by drkidd22 View Post
    Hello All,

    This is my first post here and I have a question about a function I have made. LATA is 8-bits long and all bits are set ok as in the code below, but what I want the code to do is leave the previous bit set as well and not turn it off so that at the end of the loop all bits are set.

    Code:
    void LED_test (void)
    {
    
    {
    int i;
    LATA = 0b00000001;
    for (i = 0; i < 7; i++)
    {
    Delay_Us( Delay_750mS_Cnt );
    LATA = LATA << 1;
    }
    
    
    }
    Any help on this I will appreciate it.
    Thanks.
    Perhaps then invert LATA and add one to it - eliminates looping.
    Quote Originally Posted by Dino View Post
    Have another copy of LATA, perhaps SUNA. Before you shift LATA, copy to SUNA, and then OR SUNA into LATA.

    (Get it - sooner, later.. har har)
    Lol!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitwise Shift Operations
    By John_L in forum Tech Board
    Replies: 19
    Last Post: 02-25-2008, 11:22 AM
  2. bitwise operations with double
    By henry_kay in forum C Programming
    Replies: 2
    Last Post: 10-03-2007, 04:57 AM
  3. Bitwise operations
    By sh3rpa in forum C++ Programming
    Replies: 16
    Last Post: 09-25-2007, 06:32 PM
  4. bitwise operations
    By black_watch in forum C++ Programming
    Replies: 9
    Last Post: 03-24-2007, 04:48 AM
  5. bitwise operations
    By andrew_tucker in forum C Programming
    Replies: 2
    Last Post: 11-28-2002, 12:46 AM