Bitwise Operations

This is a discussion on Bitwise Operations within the C Programming forums, part of the General Programming Boards category; Hello All, This is my first post here and I have a question about a function I have made. LATA ...

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

    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
    Katy, Texas
    Posts
    2,309
    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)
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,058
    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, 05:57 AM
  3. Bitwise operations
    By sh3rpa in forum C++ Programming
    Replies: 16
    Last Post: 09-25-2007, 07:32 PM
  4. bitwise operations
    By black_watch in forum C++ Programming
    Replies: 9
    Last Post: 03-24-2007, 05:48 AM
  5. bitwise operations
    By andrew_tucker in forum C Programming
    Replies: 2
    Last Post: 11-28-2002, 12:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21